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 by adding user attributes and try out the scenario.
Set up the WSO2 OAuth2.0 Playground sample
Before you begin, you must first configure OAuth for a service provider to use this sample.
- Add a new service provider.
- Sign in. Enter your username and password to log on to the Management Console.
- Navigate to the Main menu to access the Identity menu. Click Add under Service Providers.
- Fill in the Service Provider Name and provide a brief Description of the service provider. Only Service Provider Name is a required field.
- Click Register to add the new service provider.
Expand the Inbound Authentication Configuration section and configure OAuth/OpenID Connect.
To obtain and configure the Playground sample, follow the steps below.
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.
Open a terminal window and add the following entry to the /etc/hosts
file of your machine to configure the hostname.
Navigate to <SAMPLE_HOME>/oauth2/playground2
directory via the terminal 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).
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, such as Apache Tomcat server.
Use the following steps to deploy the web app in the web container:
- Stop the Apache Tomcat server if it is already running.
- Copy the
playground2.war
file to the <TOMCAT_HOME>/webapps
folder. - Start the Apache Tomcat server.
Make sure to update param-value
parameter in the WEB-INF/web.xml
file with the server URL of the Identity Server if required.
Make sure to enter the port the application is running on, in the URL. If you have started the Identity Server with a port offset, then the respective port needs to be configured here.
<init-param>
<description>serverUrl</description>
<param-name>serverUrl</param-name>
<param-value>https://localhost:9443/services/</param-value>
</init-param>
Update param-value
parameter 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>
Restart Apache Tomcat and access http://wso2is.local:8080/playground2/
By default Tomcat runs on port 8080. If you have configured it to run on a different port make sure to update the URL and access the playground application.
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.
OAuth 2.0 has three main phases. They are; requesting an Authorization Grant, exchanging the Authorization Grant for an Access Token and accessing the resources using this Access Token. OpenID Connect is another identity layer on top of OAuth 2.0. OAuth applications can get authentication event information over the IDToken and can get the extra claims of the authenticated user from the OpenID Connect UserInfo endpoint.
To enable OAuth support for your client application, you must first register your application. Follow the instructions below to add a new application.
Let's get started to configure the service provider you created!
- Expand the Inbound Authentication Configuration section and then expand OAuth/OpenID Connect Configuration. Click Configure.
Fill in the form that appears. For the Allowed Grant Types you can disable the ones you do not require or wish to block.
When filling out the New Application form, the following details should be taken into consideration.
Field | Notes |
---|
OAuth Version | 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. |
Callback Url | This is the exact location in the service provider's application where an access token would be sent. This is a required field (if the grant type is anything other than 'Code' or 'Implicit') and it is 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. |
Allowed Grant Types - The following are the grant types that are used to get the access token: |
Code | Entering the username and password required at the service provider will result in a code being generated. This code can be used to obtain the access token. For more information on this grant type, see this Authorization Code specification. |
Implicit | This is similar to the code grant type, but instead of generating a code, this directly provides the access token. For more information on this grant type, see this Implicit Grant specification. |
Password | This authenticates the user using the password provided and the access token is provided. For more information on this grant type, see this Resource Owner Password Credentials Grant specification. |
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. For more information on this grant type, see this Client Credentials specification. |
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. For more information on this grant type, see this Refresh Token specification. |
SAML | This uses SAML assertion to obtain the access token. For more information on this grant type, see this SAML2 Bearer specification. |
IWA-NTLM | This is similar to the password grant type, but it is specific to Microsoft Windows users. |
urn:ietf:params:oauth:grant-type:jwt-bearer | This is a custom grant type. It uses a JWT token to obtain the access token. For more information about this grant type, see this JWT specification. |
PKCE Mandatory | Select this if you are using the Code grant type. PKCE is a recommended security measure used to mitigate a code interception attack. See Mitigating Authorization Code Interception Attacks for more information. |
Support PKCE 'Plain' Transform Algorithm | Select this if you are using PKCE. |
User Access Token Expiry Time, Application Access Token Expiry Time, Refresh Token Expiry Time | Set the validity period (in seconds) for User Access Token, Application Access Token, and Refresh Token. |
Enable Audience Restriction | Select this to enable audience restrictions for OAuth applications. If necessary, you can add multiple audiences. To add an audience, specify a required Audience value and click Add. All audience values that you add would be available in the ID token generated for the corresponding application. |
- 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.
- Actions -
Edit: Click to edit the OAuth/OpenID Connect Configurations
Revoke: Click to revoke (deactivate) the OAuth application. This action revokes all tokens issued for this application. In order to activate the application, you have to regenerate the consumer secret.
Regenerate Secret: Click to regenerate the secret key of the OAuth application.
Delete: Click to delete the OAuth/OpenID Connect Configurations
Try out scenario
- Visit the URL
http://wso2is.local:8080/playground2/oauth2.jsp
to start the scenario with the sample application. Enter the following details and click Authorize.
- Authorization Grant Type: Authorization Code
- Client ID: (the client id received at the application registration step in Identity Server)
- Scope: openid (This scope is a requirement to provide user information. Any token without this scope will not be allowed to access user information.)
- Callback URL: http://wso2is.local:8080/playground2/oauth2client
- Authorize Endpoint: https://localhost:9443/oauth2/authorize
- Provide user credentials and sign in with the previously created user.
- 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
- Deny to provide information to the service provider.
- Approve to provide user profile information to this service provider only for this time.
Approve Always to provide approval to share user profile information with the service provider even in the future without prompting for consent again.
Enter the following details in the form that appears and click Get Access Token.
- Callback URL: http://wso2is.local:8080/playground2/oauth2client
- Access Token Endpoint:https://localhost:9443/oauth2/token
- Client Secret: (client secret received at the application registration)
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 receive the following response from the Identity Server.
{
"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.
{"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>
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 URL | Description |
---|
https://localhost:9443/oauth2/authorize?prompt=none | The 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=login | Even if the end user is already authenticated, it will prompt the end user for re-authentication. |
https://localhost:9443/oauth2/authorize?prompt=consent | Even if the consent is already given, it will prompt the end user for consent again before returning information to the client. |
https://localhost:9443/oauth2/authorize?prompt=consent login | The user will be prompted to login as well as for consent when returning information to the client. |