JwtTokenValidation Class

  • java.lang.Object
    • com.microsoft.bot.connector.authentication.JwtTokenValidation

public final class JwtTokenValidation

Contains helper methods for authenticating incoming HTTP requests.

Method Summary

Modifier and Type Method and Description
static java.util.concurrent.CompletableFuture<ClaimsIdentity> authenticateRequest(Activity activity, String authHeader, CredentialProvider credentials, ChannelProvider channelProvider)

Authenticates the request and add's the activity's Activity#getServiceUrl() to the set of trusted URLs.

static java.util.concurrent.CompletableFuture<ClaimsIdentity> authenticateRequest(Activity activity, String authHeader, CredentialProvider credentials, ChannelProvider channelProvider, AuthenticationConfiguration authConfig)

Authenticates the request and add's the activity's Activity#getServiceUrl() to the set of trusted URLs.

static java.lang.String getAppIdFromClaims(Map<String,String> claims)

Gets the AppId from claims.

static boolean isValidTokenFormat(String authHeader)

Internal helper to check if the token has the shape we expect "Bearer [big long string]".

static java.util.concurrent.CompletableFuture<ClaimsIdentity> validateAuthHeader(String authHeader, CredentialProvider credentials, ChannelProvider channelProvider, String channelId, String serviceUrl)

Validates the authentication header of an incoming request.

static java.util.concurrent.CompletableFuture<ClaimsIdentity> validateAuthHeader(String authHeader, CredentialProvider credentials, ChannelProvider channelProvider, String channelId, String serviceUrl, AuthenticationConfiguration authConfig)

Validates the authentication header of an incoming request.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Method Details

authenticateRequest

public static CompletableFuture authenticateRequest(Activity activity, String authHeader, CredentialProvider credentials, ChannelProvider channelProvider)

Authenticates the request and add's the activity's Activity#getServiceUrl() to the set of trusted URLs.

Parameters:

activity - The incoming Activity from the Bot Framework or the Emulator
authHeader - The Bearer token included as part of the request
credentials - The bot's credential provider.
channelProvider - The bot's channel service provider.

Returns:

A task that represents the work queued to execute.

authenticateRequest

public static CompletableFuture authenticateRequest(Activity activity, String authHeader, CredentialProvider credentials, ChannelProvider channelProvider, AuthenticationConfiguration authConfig)

Authenticates the request and add's the activity's Activity#getServiceUrl() to the set of trusted URLs.

Parameters:

activity - The incoming Activity from the Bot Framework or the Emulator
authHeader - The Bearer token included as part of the request
credentials - The bot's credential provider.
channelProvider - The bot's channel service provider.
authConfig - The optional authentication configuration.

Returns:

A task that represents the work queued to execute.

getAppIdFromClaims

public static String getAppIdFromClaims(Map claims)

Gets the AppId from claims.

In v1 tokens the AppId is in the the AppIdClaim claim. In v2 tokens the AppId is in the AuthorizedParty claim.

Parameters:

claims - The map of claims.

Returns:

The value of the appId claim if found (null if it can't find a suitable claim).

Throws:

java.lang.IllegalArgumentException - Missing claims

isValidTokenFormat

public static boolean isValidTokenFormat(String authHeader)

Internal helper to check if the token has the shape we expect "Bearer [big long string]".

Parameters:

authHeader - A string containing the token header.

Returns:

True if the token is valid, false if not.

validateAuthHeader

public static CompletableFuture validateAuthHeader(String authHeader, CredentialProvider credentials, ChannelProvider channelProvider, String channelId, String serviceUrl)

Validates the authentication header of an incoming request.

Parameters:

authHeader - The authentication header to validate.
credentials - The bot's credential provider.
channelProvider - The bot's channel service provider.
channelId - The ID of the channel that sent the request.
serviceUrl - The service URL for the activity.

Returns:

A task that represents the work queued to execute.
     On Call:

validateAuthHeader

public static CompletableFuture validateAuthHeader(String authHeader, CredentialProvider credentials, ChannelProvider channelProvider, String channelId, String serviceUrl, AuthenticationConfiguration authConfig)

Validates the authentication header of an incoming request.

Parameters:

authHeader - The authentication header to validate.
credentials - The bot's credential provider.
channelProvider - The bot's channel service provider.
channelId - The ID of the channel that sent the request.
serviceUrl - The service URL for the activity.
authConfig - The authentication configuration.

Returns:

A task that represents the work queued to execute.

Applies to