Summary
The issue I’m encountering is the Resource Owner password flow login does not cause the requested_scopes array to be initialized (from event.transaction.requested_scopes) for the Post Login actions.
Does anyone know if this is a bug or if the requested scopes are available in another object for the Post Login action for the Resource Owner code flow?
Details
I’m trying to perform the Resource Owner password flow login (per docs Call Your API Using Resource Owner Password Flow). I also have a Post Login Action that adds a custom claim to the id_token if a specific scope value is included in the login request. Specifically, requested scope values are provided to the action via the action event object in event.transaction.requested_scopes (per docs Actions Triggers: post-login - Event Object). The ultimate goal is to have this claim returned by the GET /userinfo API (per docs Authentication API Explorer).
However, the Resource Owner password flow appears to prevent this requested_scopes array from being provided to the action (when comparing it another flow like Authorization code flow).
Examples
An example of my request is as follows, with secret values obfuscated like {secretValueName}:
curl --location 'https://{myDomain}/oauth/token' \
--header 'content-type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username={username}' \
--data-urlencode 'password={password}' \
--data-urlencode 'audience={apiAudience}' \
--data-urlencode 'scope=openid email' \
--data-urlencode 'client_id={myClientId}' \
--data-urlencode 'client_secret={myClientSecret}'
The JSON response to this cURL request looks like the following (with the JWTs obfuscated):
{
"access_token": "{obfuscated JWT}",
"id_token": "{obfuscated JWT}",
"scope": "openid email",
"expires_in": 43200,
"token_type": "Bearer"
}
Here is a minimum viable example of my Post Login Action:
exports.onExecutePostLogin = async (event, api) => {
const standardOpenIdScope = "openid";
if (event.authorization
&& event.transaction
&& event.transaction.requested_scopes
&& event.transaction.requested_scopes.includes(standardOpenIdScope)) {
const additionalMetadata = {
"testMetadata": "testMetadataValue"
};
api.idToken.setCustomClaim("user_metadata", additionalMetadata);
}
};
When I perform the GET /userinfo request using the access_token granted for the Resource Owner login flow, I get the following response. It is missing the user_metadata property that should’ve been set by the Action:
{
"sub": "{obfuscated Auth0 Id}",
"email": "{obfuscated Email}",
"email_verified": true
}
As a counter example, here is the GET /userinfo response using an access_token granted from a normal Authorization Code flow login (per docs Authorization Code Flow); note the successful inclusion of the user_metadata property:
{
"sub": "{obfuscated Auth0 Id}",
"email": "{obfuscated Email}",
"email_verified": true,
"user_metadata": {
"testMetadata": "testMetadataValue"
}
}