Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This section demonstrates the WSO2 Identity Server's OpenID Connect Basic Client Profile implementation with the WSO2 OAuth2 playground sample. 

Setting up the playground sample

First follow the instructions in the sections below to set up the playground sample and register it in WSO2 IS. Once you have done so, complete the user profile and try out the scenario. 

Expand
titleSet up the WSO2 OAuth2.0 Playground sample

Include Page
IS510:Setting Up the Sample WebappIS510:
Setting Up the Sample Webapp

Expand
titleRegister the Playground application in WSO2 Identity Server

In order to configure Single-Sign-On (SSO) for OAuth2-OpenID Connect, you must first register a service provider for inbound authentication.

Include Page
IS510:Configuring OAuth2-OpenID Connect Single-Sign-OnIS510:
Configuring OAuth2-OpenID Connect Single-Sign-On

Expand
titleComplete the user profile
  1. Create a user.
  2. Log in as the user you created and go to the dashboard.
  3. Update your profile filling the user attributes.

    You can also do this at Main > List > Users and Roles > Users, then select the user and update the profile.

  4. Click Update to save your changes.

...

Try out scenario

  1. Visit the URL http://localhost:8080/playground2/oauth2.jsp to start the scenario with the sample application.
  2. Enter the following details and click Authorize.

    Note

    Note: To try out this scenario with different consent values, see step 7.


  3. Provide user credentials and sign in with the previously created user.

  4. Click Approve to provide consent to this action. The screen mentions the service provider by name and requests for user consent to provide user information to that particular service provider. The user can either 
    1. Deny to provide information to the service provider.
    2. Approve to provide user profile information to this service provider only for this time.
    3. Approve Always to provide approval to share user profile information with the service provider even in the future without prompting for consent again.

    Tip

    Tip: After approval is provided, the application receives an authorization code issued from WSO2 Identity Server. This authorization code can only be used once to get a valid access token and has a expiry time that can be configured by editing the following property in the <IS_HOME>/repository/conf/identity/identity.xml file. The default expiry time is 300 seconds.

    Code Block
    languagexml
    <!-- Default validity period for Authorization Code in seconds -->
            <AuthorizationCodeDefaultValidityPeriod>300</AuthorizationCodeDefaultValidityPeriod>
  5. Enter the following details in the form that appears and click Get Access Token

  6. At this point, the application receives the Access Token with the id token, which follows the format shown in step 7. Enter the UserInfo endpoint of the WSO2 Identity Server, (i.e., https://localhost:9443/oauth2/userinfo), in the form as seen below, to get user information.

    Since the received access token has the scope 'openid', the userinfo endpoint provides the user attribute details when the request is made. You will receive the following response from the Identity Server.

    Code Block
    languagegroovy
    titleResponse
    {  
       "scope":"openid",
       "token_type":"Bearer",
       "expires_in":3600,
       "refresh_token":"74d0d7e6d4b3c19484f5135593c2dc88",   		  "id_token":"eyJhbGciOiJSUzI1NiJ9.eyJhdXRoX3RpbWUiOjE0NTIxNzAxNzYsImV4cCI6MTQ1MjE3Mzc3Niwic3ViIjoidXNlQGNhcmJvbi5zdXBlciIsImF6cCI6IjF5TDFfZnpuekdZdXRYNWdCMDNMNnRYR3lqZ2EiLCJhdF9oYXNoIjoiWWljbDFlNTI5WlhZOE9zVDlvM3ktdyIsImF1ZCI6WyIxeUwxX2Z6bnpHWXV0WDVnQjAzTDZ0WEd5amdhIl0sImlzcyI6Imh0dHBzOlwvXC9sb2NhbGhvc3Q6OTQ0M1wvb2F1dGgyXC90b2tlbiIsImlhdCI6MTQ1MjE3MDE3Nn0.RqAgm0ybe7tQYvQYi7uqEtzWf6wgDv5sJq2UIQRC4OJGjn_fTqftIWerZc7rIMRYXi7jzuHxX_GabUhuj7m1iRzi1wgxbI9yQn825lDVF4Lt9DMUTBfKLk81KIy6uB_ECtyxumoX3372yRgC7R56_L_hAElflgBsclEUwEH9psE",
       "access_token":"f1824ef345f0565ab88a06a51db98d24"
    }

    The returned ID token carries the user details. It follows the following format: <header>.<body>.<signature>. The decoded ID token can be seen below.

    Code Block
    languagegroovy
    titleDecoded ID Token
    {"alg":"RS256"}.
    {  
       "auth_time":1452170176,
       "exp":1452173776,
       "sub":"use@carbon.super",
       "azp":"1yL1_fznzGYutX5gB03L6tXGyjga",
       "at_hash":"Yicl1e529ZXY8OsT9o3y-w",
       "aud":[  
          "1yL1_fznzGYutX5gB03L6tXGyjga"
       ],
       "iss":"https:\/\/localhost:9443\/oauth2\/token",
       "iat":1452170176
    }.<signature value>
     
    Tip

    Tip: Alternatively, you can get user information by running the following cURL command on the terminal.

    Localtabgroup
    Localtab
    activetrue
    titlecURL Command
    Code Block
    languagepowershell
    curl -k -H "Authorization: Bearer <Acess_token>" https://localhost:9443/oauth2/userinfo?schema=openid
    Localtab
    titleResponse
    Code Block
    languagegroovy
    {  
       "sub":"admin",
       "email":"admin@wso2.com",
       "website":"https://wso2.com",
       "name":"admin",
       "family_name":"admin",
       "preferred_username":"admin",
       "given_name":"admin",
       "profile":"https://wso2.com",
       "country":"Sri Lanka"
    }
  7. You can also try out this scenario with different consent values {none, login and consent}. To do this, try the following URLs when entering the Authorization Endpoint URL in step 2 of the Try out scenario section. 

    Panel