@backstage/plugin-auth-backend-module-github-provider 0.3.0-next.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/authenticator.cjs.js +6 -1
- package/dist/authenticator.cjs.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @backstage/plugin-auth-backend-module-github-provider
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 61f464e: Added `auth.providers.<providerId>.sessionDuration` config for auth providers to allow the lifespan of user sessions to be configured.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- b40af03: Fixed a bug where the requested scope was ignored when refreshing sessions for a GitHub OAuth App. This would lead to access tokens being returned that didn't have the requested scope, and in turn errors when trying to use these tokens.
|
|
12
|
+
|
|
13
|
+
As part of this fix all existing sessions are being revoked in order to ensure that they receive the correct scope.
|
|
14
|
+
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
- @backstage/backend-plugin-api@1.2.0
|
|
17
|
+
- @backstage/plugin-auth-node@0.6.0
|
|
18
|
+
|
|
3
19
|
## 0.3.0-next.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var passportGithub2 = require('passport-github2');
|
|
4
4
|
var pluginAuthNode = require('@backstage/plugin-auth-node');
|
|
5
5
|
|
|
6
|
-
const ACCESS_TOKEN_PREFIX = "access-token.";
|
|
6
|
+
const ACCESS_TOKEN_PREFIX = "access-token-v2.";
|
|
7
7
|
const githubAuthenticator = pluginAuthNode.createOAuthAuthenticator({
|
|
8
8
|
defaultProfileTransform: pluginAuthNode.PassportOAuthAuthenticatorHelper.defaultProfileTransform,
|
|
9
9
|
scopes: {
|
|
@@ -52,6 +52,11 @@ const githubAuthenticator = pluginAuthNode.createOAuthAuthenticator({
|
|
|
52
52
|
},
|
|
53
53
|
async refresh(input, helper) {
|
|
54
54
|
if (input.refreshToken?.startsWith(ACCESS_TOKEN_PREFIX)) {
|
|
55
|
+
if (!input.scopeAlreadyGranted) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
"Refresh failed, session has not been granted the requested scope"
|
|
58
|
+
);
|
|
59
|
+
}
|
|
55
60
|
const accessToken = input.refreshToken.slice(ACCESS_TOKEN_PREFIX.length);
|
|
56
61
|
const fullProfile = await helper.fetchProfile(accessToken).catch((error) => {
|
|
57
62
|
if (error.oauthError?.statusCode === 401) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticator.cjs.js","sources":["../src/authenticator.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Strategy as GithubStrategy } from 'passport-github2';\nimport {\n createOAuthAuthenticator,\n PassportOAuthAuthenticatorHelper,\n PassportOAuthDoneCallback,\n PassportProfile,\n} from '@backstage/plugin-auth-node';\n\nconst ACCESS_TOKEN_PREFIX = 'access-token.';\n\n/** @public */\nexport const githubAuthenticator = createOAuthAuthenticator({\n defaultProfileTransform:\n PassportOAuthAuthenticatorHelper.defaultProfileTransform,\n scopes: {\n persist: true,\n required: ['read:user'],\n },\n initialize({ callbackUrl, config }) {\n const clientId = config.getString('clientId');\n const clientSecret = config.getString('clientSecret');\n const enterpriseInstanceUrl = config\n .getOptionalString('enterpriseInstanceUrl')\n ?.replace(/\\/$/, '');\n const authorizationUrl = enterpriseInstanceUrl\n ? `${enterpriseInstanceUrl}/login/oauth/authorize`\n : undefined;\n const tokenUrl = enterpriseInstanceUrl\n ? `${enterpriseInstanceUrl}/login/oauth/access_token`\n : undefined;\n const userProfileUrl = enterpriseInstanceUrl\n ? `${enterpriseInstanceUrl}/api/v3/user`\n : undefined;\n\n return PassportOAuthAuthenticatorHelper.from(\n new GithubStrategy(\n {\n clientID: clientId,\n clientSecret: clientSecret,\n callbackURL: callbackUrl,\n tokenURL: tokenUrl,\n userProfileURL: userProfileUrl,\n authorizationURL: authorizationUrl,\n },\n (\n accessToken: string,\n refreshToken: string,\n params: any,\n fullProfile: PassportProfile,\n done: PassportOAuthDoneCallback,\n ) => {\n done(\n undefined,\n { fullProfile, params, accessToken },\n { refreshToken },\n );\n },\n ),\n );\n },\n\n async start(input, helper) {\n return helper.start(input, {\n accessType: 'offline',\n prompt: 'consent',\n });\n },\n\n async authenticate(input, helper) {\n const { fullProfile, session } = await helper.authenticate(input);\n\n // If we do not have a real refresh token and we have a non-expiring\n // access token, then we use that as our refresh token.\n if (!session.refreshToken && !session.expiresInSeconds) {\n session.refreshToken = ACCESS_TOKEN_PREFIX + session.accessToken;\n }\n return { fullProfile, session };\n },\n\n async refresh(input, helper) {\n // This is the OAuth App flow. A non-expiring access token is stored in the\n // refresh token cookie. We use that token to fetch the user profile and\n // refresh the Backstage session when needed.\n if (input.refreshToken?.startsWith(ACCESS_TOKEN_PREFIX)) {\n const accessToken = input.refreshToken.slice(ACCESS_TOKEN_PREFIX.length);\n\n const fullProfile = await helper\n .fetchProfile(accessToken)\n .catch(error => {\n if (error.oauthError?.statusCode === 401) {\n throw new Error('Invalid access token');\n }\n throw error;\n });\n\n return {\n fullProfile,\n session: {\n accessToken,\n tokenType: 'bearer',\n scope: input.scope,\n refreshToken: input.refreshToken,\n // No expiration\n },\n };\n }\n\n // This is the App flow, which is close to a standard OAuth refresh flow. It has a\n // pretty long session expiration, and it also ignores the requested scope, instead\n // just allowing access to whatever is configured as part of the app installation.\n return helper.refresh(input);\n },\n});\n"],"names":["createOAuthAuthenticator","PassportOAuthAuthenticatorHelper","GithubStrategy"],"mappings":";;;;;AAwBA,MAAM,mBAAsB,GAAA,
|
|
1
|
+
{"version":3,"file":"authenticator.cjs.js","sources":["../src/authenticator.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Strategy as GithubStrategy } from 'passport-github2';\nimport {\n createOAuthAuthenticator,\n PassportOAuthAuthenticatorHelper,\n PassportOAuthDoneCallback,\n PassportProfile,\n} from '@backstage/plugin-auth-node';\n\nconst ACCESS_TOKEN_PREFIX = 'access-token-v2.';\n\n/** @public */\nexport const githubAuthenticator = createOAuthAuthenticator({\n defaultProfileTransform:\n PassportOAuthAuthenticatorHelper.defaultProfileTransform,\n scopes: {\n persist: true,\n required: ['read:user'],\n },\n initialize({ callbackUrl, config }) {\n const clientId = config.getString('clientId');\n const clientSecret = config.getString('clientSecret');\n const enterpriseInstanceUrl = config\n .getOptionalString('enterpriseInstanceUrl')\n ?.replace(/\\/$/, '');\n const authorizationUrl = enterpriseInstanceUrl\n ? `${enterpriseInstanceUrl}/login/oauth/authorize`\n : undefined;\n const tokenUrl = enterpriseInstanceUrl\n ? `${enterpriseInstanceUrl}/login/oauth/access_token`\n : undefined;\n const userProfileUrl = enterpriseInstanceUrl\n ? `${enterpriseInstanceUrl}/api/v3/user`\n : undefined;\n\n return PassportOAuthAuthenticatorHelper.from(\n new GithubStrategy(\n {\n clientID: clientId,\n clientSecret: clientSecret,\n callbackURL: callbackUrl,\n tokenURL: tokenUrl,\n userProfileURL: userProfileUrl,\n authorizationURL: authorizationUrl,\n },\n (\n accessToken: string,\n refreshToken: string,\n params: any,\n fullProfile: PassportProfile,\n done: PassportOAuthDoneCallback,\n ) => {\n done(\n undefined,\n { fullProfile, params, accessToken },\n { refreshToken },\n );\n },\n ),\n );\n },\n\n async start(input, helper) {\n return helper.start(input, {\n accessType: 'offline',\n prompt: 'consent',\n });\n },\n\n async authenticate(input, helper) {\n const { fullProfile, session } = await helper.authenticate(input);\n\n // If we do not have a real refresh token and we have a non-expiring\n // access token, then we use that as our refresh token.\n if (!session.refreshToken && !session.expiresInSeconds) {\n session.refreshToken = ACCESS_TOKEN_PREFIX + session.accessToken;\n }\n return { fullProfile, session };\n },\n\n async refresh(input, helper) {\n // This is the OAuth App flow. A non-expiring access token is stored in the\n // refresh token cookie. We use that token to fetch the user profile and\n // refresh the Backstage session when needed.\n if (input.refreshToken?.startsWith(ACCESS_TOKEN_PREFIX)) {\n if (!input.scopeAlreadyGranted) {\n throw new Error(\n 'Refresh failed, session has not been granted the requested scope',\n );\n }\n const accessToken = input.refreshToken.slice(ACCESS_TOKEN_PREFIX.length);\n\n const fullProfile = await helper\n .fetchProfile(accessToken)\n .catch(error => {\n if (error.oauthError?.statusCode === 401) {\n throw new Error('Invalid access token');\n }\n throw error;\n });\n\n return {\n fullProfile,\n session: {\n accessToken,\n tokenType: 'bearer',\n scope: input.scope,\n refreshToken: input.refreshToken,\n // No expiration\n },\n };\n }\n\n // This is the App flow, which is close to a standard OAuth refresh flow. It has a\n // pretty long session expiration, and it also ignores the requested scope, instead\n // just allowing access to whatever is configured as part of the app installation.\n return helper.refresh(input);\n },\n});\n"],"names":["createOAuthAuthenticator","PassportOAuthAuthenticatorHelper","GithubStrategy"],"mappings":";;;;;AAwBA,MAAM,mBAAsB,GAAA,kBAAA;AAGrB,MAAM,sBAAsBA,uCAAyB,CAAA;AAAA,EAC1D,yBACEC,+CAAiC,CAAA,uBAAA;AAAA,EACnC,MAAQ,EA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IAAO,OAAA,MAAA,CAAO,QAAQ,KAAK,CAAA;AAAA;AAE/B,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-auth-backend-module-github-provider",
|
|
3
|
-
"version": "0.3.0
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The github-provider backend module for the auth plugin.",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "backend-plugin-module",
|
|
@@ -37,16 +37,16 @@
|
|
|
37
37
|
"test": "backstage-cli package test"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@backstage/backend-plugin-api": "1.2.0
|
|
41
|
-
"@backstage/plugin-auth-node": "0.6.0
|
|
40
|
+
"@backstage/backend-plugin-api": "^1.2.0",
|
|
41
|
+
"@backstage/plugin-auth-node": "^0.6.0",
|
|
42
42
|
"passport-github2": "^0.1.12"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@backstage/backend-defaults": "0.8.0
|
|
46
|
-
"@backstage/backend-test-utils": "1.3.0
|
|
47
|
-
"@backstage/cli": "0.30.0
|
|
48
|
-
"@backstage/plugin-auth-backend": "0.24.3
|
|
49
|
-
"@backstage/types": "1.2.1",
|
|
45
|
+
"@backstage/backend-defaults": "^0.8.0",
|
|
46
|
+
"@backstage/backend-test-utils": "^1.3.0",
|
|
47
|
+
"@backstage/cli": "^0.30.0",
|
|
48
|
+
"@backstage/plugin-auth-backend": "^0.24.3",
|
|
49
|
+
"@backstage/types": "^1.2.1",
|
|
50
50
|
"supertest": "^7.0.0"
|
|
51
51
|
},
|
|
52
52
|
"configSchema": "config.d.ts",
|