Search code examples
wso2basic-authenticationwso2-api-manager

Get username of Basic Auth in APIM


Is there a way we can retrieve the username of the user that is in Basic Auth? Get the username of the basic auth and save inside a property to use it in API Manager Logic

Thanks

I have done it before with MI and WWSecurity but not with APIM and Basic auth


Solution

  • I don't think you cannot achieve this via a simple mediation sequence as we record the username field inside the authenticationContext object.

    However with a customer handler or a custom class mediator, you can access this object from java. You can get this object from the synapse context via (AuthenticationContext) synCtx.getProperty("__API_AUTH_CONTEXT"). Here is an example of this object returned in the throttle handler. You can use the getter getUsername() to get the username of the requester and set this as a syapse property.