From c983e6ebfff916684ffd69af4138b041633ebf7e Mon Sep 17 00:00:00 2001 From: Fidel Coria Date: Mon, 14 Dec 2020 18:24:49 -0600 Subject: [PATCH 1/4] customizable storage key --- .../implementations/auth/github/GithubAuth.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/core-api/src/apis/implementations/auth/github/GithubAuth.ts b/packages/core-api/src/apis/implementations/auth/github/GithubAuth.ts index 812032a8a3..a32f77fb88 100644 --- a/packages/core-api/src/apis/implementations/auth/github/GithubAuth.ts +++ b/packages/core-api/src/apis/implementations/auth/github/GithubAuth.ts @@ -50,13 +50,16 @@ const DEFAULT_PROVIDER = { }; class GithubAuth implements OAuthApi, SessionApi { - static create({ - discoveryApi, - environment = 'development', - provider = DEFAULT_PROVIDER, - oauthRequestApi, - defaultScopes = ['read:user'], - }: OAuthApiCreateOptions) { + static create( + { + discoveryApi, + environment = 'development', + provider = DEFAULT_PROVIDER, + oauthRequestApi, + defaultScopes = ['read:user'], + }: OAuthApiCreateOptions, + storageKey = 'githubSession', + ) { const connector = new DefaultAuthConnector({ discoveryApi, environment, @@ -84,7 +87,7 @@ class GithubAuth implements OAuthApi, SessionApi { const authSessionStore = new AuthSessionStore({ manager: sessionManager, - storageKey: 'githubSession', + storageKey: storageKey, sessionScopes: (session: GithubSession) => session.providerInfo.scopes, }); From 7dd2ef7d1c4d7be069e15e92fce8e2c9ab288b0b Mon Sep 17 00:00:00 2001 From: Fidel Coria Date: Mon, 14 Dec 2020 18:45:54 -0600 Subject: [PATCH 2/4] add change log --- .changeset/sour-badgers-cry.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/sour-badgers-cry.md diff --git a/.changeset/sour-badgers-cry.md b/.changeset/sour-badgers-cry.md new file mode 100644 index 0000000000..41bb0be6ec --- /dev/null +++ b/.changeset/sour-badgers-cry.md @@ -0,0 +1,5 @@ +--- +'@backstage/core-api': patch +--- + +Add argument for storage key to GitHub Auth Api for customizing it's value. From 639883d468c1e70b9f2d83c2458d60bcfa18baeb Mon Sep 17 00:00:00 2001 From: Fidel Coria Date: Tue, 15 Dec 2020 14:30:06 -0600 Subject: [PATCH 3/4] use provider.id instead of arg --- .../implementations/auth/github/GithubAuth.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/core-api/src/apis/implementations/auth/github/GithubAuth.ts b/packages/core-api/src/apis/implementations/auth/github/GithubAuth.ts index a32f77fb88..a7c945a907 100644 --- a/packages/core-api/src/apis/implementations/auth/github/GithubAuth.ts +++ b/packages/core-api/src/apis/implementations/auth/github/GithubAuth.ts @@ -50,16 +50,13 @@ const DEFAULT_PROVIDER = { }; class GithubAuth implements OAuthApi, SessionApi { - static create( - { - discoveryApi, - environment = 'development', - provider = DEFAULT_PROVIDER, - oauthRequestApi, - defaultScopes = ['read:user'], - }: OAuthApiCreateOptions, - storageKey = 'githubSession', - ) { + static create({ + discoveryApi, + environment = 'development', + provider = DEFAULT_PROVIDER, + oauthRequestApi, + defaultScopes = ['read:user'], + }: OAuthApiCreateOptions) { const connector = new DefaultAuthConnector({ discoveryApi, environment, @@ -87,7 +84,7 @@ class GithubAuth implements OAuthApi, SessionApi { const authSessionStore = new AuthSessionStore({ manager: sessionManager, - storageKey: storageKey, + storageKey: `${provider.id}Session`, sessionScopes: (session: GithubSession) => session.providerInfo.scopes, }); From 7952667abf1ebf5caef7015b0435196c78c11a4e Mon Sep 17 00:00:00 2001 From: Fidel Coria Date: Tue, 15 Dec 2020 14:35:40 -0600 Subject: [PATCH 4/4] update changelog --- .changeset/sour-badgers-cry.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/sour-badgers-cry.md b/.changeset/sour-badgers-cry.md index 41bb0be6ec..cd5aaf7afb 100644 --- a/.changeset/sour-badgers-cry.md +++ b/.changeset/sour-badgers-cry.md @@ -2,4 +2,4 @@ '@backstage/core-api': patch --- -Add argument for storage key to GitHub Auth Api for customizing it's value. +GitHub Auth Api uses provider.id to build storage key name.