From 9ad307a07cd7df4c7f90c5ee1de583c104e42eaa Mon Sep 17 00:00:00 2001 From: Leonardo Cardoso de Almeida Date: Thu, 29 Sep 2022 11:31:12 -0300 Subject: [PATCH 1/5] feat: add connection/connection scope options to auth0 provider Signed-off-by: Leonardo Cardoso de Almeida --- docs/auth/auth0/provider.md | 8 ++++++++ .../auth-backend/src/providers/auth0/provider.ts | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/docs/auth/auth0/provider.md b/docs/auth/auth0/provider.md index 1bfa333191..6d041647f3 100644 --- a/docs/auth/auth0/provider.md +++ b/docs/auth/auth0/provider.md @@ -35,6 +35,8 @@ auth: clientSecret: ${AUTH_AUTH0_CLIENT_SECRET} domain: ${AUTH_AUTH0_DOMAIN_ID} audience: ${AUTH_AUTH0_AUDIENCE} + connection: ${AUTH_AUTH0_CONNECTION} + connectionScope: ${AUTH_AUTH0_CONNECTION_SCOPE} ``` The Auth0 provider is a structure with three configuration keys: @@ -44,6 +46,12 @@ The Auth0 provider is a structure with three configuration keys: page - `domain`: The Application domain, found on the Auth0 Application page +## Optional Configuration + +- `audience`: The intended recipients of the token +- `connection`: Social identity provider name +- `connectionScope`: Additional scopes in the interactive token request. It should always be used in combination with the `connection` parameter + ## Adding the provider to the Backstage frontend To add the provider to the frontend, add the `auth0AuthApi` reference and diff --git a/plugins/auth-backend/src/providers/auth0/provider.ts b/plugins/auth-backend/src/providers/auth0/provider.ts index 309fb0fc7b..fe45b63b98 100644 --- a/plugins/auth-backend/src/providers/auth0/provider.ts +++ b/plugins/auth-backend/src/providers/auth0/provider.ts @@ -55,6 +55,8 @@ export type Auth0AuthProviderOptions = OAuthProviderOptions & { authHandler: AuthHandler; resolverContext: AuthResolverContext; audience?: string; + connection?: string; + connectionScope?: string; }; export class Auth0AuthProvider implements OAuthHandlers { @@ -63,6 +65,8 @@ export class Auth0AuthProvider implements OAuthHandlers { private readonly authHandler: AuthHandler; private readonly resolverContext: AuthResolverContext; private readonly audience?: string; + private readonly connection?: string; + private readonly connectionScope?: string; /** * Due to passport-auth0 forcing options.state = true, @@ -86,6 +90,8 @@ export class Auth0AuthProvider implements OAuthHandlers { this.authHandler = options.authHandler; this.resolverContext = options.resolverContext; this.audience = options.audience; + this.connection = options.connection; + this.connectionScope = options.connectionScope; this._strategy = new Auth0Strategy( { clientID: options.clientId, @@ -127,6 +133,8 @@ export class Auth0AuthProvider implements OAuthHandlers { scope: req.scope, state: encodeState(req.state), ...(this.audience ? { audience: this.audience } : {}), + ...(this.connection ? { connection: this.connection } : {}), + ...(this.connectionScope ? { connection_scope: this.connectionScope } : {}), }); } @@ -136,6 +144,8 @@ export class Auth0AuthProvider implements OAuthHandlers { PrivateInfo >(req, this._strategy, { ...(this.audience ? { audience: this.audience } : {}), + ...(this.connection ? { connection: this.connection } : {}), + ...(this.connectionScope ? { connection_scope: this.connectionScope } : {}), }); return { @@ -224,6 +234,8 @@ export const auth0 = createAuthProviderIntegration({ const domain = envConfig.getString('domain'); const customCallbackUrl = envConfig.getOptionalString('callbackUrl'); const audience = envConfig.getOptionalString('audience'); + const connection = envConfig.getOptionalString('connection'); + const connectionScope = envConfig.getOptionalString('connectionScope'); const callbackUrl = customCallbackUrl || `${globalConfig.baseUrl}/${providerId}/handler/frame`; @@ -245,6 +257,8 @@ export const auth0 = createAuthProviderIntegration({ signInResolver, resolverContext, audience, + connection, + connectionScope, }); return OAuthAdapter.fromConfig(globalConfig, provider, { From b5c126010c3a7a144ac0f6aee2557b718c2e5707 Mon Sep 17 00:00:00 2001 From: Leonardo Cardoso de Almeida Date: Thu, 29 Sep 2022 12:01:30 -0300 Subject: [PATCH 2/5] chore: create changeset Signed-off-by: Leonardo Cardoso de Almeida --- .changeset/pretty-buttons-develop.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/pretty-buttons-develop.md diff --git a/.changeset/pretty-buttons-develop.md b/.changeset/pretty-buttons-develop.md new file mode 100644 index 0000000000..67fbaeaae5 --- /dev/null +++ b/.changeset/pretty-buttons-develop.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-auth-backend': minor +--- + +Auth0 provider now supports optional `connection` and `connectionScope` parameters to configure social identity providers. From b1f9a031aa6673edc01b093e49585ef86e47f59c Mon Sep 17 00:00:00 2001 From: Leonardo Cardoso de Almeida Date: Thu, 29 Sep 2022 12:13:26 -0300 Subject: [PATCH 3/5] style: prettify auth0 provider codestyle Signed-off-by: Leonardo Cardoso de Almeida --- plugins/auth-backend/src/providers/auth0/provider.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/auth-backend/src/providers/auth0/provider.ts b/plugins/auth-backend/src/providers/auth0/provider.ts index fe45b63b98..95e83d2cce 100644 --- a/plugins/auth-backend/src/providers/auth0/provider.ts +++ b/plugins/auth-backend/src/providers/auth0/provider.ts @@ -134,7 +134,9 @@ export class Auth0AuthProvider implements OAuthHandlers { state: encodeState(req.state), ...(this.audience ? { audience: this.audience } : {}), ...(this.connection ? { connection: this.connection } : {}), - ...(this.connectionScope ? { connection_scope: this.connectionScope } : {}), + ...(this.connectionScope + ? { connection_scope: this.connectionScope } + : {}), }); } @@ -145,7 +147,9 @@ export class Auth0AuthProvider implements OAuthHandlers { >(req, this._strategy, { ...(this.audience ? { audience: this.audience } : {}), ...(this.connection ? { connection: this.connection } : {}), - ...(this.connectionScope ? { connection_scope: this.connectionScope } : {}), + ...(this.connectionScope + ? { connection_scope: this.connectionScope } + : {}), }); return { From c4d6c74cbb7d998a7910d93a1e86ba5ffad0ec54 Mon Sep 17 00:00:00 2001 From: Leonardo Cardoso de Almeida <105804599+imleozzito@users.noreply.github.com> Date: Fri, 30 Sep 2022 10:30:24 -0300 Subject: [PATCH 4/5] Update .changeset/pretty-buttons-develop.md Co-authored-by: Johan Haals Signed-off-by: Leonardo Cardoso de Almeida <105804599+imleozzito@users.noreply.github.com> --- .changeset/pretty-buttons-develop.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/pretty-buttons-develop.md b/.changeset/pretty-buttons-develop.md index 67fbaeaae5..7c686df250 100644 --- a/.changeset/pretty-buttons-develop.md +++ b/.changeset/pretty-buttons-develop.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-auth-backend': minor +'@backstage/plugin-auth-backend': patch --- Auth0 provider now supports optional `connection` and `connectionScope` parameters to configure social identity providers. From 9cf69e11a3e9cc5bce24fb60aa576e44bbb36b9a Mon Sep 17 00:00:00 2001 From: Leonardo Cardoso de Almeida <105804599+imleozzito@users.noreply.github.com> Date: Fri, 30 Sep 2022 10:30:56 -0300 Subject: [PATCH 5/5] Update docs/auth/auth0/provider.md Co-authored-by: Johan Haals Signed-off-by: Leonardo Cardoso de Almeida <105804599+imleozzito@users.noreply.github.com> --- docs/auth/auth0/provider.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/auth/auth0/provider.md b/docs/auth/auth0/provider.md index 6d041647f3..6fb57a641b 100644 --- a/docs/auth/auth0/provider.md +++ b/docs/auth/auth0/provider.md @@ -49,7 +49,7 @@ The Auth0 provider is a structure with three configuration keys: ## Optional Configuration - `audience`: The intended recipients of the token -- `connection`: Social identity provider name +- `connection`: Social identity provider name. To check the available social connections, please visit [Auth0 Social Connections](https://marketplace.auth0.com/features/social-connections). - `connectionScope`: Additional scopes in the interactive token request. It should always be used in combination with the `connection` parameter ## Adding the provider to the Backstage frontend