diff --git a/src/accounts/openid.js b/src/accounts/openid.js index cd1a80f7b..2080a3bcb 100644 --- a/src/accounts/openid.js +++ b/src/accounts/openid.js @@ -170,11 +170,22 @@ export async function loginWithOpenIdFinalize(body) { let { code_verifier, return_url } = pendingRequest; try { - const params = { code: body.code, state: body.state }; - let tokenSet = await client.callback(client.redirect_uris[0], params, { - code_verifier, - state: body.state, - }); + let tokenSet = null; + + if (!config.authMethod || config.authMethod === 'openid') { + const params = { code: body.code, state: body.state }; + tokenSet = await client.callback(client.redirect_uris[0], params, { + code_verifier, + state: body.state, + }); + } else { + tokenSet = await client.grant({ + grant_type: 'authorization_code', + code: body.code, + redirect_uri: client.redirect_uris[0], + code_verifier, + }); + } const userInfo = await client.userinfo(tokenSet.access_token); const identity = userInfo.preferred_username ?? diff --git a/src/config-types.ts b/src/config-types.ts index 778982d59..3feecc9ec 100644 --- a/src/config-types.ts +++ b/src/config-types.ts @@ -32,6 +32,7 @@ export interface Config { client_id: string; client_secret: string; server_hostname: string; + authMethod?: 'openid' | 'oauth2'; }; multiuser: boolean; token_expiration?: 'never' | 'openid-provider' | number; diff --git a/upcoming-release-notes/527.md b/upcoming-release-notes/527.md index 5633eaa35..575328f07 100644 --- a/upcoming-release-notes/527.md +++ b/upcoming-release-notes/527.md @@ -3,4 +3,4 @@ category: Enhancements authors: [lelemm] --- -Commands to enable/disable OpenID from console. +Commands to enable/disable OpenID from console. Also, enabling to login with oauth2 (for github).