Azure AD B2C missing access_token in refreshTokenGrant #719
-
Edit by @panva: See #719 (comment) for resolution. What happened?I got a an error The error comes from here: Lines 2772 to 2783 in c7fb6e4 but originates here: The debugger showed, that the variable {
id_token: "redacted",
token_type: "Bearer",
not_before: 1729706541,
id_token_expires_in: 3600,
profile_info: "redacted",
scope: "offline_access openid",
refresh_token: "redacted",
refresh_token_expires_in: 7776000,
} It seems like Azure AD B2C (my OIDC provider) responds only with an id token in a refresh request but the library always expects an access token to be present. Versionv6.1.1 RuntimeNode.js Runtime DetailsNode v22.8.0 Code to reproduceconst discoveryUrl = `https://${config.B2C_TENANT_NAME}.b2clogin.com/${config.B2C_TENANT_NAME}.onmicrosoft.com/${config.B2C_SIGN_IN_POLICY_NAME}/v2.0/.well-known/openid-configuration`;
const clientConfig = await discovery(
new URL(discoveryUrl),
config.B2C_CLIENT_ID,
{
[clockTolerance]: 5,
client_secret: config.B2C_CLIENT_SECRET,
},
);
const refreshToken = "my-refresh-token";
const tokens = await refreshTokenGrant(clientConfig, refreshToken); Required
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
The point of the refresh grant is to get a new fresh access token. As per the docs you've linked yourself there should always be one. I'd say the error is warranted. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your prompt response! |
Beta Was this translation helpful? Give feedback.
-
Thanks, I found another solution/workaround: When I add the Client ID as the first scope I also get an access token and everything works: Scopes before: const b2cOidcScopes = "openid offline_access profile email"; Scopes after: const B2C_CLIENT_ID = "90c0fe63-bcf2-44d5-8fb7-b8bbc0b29dc6"; // Example value
const b2cOidcScopes = `${B2C_CLIENT_ID} openid offline_access profile email`; Thanks for your help! Really appreciate it! |
Beta Was this translation helpful? Give feedback.
Thanks, I found another solution/workaround: When I add the Client ID as the first scope I also get an access token and everything works:
Scopes before:
Scopes after:
Thanks for your help! Really appreciate it!