Wednesday, May 6, 2015

Use OpenID Connect with OAuth 2.0 in WSO2 API Manager to retrieve user information

When we calling an API, we request for an oauth token which we send with each API call.

The reason for introduce OpenID on top of oauth 2.0 is oauth 2.0 access token retrieving process does not provide any additional information about user who is generating access tokens. Oauth is only authorization mechanism and we cannot derive more information from that.
So to get more information about user we will use openId scope to get user access token.

In that case we will pass openid scope with token request. Then we will get JWT as a part of the response from API manager, which contains user information in addition to access token and refresh token. So we will have all required user information after token generation process and we can use it for next steps if we need to do anything specific to users.
Issue following command to request OpenID based OAuth token.

curl -k -d "grant_type=password&username=admin&password=admin&scope=openid" -H "Authorization: Basic M1J6RFNrRFI5ZmQ5czRqY296R2xfVjh0QU5JYTpXeElqSkFJd0dqRWVYOHdHZGFfcGM1Wl94RjRh, Content-Type: application/x-www-form-urlencoded"



This response contain JWT as well. Then we can invoke user info API as follows.
curl -k -v -H "Authorization: Bearer 1c0c92c4e98e4371c91463ee3f2284c"

HTTP/1.1 200 OK
{"email":"","family_name":"malalgoda"}As you see we can get results for user details.


  1. Hi,
    I use the AM 1.8.0
    I'm trying to make here is written

    curl -k -d "grant_type=password&username=admin&password=admin&scope=openid" -H "Authorization: Basic M1J6RFNrRFI5ZmQ5czRqY296R2xfVjh0QU5JYTpXeElqSkFJd0dqRWVYOHdHZGFfcGM1Wl94RjRh, Content-Type: application/x-www-form-urlencoded" https://localhost:9443/oauth2/token

    But I keep getting scope: "default"

    like this:

    "scope": "default",
    "token_type": "bearer",
    "expires_in": 2377,
    "refresh_token": "5ed24fcf5dd1ccda497487ee8f51c",
    "access_token": "e585676ad7561b8f50d7e5b5d70b6"

    And the following request with that access_token:


    It returns to me:

    "error": "insufficient_scope",
    "error_description": "Access token does not have the openid scope"

    Please tell me what could be the problem


    1. Hi Dmytro,

      I am also facing the same issue, but with WSO2 API Manager 1.9.1 release. How you fixed this issue ? Could you please provide steps ?

  2. There was an issue in Scope issuer class and we fixed it after API Manager 1.8.0 release.
    There issue was scope validation logic unable to validate openid scope and set default scope to request. That is why you get scope as default in your response.
    This issue fixed in API Manager 1.9.0 and you may use that version.


  3. Thanks for the answer,

    but I understand that the AM 1.9.0 has not yet released

    I tried 1.9.0-alpha (

    and I got the same result :(

  4. I think fix gone after that. I will check this and get back you.


  5. Hi Sanjeewa,

    We're using WSO2 API Manager 1.9.1 release. We're getting following details / information correctly

    curl -k -d "grant_type=password&username=john&password=test00" -H "Authorization: Basic UGFwc25sMXM3eTViazlmb3huOW56cFF0Zm9rYTpFc0VFWFBvU1FLZlVuQzNiajlMZ2lVRXdiUXNh, Content-Type: application/x-www-form-urlencoded"


    When I used curl -k -H "Authorization: Bearer 673388870cdc4aef1abf36446b4d"

    404Status reportNot FoundThe requested resource (/oauth2/userinfo?schema=openid) is not available.

    Could you please help me how to solve this issue ? Could you please update your blog with screen shots ?

  6. Hello Sanjeewa,

    I was able to implement your suggested steps easily with WSO2 API Manager (APIM). But when I simply execute below command

    curl -k -v -H "Authorization: Bearer 1c0c92c4e98e4371c91463ee3f2284c"

    I only see following details are coming
    {"email":"","family_name":"sayali shinde"}

    But I was expecting other details should come with user schema like subscriber,applicationid,applicationname,applicationtier etc because I did configure all these dialects (list of claims) in SP (service Provider). Please guide.

  7. I am able to run this project successfully, but I need all my custom claims to be get appeared in the Openid user schema

    https://localhost:9443/oauth2/userinfo?schema=openid - For this URL I only see following information:

  8. Hi,
    All those claims defined in under same based claim URI.
    Can you please check claim configurations and user profile.