Yes, it is possible to integrate the Token REST endpoint for your Azure AD B2C custom policy. In your TrustFrameworkExtensions.xml
file, you can define a new RESTful technical profile for the Token endpoint by using the following code:
<TechnicalProfile Id="TokenEndpoint">
<DisplayName>Token Endpoint</DisplayName>
<Protocol Name="OpenIdConnect" />
<OutputTokenFormat>JWT</OutputTokenFormat>
<Metadata>
<Item Key="HttpBinding">POST</Item>
<Item Key="response_types">code</Item>
<Item Key="grant_type">authorization_code</Item>
<Item Key="scope">openid</Item>
<Item Key="UsePolicyInRedirectUri">false</Item>
<Item Key="BearerTokenTransmissionMethod">AuthorizationHeader</Item>
<Item Key="client_id">{client_id}</Item>
<Item Key="DiscoverMetadataByTokenIssuer">true</Item>
</Metadata>
<CryptographicKeys>
<Key Id="client_secret" StorageReferenceId="B2C_1A_TokenSigningKeyContainer" />
</CryptographicKeys>
<InputClaims>
<InputClaim ClaimTypeReferenceId="authorizationCode" />
<InputClaim ClaimTypeReferenceId="scope" DefaultValue="openid" />
</InputClaims>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="id_token" />
<OutputClaim ClaimTypeReferenceId="access_token" />
<OutputClaim ClaimTypeReferenceId="refresh_token" />
<OutputClaim ClaimTypeReferenceId="expires_in" />
<OutputClaim ClaimTypeReferenceId="token_type" DefaultValue="Bearer" />
</OutputClaims>
<UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
</TechnicalProfile>
You can then call the Token endpoint by using the OAuth2
technical profile. Here's an example of how to do that:
<TechnicalProfile Id="OAuth2-Token">
<DisplayName>OAuth2 Token</DisplayName>
<Protocol Name="OAuth2" />
<Metadata>
<Item Key="AccessTokenEndpoint">{your_token_endpoint_url}</Item>
<Item Key="authorization_endpoint">{your_authorization_endpoint_url}</Item>
<Item Key="ClaimsEndpoint">{your_claims_endpoint_url}</Item>
<Item Key="ClientId">{your_client_id}</Item>
<Item Key="ClientSecret">{your_client_secret}</Item>
<Item Key="HttpBinding">POST</Item>
<Item Key="response_types">code</Item>
<Item Key="grant_type">authorization_code</Item>
<Item Key="scope">openid</Item>
<Item Key="UsePolicyInRedirectUri">false</Item>
<Item Key="BearerTokenTransmissionMethod">AuthorizationHeader</Item>
<Item Key="DiscoverMetadataByTokenIssuer">true</Item>
</Metadata>
<CryptographicKeys>
<Key Id="client_secret" StorageReferenceId="B2C_1A_TokenSigningKeyContainer" />
</CryptographicKeys>
<InputClaims>
<InputClaim ClaimTypeReferenceId="authorizationCode" />
<InputClaim ClaimTypeReferenceId="scope" DefaultValue="openid" />
</InputClaims>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="id_token" />
<OutputClaim ClaimTypeReferenceId="access_token" />
<OutputClaim ClaimTypeReferenceId="refresh_token" />
<OutputClaim ClaimTypeReferenceId="expires_in" />
<OutputClaim ClaimTypeReferenceId="token_type" DefaultValue="Bearer" />
</OutputClaims>
<UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" />
</TechnicalProfile>
Make sure to replace the {your_token_endpoint_url}
, {your_authorization_endpoint_url}
, {your_claims_endpoint_url}
, {your_client_id}
, and {your_client_secret}
placeholders with the actual values for your custom policy.
References: