Newer Version Available

This content describes an older version of this product. View Latest

TokenValidationResult Class

Contains methods that describe the result of the token validation performed by a token exchange handler using the validateIncomingToken method in the Auth.Oauth2TokenExchangeHandler class during the OAuth 2.0 token exchange flow.

Namespace

Auth

Usage

For a full example implementation that shows how to get information from the TokenValidationResult class, see OAuth 2.0 Token Exchange Handler Examples.

Example

Here’s is an example of the Auth.TokenValidationResult class.

1global class TokenValidationResult {        
2    global TokenValidationResult(Boolean valid) { this.isValid = valid; }
3    
4    global TokenValidationResult(Boolean isValid, Object data, Auth.UserData userData, 
5        String token, Auth.OAuth2TokenExchangeType tokenType, String customErrorMsg) {
6        
7        this.isValid = isValid;
8        this.data = data;
9        this.userData = userData;
10        this.token = token;
11        this.tokenType = tokenType;
12        this.customErrorMsg = customErrorMsg;
13    
14    }
15    
16    global Boolean isValid;
17    global Object data; 
18    global Auth.UserData userData;
19    global String token;
20    global Auth.OAuth2TokenExchangeType tokenType; //Enum
21    global String customErrorMsg; //Custom error message that’s returned to the client if token validation fails 
22    
23    global Boolean isValid(){
24        return isValid;
25    }
26    global Object getData(){
27        return data;
28    }
29    global Auth.UserData getUserData(){
30        return userData;
31    }
32    global String getToken(){
33        return token;
34    }
35    global OAuth2TokenExchangeType getTokenType(){
36        return tokenType;
37    }
38    global String getCustomErrorMessage(){
39        return customErrorMsg;
40    }
41}

TokenValidationResult Constructors

The following are constructors for TokenValidationResult.

TokenValidationResult(isValid, data, userData, token, tokenType, customErrorMsg)

Creates an instance of the Auth.TokenValidationResult class to describe the result of token validation performed during the OAuth 2.0 token exchange flow.

Signature

public TokenValidationResult(Boolean isValid, Object data, Auth.UserData userData, String token, Auth.OAuth2TokenExchangeType tokenType, String customErrorMsg)

Parameters

isValid
Type: Boolean
If true, the token is valid.
data
Type: Object
Stores custom data that isn’t stored in userData.
userData
Type: Auth.UserData
Stores information about a Salesforce user.
token
Type: String
The token from the external identity provider.
tokenType
Type: Auth.OAuth2TokenExchangeType
The type of token from the external identity provider.
customErrorMsg
Type: String
A custom error message that’s returned if the token validation fails.

TokenValidationResult(valid)

Creates an instance of the Auth.TokenValidationResult class to describe a valid token validation result during the OAuth 2.0 token exchange flow.

Signature

public TokenValidationResult(Boolean valid)

Parameters

valid
Type: Boolean
Indicates a valid token validation result.

TokenValidationResult Properties

The following are properties for TokenValidationResult.

customErrorMsg

A custom error message that’s returned if token validation fails.

Signature

public String customErrorMsg {get; set;}

Property Value

Type: String

data

Contains information about the user that isn’t stored in the Auth.UserData class, such as information obtained via callouts to the external identity provider.

Signature

public Object data {get; set;}

Property Value

Type: Object

isValid

Indicates whether the token is valid or not, based on the custom validation logic in your token exchange handler.

Signature

public Boolean isValid {get; set;}

Property Value

Type: Boolean

token

The token from the external identity provider.

Signature

public String token {get; set;}

Property Value

Type: String

tokenType

The type of token from the external identity provider. It can be an access token, refresh token, ID token, SAML 2.0 assertion, or a JSON Web Token (JWT).

Signature

public Auth.OAuth2TokenExchangeType tokenType {get; set;}

Property Value

Type: Auth.OAuth2TokenExchangeType

userData

Information about the user that’s obtained from the identity provider’s token.

Signature

public Auth.UserData userData {get; set;}

Property Value

Type: Auth.UserData

TokenValidationResult Methods

The following are methods for TokenValidationResult.

getCustomErrorMessage()

Retrieves the CustomErrorMsg that’s returned when token validation fails.

Signature

public String getCustomErrorMessage()

Return Value

Type: String

getData()

Retrieves data from the identity provider token. This data can include custom data that isn’t stored in the userData property.

Signature

public Object getData()

Return Value

Type: Object

getToken()

Retrieves the token that was passed from the external identity provider.

Signature

public String getToken()

Return Value

Type: String

getTokenType()

Retrieves the type of token that was passed from the external identity provider.

Signature

public Auth.OAuth2TokenExchangeType getTokenType()

Return Value

Type: Auth.OAuth2TokenExchangeType

getUserData()

Retrieves information about the user. The user information can be obtained from the identity provider’s token or from callouts to the identity provider, if applicable.

Signature

public Auth.UserData getUserData()

Return Value

Type: Auth.UserData

isValid

Indicates whether the token is valid or not, based on the custom validation logic in your token exchange handler.

Signature

public Boolean isValid {get; set;}

Property Value

Type: Boolean