This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Basic Client Profile with Playground

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. 

 Set up the WSO2 OAuth2.0 Playground sample

To obtain and configure the Playground sample, follow the steps below.

  1. You can check out the repository of the OAuth 2.0 sample from GitHub. Follow the instructions here to checkout the folder. We refer <SAMPLE_HOME> as the modules/samples folder inside the folder where the product-is repository is checked out.

    https://github.com/wso2/product-is/tree/v5.1.0/modules/samples/oauth2/playground2
  2. In your command line, navigate to <SAMPLE_HOME>/oauth2/playground2 in the folder you checked out and build the sample using the following command. You must have Apache Maven installed to do this (see Installation Prerequisites for the appropriate version to use).

    mvn clean install
  3. After successfully building the sample, a .war file named playground2 can be found inside the <SAMPLE_HOME>/oauth2/playground2/target folder. Deploy this sample web app on a web container. To do this, use the Apache Tomcat server.

    Since this sample is written based on Servlet 3.0 it needs to be deployed on Tomcat 7.x.

    Use the following steps to deploy the web app in the web container:

    1. Stop the Apache Tomcat server if it is already running.
    2. Copy the playground2.war file to the <TOMCAT_HOME>/webapps folder.
    3. Start the Apache Tomcat server.
  4. Make sure to update param-value the following parameter in the WEB-INF/web.xml file with the server url of the Identity Server if required.

    <init-param>
         <description>serverUrl</description>
         <param-name>serverUrl</param-name>
         <param-value>https://localhost:9443/services/</param-value>
    </init-param>

    Note that localhost is the server that hosts WSO2 Identity Server and 9443 is the default SSL port of it.

  5. Update param-value of below parameters with credentials of an admin user if required.

    <init-param>
         <description>userName</description>
         <param-name>userName</param-name>
         <param-value>admin</param-value>
    </init-param>
    <init-param>
         <description>password</description>
         <param-name>password</param-name>
         <param-value>admin</param-value>
    </init-param>
  6. Restart Apache Tomcat and access http://localhost:8080/playground2/ (assuming Tomcat is running on HTTP port 8080). You are directed to the landing page of the sample application. Click on Import Photos and the following page appears.

This application is used to request access tokens using the four OAuth2 grant types. 

 Register 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.

To enable OAuth support for your client application, you must first register your application by providing an application name. For code and implicit grant types, you have to provide a callback URL. Follow the instructions below to add a new application.

  1. Expand the OAuth/OpenID Connect Configuration and click Configure.
  2. Fill in the form that appears. For the Allowed Grant Types you can disable the ones you do not require or wish to block.
  3. Click Add. The following information is added for your service provider.

    • OAuth Client Key - This is the client key of the service provider, which will be checked for authentication by the Identity Server before providing the access token.
    • OAuth Client Secret - This is the client secret of the service provider, which will be checked for authentication by the Identity Server before providing the access token. Click the Show button to view the exact value of this.

    Tip: The OAuth client key and client secret are stored in plain text. To encrypt the client secret, access token and refresh token, do the following:

    Open the identity.xml file found in the <IS_HOME>/repository/conf/identity directory and change the <TokenPersistenceProcessor> property as follows:

    <TokenPersistenceProcessor>org.wso2.carbon.identity.oauth.tokenprocessor.EncryptionDecryptionPersistenceProcessor</TokenPersistenceProcessor>

When filling out the New Application form, the following should be taken into consideration.

  • Selecting OAuth Version as 1.0a removes all the configurable Allowed Grant Types. This is because this version of OAuth does not support grant types.
  • The Callback Url is the exact location in the service provider's application where an access token would be sent. This is a required field and important to configure as it is imperative that the service provider receives the access token. This is necessary for security purposes to ensure that the token is not compromised.
  • The following are the grant types that are used to get the access token.
    • Code - Entering the user name and password required at the service provider will result in a code being generated. This code can be used to obtain the access token.
    • Implicit - This is similar to the code grant type, but instead of generating a code, this directly provides the access token.
    • Password - This authenticates the user using the password provided and the access token is provided.
    • Client Credential - This is the grant type for the client key and client secret. If these two items are provided correctly by the service provider, the access token is sent.
    • Refresh Token - This will enable the user to obtain an access token by using the refresh token once the originally provided access token is used up.
    • SAML - This uses SAML as the grant type to obtain the access token.
    • IWA-NTLM - This is similar to the password grant type, but it is specific to Microsoft Windows users.
Related Topics

See Delegated Access Control for more information on working with OAuth2/OpenIDConnect. See the following topics for samples of configuring delegated access control:

 Complete 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: 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: 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.

    <!-- 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?schema=openid), 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.

    Response
    {  
       "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.

    Decoded 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: Alternatively, you can get user information by running the following cURL command on the terminal.

  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. 

    Authorization Endpoint URLDescription
    https://localhost:9443/oauth2/authorize?prompt=noneThe Identity Server does not display any authentication or consent user interface pages. An error is returned if an end user is not already authenticated or the client does not have pre-configured consent for the requested claims or if there are any other unfulfilled conditions for processing the request.
    https://localhost:9443/oauth2/authorize?prompt=loginEven if the end user is already authenticated, it will prompt the end user for re-authentication.
    https://localhost:9443/oauth2/authorize?prompt=consentEven if the consent is already given, it will prompt the end user for consent again before returning information to the Client.

    Note: To skip user consent, you can also edit the following property in the <IS_HOME>/repository/conf/identity/identity.xml file found under the <OAuth> <OpenIDConnect> tags. To skip user consent, set this property to true.

    <SkipUserConsent>false</SkipUserConsent>

    Note that even if this property is set to true so that it will skip user consent, if you use an Authorization Endpoint URL that prompts user consent (e.g.,https://localhost:9443/oauth2/authorize?prompt=consent), it will still prompt consent from the user.