+
Skip to content

Allow scope values with 'openid' in their name #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/keycloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,15 @@ function Keycloak (config) {
: kc.endpoints.authorize();

let scope = options?.scope || kc.scope;
if (!scope) {
// if scope is not set, default to "openid"
scope = "openid";
} else if (!scope.includes("openid")) {
// if openid scope is missing, prefix the given scopes with it
scope = `openid ${scope}`;
const scopeValues = scope ? scope.split(' ') : [];

// Ensure the 'openid' scope is always included.
if (!scopeValues.includes('openid')) {
scopeValues.unshift('openid');
}

scope = scopeValues.join(' ');

const params = new URLSearchParams([
['client_id', kc.clientId],
['redirect_uri', redirectUri],
Expand Down
4 changes: 2 additions & 2 deletions test/tests/login-url.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ test('creates a login URL using the scope passed during initialization', async (

test("creates a login URL with the 'openid' scope appended if omitted", async ({ page, appUrl, authServerUrl }) => {
const { executor } = await createTestBed(page, { appUrl, authServerUrl })
const initOptions: KeycloakInitOptions = { ...executor.defaultInitOptions(), scope: 'profile email' }
const initOptions: KeycloakInitOptions = { ...executor.defaultInitOptions(), scope: 'profile email openidlike' }
await executor.initializeAdapter(initOptions)
const loginUrl = new URL(await executor.createLoginUrl())
expect(loginUrl.searchParams.get('scope')).toBe('openid profile email')
expect(loginUrl.searchParams.get('scope')).toBe('openid profile email openidlike')
})

test('creates a login URL using the response mode passed during initialization', async ({ page, appUrl, authServerUrl }) => {
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载