Skip to content

Commit 47b2547

Browse files
authored
fix(core): make access_token optional for Azure SSO (#7457)
make access_token optional in Azure OIDC SSO connector token response
1 parent f2cd1ff commit 47b2547

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

.changeset/lemon-walls-fry.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@logto/core": patch
3+
---
4+
5+
fix: make `access_token` optional for Azure OIDC SSO connector
6+
7+
Previously, the Azure OIDC connector strictly required an access token in the token response, which caused issues with Azure B2C applications that only return ID tokens.
8+
9+
This change makes the connector more flexible by:
10+
11+
- Making access token optional in token response
12+
- Conditionally fetching user claims from userinfo endpoint only when:
13+
- Access token is present in the response
14+
- Userinfo endpoint is supported by the provider
15+
- Falling back to ID token claims when access token is not available

packages/core/src/sso/AzureOidcSsoConnector/index.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import camelcaseKeys from 'camelcase-keys';
44
import { decodeJwt } from 'jose';
55
import { z } from 'zod';
66

7-
import assertThat from '#src/utils/assert-that.js';
8-
97
import OidcConnector from '../OidcConnector/index.js';
108
import { fetchToken, getIdTokenClaims, getUserInfo } from '../OidcConnector/utils.js';
119
import { type SingleSignOnFactory } from '../index.js';
@@ -76,13 +74,6 @@ export class AzureOidcSsoConnector extends OidcConnector implements SingleSignOn
7674
// Fetch token from the OIDC provider using authorization code
7775
const { idToken, accessToken } = await fetchToken(oidcConfig, data, redirectUri);
7876

79-
assertThat(
80-
accessToken,
81-
new SsoConnectorError(SsoConnectorErrorCodes.AuthorizationFailed, {
82-
message: 'The access token is missing from the response.',
83-
})
84-
);
85-
8677
// Need to decode the id token to get the tenant id
8778
const decodeToken = decodeJwt(idToken);
8879

@@ -97,9 +88,10 @@ export class AzureOidcSsoConnector extends OidcConnector implements SingleSignOn
9788
// Verify the id token and get the claims
9889
const idTokenClaims = await getIdTokenClaims(idToken, oidcConfig, nonce, jwtVerifyOptions);
9990
// Fetch user info from the userinfo endpoint
100-
const userInfoClaims = oidcConfig.userinfoEndpoint
101-
? await getUserInfo(accessToken, oidcConfig.userinfoEndpoint)
102-
: undefined;
91+
const userInfoClaims =
92+
oidcConfig.userinfoEndpoint && accessToken
93+
? await getUserInfo(accessToken, oidcConfig.userinfoEndpoint)
94+
: undefined;
10395

10496
// Merge the claims from id token and userinfo endpoint as in Azure AD, some claims are only available in the userinfo endpoint
10597
const mergedClaims = {

0 commit comments

Comments
 (0)