This documentation is for WSO2 Identity Server 5.4.1 . View documentation for the latest release.

All docs This doc
Skip to end of metadata
Go to start of metadata

This section provides instructions on how to get the user claims of the authorized user as a JWT token with the validation response. 


  1. Open the <IS_HOME>/repository/conf/identity/identity.xml file and set the <Enabled> element (found under the <OAuth>,<AuthorizationContextTokenGeneration> elements) to true as shown in the code block below. 


    Note: By default, the user claims are retrieved as an array. To retrieve the claims as a string instead of an array, add the following property under the <AuthorizationContextTokenGeneration> tag in the identity.xml file.

  2. Add the following property under <OAUTH> section to use the JWT Token Builder instead of the default Token Builder.


    If you need to use a self-contained access token generator, make sure you change the above values accordingly.

  3. The following configurations are optional and can be configured as needed.

    1. See the Extension Points for OAuth topic for more details about the usage of the 'TokenGeneratorImplClass' and 'ClaimsRetrieverImplClass'. 

    2. ConsumerDialectURI: Defines the URI for the claim dialect under which the user attributes need to be retrieved. 

    3. SignatureAlgorithm: Defines the algorithm to be used in signing the payload that carries user claims. If you want to disable signing of the JWT token, set this element to "NONE". 

    4. AuthorizationContextTTL: Defines the expiry time for JWT token in minutes.

Calling the OAuth2ValidationService with a valid token

After configuring the elements mentioned above, see the OAuth2 Token Validation and Introspection topic to call the OAuth2ValidationService. The following screenshot is the request and response of the OAuth2ValidationService from the SOAP UI. Additionally, it shows the required claims of the user as required claim URIs. In the response, you can see the received JWT token under the <tokenString> element. 

If there are no requested claim URIs defined, all the claims that carry values for the user are returned.

Header Metadata: 
The header contains the metadata for the token as seen below. 



Decoded Header: 


x5t : This header provides a base64url encoded SHA-256 thumbprint (a.k.a. digest) of the DER encoding of an X.509 certificate that can be used to match a certificate to validate the signature.

Decoded Payload:

   "sub":"[email protected]",
   "http:\/\/\/gateway\/subscriber":"[email protected]",
   "http:\/\/\/gateway\/enduser":"[email protected]",
   "http:\/\/\/claims\/emailaddress":"[email protected]",

Signature verification

The signature verification can be done similar to the ID token signature verification. 

The WSO2 Identity Server is shipped with a signed ID Token. This is provided in order to address some security vulnerabilities in a typical production environment. This topic provides information about using this signed ID Token for signature verification. 

The portions of each token are separated by the full stop. To see the exact JSON values, do a Base64 decode for <header>.<body>.

  • If the unsigned ID token contains only 2 portions: 

    Sample of unsigned ID token


  • If the signed ID token contains 3 portions: 

    Sample of signed ID token


Validating the ID token signature

The following code segment is a simple Java program that can be used to validate the ID token signature against the default wso2carbon.jks public key in WSO2 products.

package org.sample;


import com.nimbusds.jose.JWSVerifier;
import com.nimbusds.jose.crypto.RSASSAVerifier;
import com.nimbusds.jwt.SignedJWT;

public class ValidateRSASignature {

    public static void main(String[] args) throws Exception {
        RSAPublicKey publicKey = null;
        InputStream file = ClassLoader
        KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
        keystore.load(file, "wso2carbon".toCharArray());

        String alias = "wso2carbon";

        // Get certificate of public key
        Certificate cert = keystore.getCertificate(alias);
        // Get public key
        publicKey = (RSAPublicKey) cert.getPublicKey();

        // Enter JWT String here
        String signedJWTAsString = "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhbGljZSIsImlzcyI6Imh0d";

        SignedJWT signedJWT = SignedJWT.parse(signedJWTAsString);

        JWSVerifier verifier = new RSASSAVerifier(publicKey);

        if (signedJWT.verify(verifier)) {
            System.out.println("Signature is Valid");
        } else {
            System.out.println("Signature is NOT Valid");