Search code examples
javascriptnode.jswso2wso2-api-managerwso2-data-services-server

How to get user's profile in wso2 api manager?


I need get user's profile in wso2 api manager, how could i do that? Until now, i've done get access token, refresh token and revoke token:

https://localhost:9443/oauth2/token --> access and refresh token
https://localhost:9443/oauth2/revoke --> revoke token

Thanks for help me.


Solution

  • if you define openid as one of the scope, then you would be able to use userinfo endpoint to get the user related info.

    Generate token with scope openid

    curl -k -d "grant_type=password&username=admin&password=admin&scope=openid" -H "Authorization: Basic NzhfQURZNGdBMWJ6djd0ZVc0Zk11VkpMM0xVYTpQWE55RmZ1ZjlmbkVhUW9NYksyaUxjTFE1dndh" https://localhost:9443/oauth2/token
    

    use that token to request userinfo

    curl -k  -H "Authorization: Bearer 14e78b764c91a1f18b5566ddbd88c5ff" https://localhost:9443/oauth2/userinfo?schema=openid
    

    by default, response would only contain the sub value. {"sub":"[email protected]"}

    You can define which parameters you should send by configuring the claims in the service provide application in API Manager

    for that log in to carbon management console and select the service provider application

    under the claim configuration you can set email, lastname, and any other claims you need as 'Requested claims'

    ex: http://wso2.org/claims/emailaddress for email
    

    once configured, you would get following kind of response for previous request

    {"sub":"[email protected]","family_name":"adhikarinayake","email":"[email protected]"}