wso2wso2-esbwso2-api-managerapache-synapse

How to get username of API caller in wso2 apim in Basic Authorization?


As you know we have 3 types of Authorization in WSO2 API management API Call: Basic, ApiKey, OAuth

I need to extract username of API caller. I used this way as you can see in this link: https://stackoverflow.com/a/78538232/7318224

<log level="custom">
  <property name="USER_NAME" expression="$ctx:api.ut.userName">
</log> 

But, This code only works if we use OAuth Authentication. So If we use Basic Authentication, this property will be NULL. Do you have any solution for that? I search the easiest way. Thank you!


Solution

  • You can use following property for this.

    <log level="custom">
      <property name="USER_NAME" expression="$ctx:api.ut.userId">
    </log>
    

    Full set of properties.

    api.ut.consumerKey
    api.ut.userId
    api.ut.api_version
    api.ut.api
    api.ut.version
    api.ut.api_type
    api.ut.hostName
    api.ut.application.name
    api.ut.application.id
    api.ut.userName