Skip to content

Commit

Permalink
refactor(core): remove offline_access scope by default
Browse files Browse the repository at this point in the history
remove the offline_access scope by default
  • Loading branch information
simeng-li committed Oct 14, 2024
1 parent 791feb7 commit 54c6f7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
10 changes: 6 additions & 4 deletions packages/core/src/libraries/sso-connector.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Prompt, QueryKey, withReservedScopes } from '@logto/js';
import { Prompt, QueryKey, ReservedScope, UserScope } from '@logto/js';
import { ApplicationType, type SsoConnectorIdpInitiatedAuthConfig } from '@logto/schemas';

import { mockSsoConnector, wellConfiguredSsoConnector } from '#src/__mocks__/sso.js';
Expand Down Expand Up @@ -204,7 +204,7 @@ describe('SsoConnectorLibrary', () => {
for (const [key, value] of Object.entries(defaultQueryParameters)) {
expect(parameters.get(key)).toBe(value);
}
expect(parameters.get(QueryKey.Scope)).toBe(withReservedScopes());
expect(parameters.get(QueryKey.Scope)).toBe(`${ReservedScope.OpenId} ${UserScope.Profile}`);
});

it('should use the provided redirectUri', async () => {
Expand Down Expand Up @@ -233,7 +233,7 @@ describe('SsoConnectorLibrary', () => {
});

it('should append extra scopes to the query parameters', async () => {
const scopes = ['scope1', 'scope2'];
const scopes = ['organization', 'email', 'profile'];

const url = await getIdpInitiatedSamlSsoSignInUrl(issuer, {
...authConfig,
Expand All @@ -243,7 +243,9 @@ describe('SsoConnectorLibrary', () => {
});

const parameters = new URLSearchParams(url.search);
expect(parameters.get(QueryKey.Scope)).toBe(withReservedScopes(scopes));
expect(parameters.get(QueryKey.Scope)).toBe(
`${ReservedScope.OpenId} ${UserScope.Profile} organization email`
);
});

it('should be able to append extra query parameters', async () => {
Expand Down
13 changes: 10 additions & 3 deletions packages/core/src/libraries/sso-connector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type DirectSignInOptions, Prompt, QueryKey, withReservedScopes } from '@logto/js';
import { type DirectSignInOptions, Prompt, QueryKey, ReservedScope, UserScope } from '@logto/js';
import {
ApplicationType,
type SsoSamlAssertionContent,
Expand All @@ -7,7 +7,7 @@ import {
type SsoConnectorIdpInitiatedAuthConfig,
} from '@logto/schemas';
import { generateStandardId } from '@logto/shared';
import { assert, trySafe } from '@silverhand/essentials';
import { assert, deduplicate, trySafe } from '@silverhand/essentials';

import { defaultIdPInitiatedSamlSsoSessionTtl } from '#src/constants/index.js';
import RequestError from '#src/errors/RequestError/index.js';
Expand Down Expand Up @@ -141,6 +141,9 @@ export const createSsoConnectorLibrary = (queries: Queries) => {
*
* @remarks
* For IdP-initiated SAML SSO flow use only. Generate the sign-in URL for the user to sign in.
* Default scopes: openid, profile
* Default prompt: login
* Default response type: code
*
* @param issuer The oidc issuer endpoint of the current tenant.
* @param authConfig The IdP-initiated SAML SSO authentication configuration.
Expand Down Expand Up @@ -183,7 +186,11 @@ export const createSsoConnectorLibrary = (queries: Queries) => {
...extraParams,
});

queryParameters.append(QueryKey.Scope, withReservedScopes(scope?.split(' ') ?? []));
queryParameters.append(
QueryKey.Scope,
// For security reasons, DO NOT include the offline_access scope for IdP-initiated SAML SSO by default
deduplicate([ReservedScope.OpenId, UserScope.Profile, ...(scope?.split(' ') ?? [])]).join(' ')
);

return new URL(`${issuer}/auth?${queryParameters.toString()}`);
};
Expand Down

0 comments on commit 54c6f7a

Please sign in to comment.