@backstage/plugin-auth-backend-module-oauth2-proxy-provider 0.0.0-nightly-20231129021646

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 ADDED
@@ -0,0 +1,29 @@
1
+ # @backstage/plugin-auth-backend-module-oauth2-proxy-provider
2
+
3
+ ## 0.0.0-nightly-20231129021646
4
+
5
+ ### Minor Changes
6
+
7
+ - 271aa12: Release of `oauth2-proxy-provider` plugin
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @backstage/backend-common@0.0.0-nightly-20231129021646
13
+ - @backstage/plugin-auth-node@0.0.0-nightly-20231129021646
14
+ - @backstage/backend-plugin-api@0.0.0-nightly-20231129021646
15
+ - @backstage/errors@1.2.3
16
+
17
+ ## 0.1.0-next.0
18
+
19
+ ### Minor Changes
20
+
21
+ - 271aa12c7c: Release of `oauth2-proxy-provider` plugin
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies
26
+ - @backstage/backend-common@0.20.0-next.1
27
+ - @backstage/backend-plugin-api@0.6.8-next.1
28
+ - @backstage/errors@1.2.3
29
+ - @backstage/plugin-auth-node@0.4.2-next.1
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @backstage/plugin-auth-backend-module-oauth2-proxy-provider
2
+
3
+ The oauth2-proxy-provider backend module for the auth plugin.
4
+
5
+ _This plugin was created through the Backstage CLI_
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var backendPluginApi = require('@backstage/backend-plugin-api');
6
+ var pluginAuthNode = require('@backstage/plugin-auth-node');
7
+ var errors = require('@backstage/errors');
8
+ var jose = require('jose');
9
+
10
+ const OAUTH2_PROXY_JWT_HEADER = "X-OAUTH2-PROXY-ID-TOKEN";
11
+ const oauth2ProxyAuthenticator = pluginAuthNode.createProxyAuthenticator({
12
+ defaultProfileTransform: async (result) => {
13
+ return {
14
+ profile: {
15
+ email: result.getHeader("x-forwarded-email"),
16
+ displayName: result.getHeader("x-forwarded-preferred-username") || result.getHeader("x-forwarded-user")
17
+ }
18
+ };
19
+ },
20
+ async initialize() {
21
+ },
22
+ async authenticate({ req }) {
23
+ try {
24
+ const authHeader = req.header(OAUTH2_PROXY_JWT_HEADER);
25
+ const jwt = pluginAuthNode.getBearerTokenFromAuthorizationHeader(authHeader);
26
+ const decodedJWT = jwt && jose.decodeJwt(jwt);
27
+ const result = {
28
+ fullProfile: decodedJWT || {},
29
+ accessToken: jwt || "",
30
+ headers: req.headers,
31
+ getHeader(name) {
32
+ if (name.toLocaleLowerCase("en-US") === "set-cookie") {
33
+ throw new Error("Access Set-Cookie via the headers object instead");
34
+ }
35
+ return req.get(name);
36
+ }
37
+ };
38
+ return { result };
39
+ } catch (e) {
40
+ throw new errors.AuthenticationError("Authentication failed", e);
41
+ }
42
+ }
43
+ });
44
+
45
+ var oauth2ProxySignInResolvers;
46
+ ((oauth2ProxySignInResolvers2) => {
47
+ oauth2ProxySignInResolvers2.forwardedUserMatchingUserEntityName = pluginAuthNode.createSignInResolverFactory({
48
+ create() {
49
+ return async (info, ctx) => {
50
+ const name = info.result.getHeader("x-forwarded-user");
51
+ if (!name) {
52
+ throw new Error("Request did not contain a user");
53
+ }
54
+ return ctx.signInWithCatalogUser({
55
+ entityRef: { name }
56
+ });
57
+ };
58
+ }
59
+ });
60
+ })(oauth2ProxySignInResolvers || (oauth2ProxySignInResolvers = {}));
61
+
62
+ const authModuleOauth2ProxyProvider = backendPluginApi.createBackendModule({
63
+ pluginId: "auth",
64
+ moduleId: "oauth2ProxyProvider",
65
+ register(reg) {
66
+ reg.registerInit({
67
+ deps: {
68
+ providers: pluginAuthNode.authProvidersExtensionPoint
69
+ },
70
+ async init({ providers }) {
71
+ providers.registerProvider({
72
+ providerId: "oauth2ProxyProvider",
73
+ factory: pluginAuthNode.createProxyAuthProviderFactory({
74
+ authenticator: oauth2ProxyAuthenticator,
75
+ signInResolverFactories: {
76
+ ...pluginAuthNode.commonSignInResolvers,
77
+ ...oauth2ProxySignInResolvers
78
+ }
79
+ })
80
+ });
81
+ }
82
+ });
83
+ }
84
+ });
85
+
86
+ exports.OAUTH2_PROXY_JWT_HEADER = OAUTH2_PROXY_JWT_HEADER;
87
+ exports.authModuleOauth2ProxyProvider = authModuleOauth2ProxyProvider;
88
+ exports.oauth2ProxyAuthenticator = oauth2ProxyAuthenticator;
89
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/authenticator.ts","../src/resolvers.ts","../src/module.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 { AuthenticationError } from '@backstage/errors';\nimport {\n createProxyAuthenticator,\n getBearerTokenFromAuthorizationHeader,\n} from '@backstage/plugin-auth-node';\nimport { decodeJwt } from 'jose';\nimport { OAuth2ProxyResult } from './types';\n\n/**\n * NOTE: This may come in handy if you're doing work on this provider:\n * plugins/auth-backend/examples/docker-compose.oauth2-proxy.yaml\n *\n * @public\n */\nexport const OAUTH2_PROXY_JWT_HEADER = 'X-OAUTH2-PROXY-ID-TOKEN';\n\n/** @public */\nexport const oauth2ProxyAuthenticator = createProxyAuthenticator<\n unknown,\n OAuth2ProxyResult\n>({\n defaultProfileTransform: async (result: OAuth2ProxyResult) => {\n return {\n profile: {\n email: result.getHeader('x-forwarded-email'),\n displayName:\n result.getHeader('x-forwarded-preferred-username') ||\n result.getHeader('x-forwarded-user'),\n },\n };\n },\n async initialize() {},\n async authenticate({ req }) {\n try {\n const authHeader = req.header(OAUTH2_PROXY_JWT_HEADER);\n const jwt = getBearerTokenFromAuthorizationHeader(authHeader);\n const decodedJWT = jwt && decodeJwt(jwt);\n\n const result = {\n fullProfile: decodedJWT || {},\n accessToken: jwt || '',\n headers: req.headers,\n getHeader(name: string) {\n if (name.toLocaleLowerCase('en-US') === 'set-cookie') {\n throw new Error('Access Set-Cookie via the headers object instead');\n }\n return req.get(name);\n },\n };\n return { result };\n } catch (e) {\n throw new AuthenticationError('Authentication failed', e);\n }\n },\n});\n","/*\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 {\n createSignInResolverFactory,\n SignInInfo,\n} from '@backstage/plugin-auth-node';\nimport { OAuth2ProxyResult } from './types';\n\n/**\n * @public\n */\nexport namespace oauth2ProxySignInResolvers {\n export const forwardedUserMatchingUserEntityName =\n createSignInResolverFactory({\n create() {\n return async (info: SignInInfo<OAuth2ProxyResult>, ctx) => {\n const name = info.result.getHeader('x-forwarded-user');\n if (!name) {\n throw new Error('Request did not contain a user');\n }\n return ctx.signInWithCatalogUser({\n entityRef: { name },\n });\n };\n },\n });\n}\n","/*\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 { createBackendModule } from '@backstage/backend-plugin-api';\nimport {\n authProvidersExtensionPoint,\n createProxyAuthProviderFactory,\n commonSignInResolvers,\n} from '@backstage/plugin-auth-node';\nimport { oauth2ProxyAuthenticator } from './authenticator';\nimport { oauth2ProxySignInResolvers } from './resolvers';\n\n/** @public */\nexport const authModuleOauth2ProxyProvider = createBackendModule({\n pluginId: 'auth',\n moduleId: 'oauth2ProxyProvider',\n register(reg) {\n reg.registerInit({\n deps: {\n providers: authProvidersExtensionPoint,\n },\n async init({ providers }) {\n providers.registerProvider({\n providerId: 'oauth2ProxyProvider',\n factory: createProxyAuthProviderFactory({\n authenticator: oauth2ProxyAuthenticator,\n signInResolverFactories: {\n ...commonSignInResolvers,\n ...oauth2ProxySignInResolvers,\n },\n }),\n });\n },\n });\n },\n});\n"],"names":["createProxyAuthenticator","getBearerTokenFromAuthorizationHeader","decodeJwt","AuthenticationError","oauth2ProxySignInResolvers","createSignInResolverFactory","createBackendModule","authProvidersExtensionPoint","createProxyAuthProviderFactory","commonSignInResolvers"],"mappings":";;;;;;;;;AA8BO,MAAM,uBAA0B,GAAA,0BAAA;AAGhC,MAAM,2BAA2BA,uCAGtC,CAAA;AAAA,EACA,uBAAA,EAAyB,OAAO,MAA8B,KAAA;AAC5D,IAAO,OAAA;AAAA,MACL,OAAS,EAAA;AAAA,QACP,KAAA,EAAO,MAAO,CAAA,SAAA,CAAU,mBAAmB,CAAA;AAAA,QAC3C,aACE,MAAO,CAAA,SAAA,CAAU,gCAAgC,CACjD,IAAA,MAAA,CAAO,UAAU,kBAAkB,CAAA;AAAA,OACvC;AAAA,KACF,CAAA;AAAA,GACF;AAAA,EACA,MAAM,UAAa,GAAA;AAAA,GAAC;AAAA,EACpB,MAAM,YAAA,CAAa,EAAE,GAAA,EAAO,EAAA;AAC1B,IAAI,IAAA;AACF,MAAM,MAAA,UAAA,GAAa,GAAI,CAAA,MAAA,CAAO,uBAAuB,CAAA,CAAA;AACrD,MAAM,MAAA,GA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AAA,CAAA,CAAA;;ACCV,MAAM,gCAAgCC,oCAAoB,CAAA;AAAA,EAC/D,QAAU,EAAA,MAAA;AAAA,EACV,QAAU,EAAA,qBAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,SAAW,EAAAC,0CAAA;AAAA,OACb;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,SAAA,EAAa,EAAA;AACxB,QAAA,SAAA,CAAU,gBAAiB,CAAA;AAAA,UACzB,UAAY,EAAA,qBAAA;AAAA,UACZ,SAASC,6CAA+B,CAAA;AAAA,YACtC,aAAe,EAAA,wBAAA;AAAA,YACf,uBAAyB,EAAA;AAAA,cACvB,GAAGC,oCAAA;AAAA,cACH,GAAG,0BAAA;AAAA,aACL;AAAA,WACD,CAAA;AAAA,SACF,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;;"}
@@ -0,0 +1,59 @@
1
+ /// <reference types="node" />
2
+ import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
3
+ import * as _backstage_plugin_auth_node from '@backstage/plugin-auth-node';
4
+ import { IncomingHttpHeaders } from 'http';
5
+
6
+ /** @public */
7
+ declare const authModuleOauth2ProxyProvider: () => _backstage_backend_plugin_api.BackendFeature;
8
+
9
+ /**
10
+ * JWT header extraction result, containing the raw value and the parsed JWT
11
+ * payload.
12
+ *
13
+ * @public
14
+ */
15
+ type OAuth2ProxyResult<JWTPayload = {}> = {
16
+ /**
17
+ * The parsed payload of the `accessToken`. The token is only parsed, not verified.
18
+ *
19
+ * @deprecated Access through the `headers` instead. This will be removed in a future release.
20
+ */
21
+ fullProfile: JWTPayload;
22
+ /**
23
+ * The token received via the X-OAUTH2-PROXY-ID-TOKEN header. Will be an empty string
24
+ * if the header is not set. Note the this is typically an OpenID Connect token.
25
+ *
26
+ * @deprecated Access through the `headers` instead. This will be removed in a future release.
27
+ */
28
+ accessToken: string;
29
+ /**
30
+ * The headers of the incoming request from the OAuth2 proxy. This will include
31
+ * both the headers set by the client as well as the ones added by the OAuth2 proxy.
32
+ * You should only trust the headers that are injected by the OAuth2 proxy.
33
+ *
34
+ * Useful headers to use to complete the sign-in are for example `x-forwarded-user`
35
+ * and `x-forwarded-email`. See the OAuth2 proxy documentation for more information
36
+ * about the available headers and how to enable them. In particular it is possible
37
+ * to forward access and identity tokens, which can be user for additional verification
38
+ * and lookups.
39
+ */
40
+ headers: IncomingHttpHeaders;
41
+ /**
42
+ * Provides convenient access to the request headers.
43
+ *
44
+ * This call is simply forwarded to `req.get(name)`.
45
+ */
46
+ getHeader(name: string): string | undefined;
47
+ };
48
+
49
+ /**
50
+ * NOTE: This may come in handy if you're doing work on this provider:
51
+ * plugins/auth-backend/examples/docker-compose.oauth2-proxy.yaml
52
+ *
53
+ * @public
54
+ */
55
+ declare const OAUTH2_PROXY_JWT_HEADER = "X-OAUTH2-PROXY-ID-TOKEN";
56
+ /** @public */
57
+ declare const oauth2ProxyAuthenticator: _backstage_plugin_auth_node.ProxyAuthenticator<unknown, OAuth2ProxyResult>;
58
+
59
+ export { OAUTH2_PROXY_JWT_HEADER, OAuth2ProxyResult, authModuleOauth2ProxyProvider, oauth2ProxyAuthenticator };
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@backstage/plugin-auth-backend-module-oauth2-proxy-provider",
3
+ "description": "The oauth2-proxy-provider backend module for the auth plugin.",
4
+ "version": "0.0.0-nightly-20231129021646",
5
+ "main": "dist/index.cjs.js",
6
+ "types": "dist/index.d.ts",
7
+ "license": "Apache-2.0",
8
+ "publishConfig": {
9
+ "access": "public",
10
+ "main": "dist/index.cjs.js",
11
+ "types": "dist/index.d.ts"
12
+ },
13
+ "backstage": {
14
+ "role": "backend-plugin-module"
15
+ },
16
+ "scripts": {
17
+ "start": "backstage-cli package start",
18
+ "build": "backstage-cli package build",
19
+ "lint": "backstage-cli package lint",
20
+ "test": "backstage-cli package test",
21
+ "clean": "backstage-cli package clean",
22
+ "prepack": "backstage-cli package prepack",
23
+ "postpack": "backstage-cli package postpack"
24
+ },
25
+ "dependencies": {
26
+ "@backstage/backend-common": "^0.0.0-nightly-20231129021646",
27
+ "@backstage/backend-plugin-api": "^0.0.0-nightly-20231129021646",
28
+ "@backstage/errors": "^1.2.3",
29
+ "@backstage/plugin-auth-node": "^0.0.0-nightly-20231129021646",
30
+ "jose": "^4.6.0"
31
+ },
32
+ "devDependencies": {
33
+ "@backstage/backend-test-utils": "^0.0.0-nightly-20231129021646",
34
+ "@backstage/cli": "^0.0.0-nightly-20231129021646"
35
+ },
36
+ "files": [
37
+ "dist"
38
+ ]
39
+ }