From 8a60033962c0e529c81f12c1695225377c59242b Mon Sep 17 00:00:00 2001 From: Zach Falen Date: Fri, 12 Nov 2021 12:53:13 -0700 Subject: [PATCH 1/3] hotfix for Backstage token generation, prefer .token over .idToken Signed-off-by: Zach Falen --- .../src/layout/SignInPage/commonProvider.tsx | 4 +++- plugins/auth-backend/src/lib/oauth/OAuthAdapter.ts | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/core-components/src/layout/SignInPage/commonProvider.tsx b/packages/core-components/src/layout/SignInPage/commonProvider.tsx index 103050a2d9..515ae01e4d 100644 --- a/packages/core-components/src/layout/SignInPage/commonProvider.tsx +++ b/packages/core-components/src/layout/SignInPage/commonProvider.tsx @@ -49,7 +49,9 @@ const Component: ProviderComponent = ({ config, onResult }) => { userId: identity!.id, profile: profile!, getIdToken: () => { - return authApi.getBackstageIdentity().then(i => i!.idToken); + return authApi + .getBackstageIdentity() + .then(i => i!.token ?? i!.idToken); }, signOut: async () => { await authApi.signOut(); diff --git a/plugins/auth-backend/src/lib/oauth/OAuthAdapter.ts b/plugins/auth-backend/src/lib/oauth/OAuthAdapter.ts index a5128711bc..24b9a0f210 100644 --- a/plugins/auth-backend/src/lib/oauth/OAuthAdapter.ts +++ b/plugins/auth-backend/src/lib/oauth/OAuthAdapter.ts @@ -233,10 +233,12 @@ export class OAuthAdapter implements AuthProviderRouteHandlers { return; } - if (!identity.idToken) { - identity.idToken = await this.options.tokenIssuer.issueToken({ + if (!(identity.token || identity.idToken)) { + identity.token = await this.options.tokenIssuer.issueToken({ claims: { sub: identity.id }, }); + } else if (!identity.token && identity.idToken) { + identity.token = identity.idToken; } } From 892c1d9202f42856e7585d670abb75f1d7059eaf Mon Sep 17 00:00:00 2001 From: Zach Falen Date: Fri, 12 Nov 2021 12:56:33 -0700 Subject: [PATCH 2/3] add changeset Signed-off-by: Zach Falen --- .changeset/ninety-grapes-love.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/ninety-grapes-love.md diff --git a/.changeset/ninety-grapes-love.md b/.changeset/ninety-grapes-love.md new file mode 100644 index 0000000000..9143bddd30 --- /dev/null +++ b/.changeset/ninety-grapes-love.md @@ -0,0 +1,6 @@ +--- +'@backstage/core-components': patch +'@backstage/plugin-auth-backend': patch +--- + +Update OAuthAdapter to create identity.token from identity.idToken if it does not exist, and prevent overwrites to identity.toke. Update login page commonProvider to prefer .token over .idToken From 7d6ab03ebbfc14ec4f1c8d0ebf9fa7957a200457 Mon Sep 17 00:00:00 2001 From: Zach Falen Date: Fri, 12 Nov 2021 13:32:48 -0700 Subject: [PATCH 3/3] update test Signed-off-by: Zach Falen --- plugins/auth-backend/src/lib/oauth/OAuthAdapter.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/auth-backend/src/lib/oauth/OAuthAdapter.test.ts b/plugins/auth-backend/src/lib/oauth/OAuthAdapter.test.ts index 27b629cc07..dfb3a0a79a 100644 --- a/plugins/auth-backend/src/lib/oauth/OAuthAdapter.test.ts +++ b/plugins/auth-backend/src/lib/oauth/OAuthAdapter.test.ts @@ -22,7 +22,7 @@ import { OAuthHandlers } from './types'; const mockResponseData = { providerInfo: { accessToken: 'ACCESS_TOKEN', - idToken: 'ID_TOKEN', + token: 'ID_TOKEN', expiresInSeconds: 10, scope: 'email', }, @@ -216,7 +216,7 @@ describe('OAuthAdapter', () => { ...mockResponseData, backstageIdentity: { id: mockResponseData.backstageIdentity.id, - idToken: 'my-id-token', + token: 'my-id-token', }, }); });