SkillValidation Class

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

public final class SkillValidation

Validates JWT tokens sent to and from a Skill.

Method Summary

Modifier and Type Method and Description
static java.util.concurrent.CompletableFuture<ClaimsIdentity> authenticateChannelToken(String authHeader, CredentialProvider credentials, ChannelProvider channelProvider, String channelId, AuthenticationConfiguration authConfig)

Validates that the incoming Auth Header is a token sent from a bot to a skill or from a skill to a bot.

static ClaimsIdentity createAnonymousSkillClaim()

Creates a ClaimsIdentity for an anonymous (unauthenticated) skill.

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

Checks if the given list of claims represents a skill.

static boolean isSkillToken(String authHeader)

Determines if a given Auth header is from from a skill to bot or bot to skill request.

static java.util.concurrent.CompletableFuture<java.lang.Void> validateIdentity(ClaimsIdentity identity, CredentialProvider credentials)

Helper to validate a skills ClaimsIdentity.

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

authenticateChannelToken

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

Validates that the incoming Auth Header is a token sent from a bot to a skill or from a skill to a bot.

Parameters:

authHeader - The raw HTTP header in the format: "Bearer [longString]".
credentials - The user defined set of valid credentials, such as the AppId.
channelProvider - The channelService value that distinguishes public Azure from US Government Azure.
channelId - The ID of the channel to validate.
authConfig - The authentication configuration.

Returns:

A ClaimsIdentity instance if the validation is successful.

createAnonymousSkillClaim

public static ClaimsIdentity createAnonymousSkillClaim()

Creates a ClaimsIdentity for an anonymous (unauthenticated) skill.

Returns:

A ClaimsIdentity instance with authentication type set to AuthenticationConstants.AnonymousAuthType and a reserved AuthenticationConstants.AnonymousSkillAppId claim.

isSkillClaim

public static Boolean isSkillClaim(Map claims)

Checks if the given list of claims represents a skill. A skill claim should contain: An VERSION_CLAIM claim. An AuthenticationConstants.AUTIENCE_CLAIM claim. An APPID_CLAIM claim (v1) or an a AUTHORIZED_PARTY claim (v2). And the appId claim should be different than the audience claim. When a channel (webchat, teams, etc.) invokes a bot, the AuthenticationConstants.AUTIENCE_CLAIM is set to TO_BOT_FROM_CHANNEL_TOKEN_ISSUER but when a bot calls another bot, the audience claim is set to the appId of the bot being invoked. The protocol supports v1 and v2 tokens: For v1 tokens, the APPID_CLAIM is present and set to the app Id of the calling bot. For v2 tokens, the AUTHORIZED_PARTY is present and set to the app Id of the calling bot.

Parameters:

claims - A list of claims.

Returns:

True if the list of claims is a skill claim, false if is not.

isSkillToken

public static boolean isSkillToken(String authHeader)

Determines if a given Auth header is from from a skill to bot or bot to skill request.

Parameters:

authHeader - Bearer Token, in the "Bearer [Long String]" Format.

Returns:

True, if the token was issued for a skill to bot communication. Otherwise, false.

validateIdentity

public static CompletableFuture validateIdentity(ClaimsIdentity identity, CredentialProvider credentials)

Helper to validate a skills ClaimsIdentity.

Parameters:

identity - The ClaimsIdentity to validate.
credentials - The CredentialProvider.

Returns:

Nothing if success, otherwise a CompletionException

Applies to