@backstage/plugin-auth-backend-module-okta-provider 0.0.0-nightly-20231121021721

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,11 @@
1
+ # @backstage/plugin-auth-backend-module-okta-provider
2
+
3
+ ## 0.0.0-nightly-20231121021721
4
+
5
+ ### Patch Changes
6
+
7
+ - e1c189b52414: Adds okta-provider backend module for the auth plugin
8
+ - Updated dependencies
9
+ - @backstage/backend-common@0.0.0-nightly-20231121021721
10
+ - @backstage/plugin-auth-node@0.0.0-nightly-20231121021721
11
+ - @backstage/backend-plugin-api@0.0.0-nightly-20231121021721
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Auth Module: Okta Provider
2
+
3
+ This module provides an Okta auth provider implementation for `@backstage/plugin-auth-backend`.
4
+
5
+ ## Utilization
6
+
7
+ This module is used in `auth-backend/src/providers/okta`
8
+
9
+ ```ts
10
+ import { oktaAuthenticator } from '@backstage/plugin-auth-backend-module-okta-provider';
11
+
12
+ export const okta = createAuthProviderIntegration({
13
+ create({
14
+ authHandler?: AuthHandler<OAuthResult>,
15
+
16
+ signIn?: {
17
+ resolver: SignInResolver<OAuthResult>,
18
+ },
19
+ }) {
20
+ return createOAuthProviderFactory({
21
+ authenticator: oktaAuthenticator,
22
+ });
23
+ },
24
+ });
25
+ ```
26
+
27
+ ## Links
28
+
29
+ - [Repository](https://okta.com/backstage/backstage/tree/master/plugins/auth-backend-module-okta-provider)
30
+ - [Backstage Project Homepage](https://backstage.io)
package/config.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright 2020 The Backstage Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ export interface Config {
18
+ auth?: {
19
+ providers?: {
20
+ /** @visibility frontend */
21
+ okta?: {
22
+ [authEnv: string]: {
23
+ clientId: string;
24
+ /**
25
+ * @visibility secret
26
+ */
27
+ clientSecret: string;
28
+ audience?: string;
29
+ authServerId?: string;
30
+ idp?: string;
31
+ callbackUrl?: string;
32
+ };
33
+ };
34
+ };
35
+ };
36
+ }
@@ -0,0 +1,108 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var passportOktaOauth = require('@davidzemon/passport-okta-oauth');
6
+ var pluginAuthNode = require('@backstage/plugin-auth-node');
7
+ var backendPluginApi = require('@backstage/backend-plugin-api');
8
+
9
+ const oktaAuthenticator = pluginAuthNode.createOAuthAuthenticator({
10
+ defaultProfileTransform: pluginAuthNode.PassportOAuthAuthenticatorHelper.defaultProfileTransform,
11
+ initialize({ callbackUrl, config }) {
12
+ const clientId = config.getString("clientId");
13
+ const clientSecret = config.getString("clientSecret");
14
+ const audience = config.getOptionalString("audience") || "https://okta.com";
15
+ const authServerId = config.getOptionalString("authServerId");
16
+ const idp = config.getOptionalString("idp");
17
+ const defaultScopes = "openid profile email";
18
+ const additionalScopes = config.getOptionalString("additionalScopes") || "";
19
+ const combineScopeStrings = (scopesA, scopesB) => {
20
+ const scopesAArray = scopesA.split(" ");
21
+ const scopesBArray = scopesB.split(" ");
22
+ const combinedScopes = /* @__PURE__ */ new Set([...scopesAArray, ...scopesBArray]);
23
+ return Array.from(combinedScopes).join(" ");
24
+ };
25
+ const scope = combineScopeStrings(defaultScopes, additionalScopes);
26
+ return pluginAuthNode.PassportOAuthAuthenticatorHelper.from(
27
+ new passportOktaOauth.Strategy(
28
+ {
29
+ clientID: clientId,
30
+ clientSecret,
31
+ callbackURL: callbackUrl,
32
+ audience,
33
+ authServerID: authServerId,
34
+ idp,
35
+ passReqToCallback: false,
36
+ response_type: "code",
37
+ scope
38
+ },
39
+ (accessToken, refreshToken, params, fullProfile, done) => {
40
+ done(
41
+ void 0,
42
+ { fullProfile, params, accessToken },
43
+ { refreshToken }
44
+ );
45
+ }
46
+ )
47
+ );
48
+ },
49
+ async start(input, helper) {
50
+ return helper.start(input, {
51
+ accessType: "offline",
52
+ prompt: "consent"
53
+ });
54
+ },
55
+ async authenticate(input, helper) {
56
+ return helper.authenticate(input);
57
+ },
58
+ async refresh(input, helper) {
59
+ return helper.refresh(input);
60
+ }
61
+ });
62
+
63
+ exports.oktaSignInResolvers = void 0;
64
+ ((oktaSignInResolvers2) => {
65
+ oktaSignInResolvers2.emailMatchingUserEntityAnnotation = pluginAuthNode.createSignInResolverFactory({
66
+ create() {
67
+ return async (info, ctx) => {
68
+ const { profile } = info;
69
+ if (!profile.email) {
70
+ throw new Error("Okta profile contained no email");
71
+ }
72
+ return ctx.signInWithCatalogUser({
73
+ annotations: {
74
+ "okta.com/email": profile.email
75
+ }
76
+ });
77
+ };
78
+ }
79
+ });
80
+ })(exports.oktaSignInResolvers || (exports.oktaSignInResolvers = {}));
81
+
82
+ const authModuleOktaProvider = backendPluginApi.createBackendModule({
83
+ pluginId: "auth",
84
+ moduleId: "okta-provider",
85
+ register(reg) {
86
+ reg.registerInit({
87
+ deps: {
88
+ providers: pluginAuthNode.authProvidersExtensionPoint
89
+ },
90
+ async init({ providers }) {
91
+ providers.registerProvider({
92
+ providerId: "okta",
93
+ factory: pluginAuthNode.createOAuthProviderFactory({
94
+ authenticator: oktaAuthenticator,
95
+ signInResolverFactories: {
96
+ ...exports.oktaSignInResolvers,
97
+ ...pluginAuthNode.commonSignInResolvers
98
+ }
99
+ })
100
+ });
101
+ }
102
+ });
103
+ }
104
+ });
105
+
106
+ exports["default"] = authModuleOktaProvider;
107
+ exports.oktaAuthenticator = oktaAuthenticator;
108
+ //# 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 { Strategy as OktaStrategy } from '@davidzemon/passport-okta-oauth';\nimport {\n createOAuthAuthenticator,\n PassportOAuthAuthenticatorHelper,\n PassportOAuthDoneCallback,\n PassportProfile,\n} from '@backstage/plugin-auth-node';\n\n/** @public */\nexport const oktaAuthenticator = createOAuthAuthenticator({\n defaultProfileTransform:\n PassportOAuthAuthenticatorHelper.defaultProfileTransform,\n initialize({ callbackUrl, config }) {\n const clientId = config.getString('clientId');\n const clientSecret = config.getString('clientSecret');\n const audience = config.getOptionalString('audience') || 'https://okta.com';\n const authServerId = config.getOptionalString('authServerId');\n const idp = config.getOptionalString('idp');\n // default scopes are taken from\n // https://developer.okta.com/docs/reference/api/oidc/#response-example-success-refresh-token\n const defaultScopes = 'openid profile email';\n // additional scopes can be configured in the config as a space separated string\n const additionalScopes = config.getOptionalString('additionalScopes') || '';\n // combine default and additional scopes and remove duplicates\n const combineScopeStrings = (scopesA: string, scopesB: string) => {\n const scopesAArray = scopesA.split(' ');\n const scopesBArray = scopesB.split(' ');\n const combinedScopes = new Set([...scopesAArray, ...scopesBArray]);\n return Array.from(combinedScopes).join(' ');\n };\n const scope = combineScopeStrings(defaultScopes, additionalScopes);\n\n return PassportOAuthAuthenticatorHelper.from(\n new OktaStrategy(\n {\n clientID: clientId,\n clientSecret: clientSecret,\n callbackURL: callbackUrl,\n audience: audience,\n authServerID: authServerId,\n idp: idp,\n passReqToCallback: false,\n response_type: 'code',\n scope,\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 return helper.authenticate(input);\n },\n\n async refresh(input, helper) {\n return helper.refresh(input);\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 OAuthAuthenticatorResult,\n PassportProfile,\n SignInInfo,\n} from '@backstage/plugin-auth-node';\n\n/**\n * Available sign-in resolvers for the Okta auth provider.\n *\n * @public\n */\nexport namespace oktaSignInResolvers {\n /**\n * Looks up the user by matching their Okta email to the entity email.\n */\n\n export const emailMatchingUserEntityAnnotation = createSignInResolverFactory({\n create() {\n return async (\n info: SignInInfo<OAuthAuthenticatorResult<PassportProfile>>,\n ctx,\n ) => {\n const { profile } = info;\n\n if (!profile.email) {\n throw new Error('Okta profile contained no email');\n }\n\n return ctx.signInWithCatalogUser({\n annotations: {\n 'okta.com/email': profile.email,\n },\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 */\nimport { createBackendModule } from '@backstage/backend-plugin-api';\nimport {\n authProvidersExtensionPoint,\n commonSignInResolvers,\n createOAuthProviderFactory,\n} from '@backstage/plugin-auth-node';\nimport { oktaAuthenticator } from './authenticator';\nimport { oktaSignInResolvers } from './resolvers';\n\n/** @public */\nexport const authModuleOktaProvider = createBackendModule({\n pluginId: 'auth',\n moduleId: 'okta-provider',\n register(reg) {\n reg.registerInit({\n deps: {\n providers: authProvidersExtensionPoint,\n },\n async init({ providers }) {\n providers.registerProvider({\n providerId: 'okta',\n factory: createOAuthProviderFactory({\n authenticator: oktaAuthenticator,\n signInResolverFactories: {\n ...oktaSignInResolvers,\n ...commonSignInResolvers,\n },\n }),\n });\n },\n });\n },\n});\n"],"names":["createOAuthAuthenticator","PassportOAuthAuthenticatorHelper","OktaStrategy","oktaSignInResolvers","createSignInResolverFactory","createBackendModule","authProvidersExtensionPoint","createOAuthProviderFactory","commonSignInResolvers"],"mappings":";;;;;;;;AAyBO,MAAM,oBAAoBA,uCAAyB,CAAA;AAAA,EACxD,yBACEC,+CAAiC,CAAA,uBAAA;AAAA,EACnC,UAAW,CAAA,EAAE,WAAa,EAAA,MAAA,EAAU,EAAA;AAClC,IAAM,MAAA,QAAA,GAAW,MAAO,CAAA,SAAA,CAAU,UAAU,CAAA,CAAA;AAC5C,IAAM,MAAA,YAAA,GAAe,MAAO,CAAA,SAAA,CAAU,cAAc,CAAA,CAAA;AACpD,IAAA,MAAM,QAAW,GAAA,MAAA,CAAO,iBAAkB,CAAA,UAAU,CAAK,IAAA,kBAAA,CAAA;AACzD,IAAM,MAAA,YAAA,GAAe,MAAO,CAAA,iBAAA,CAAkB,cAAc,CAAA,CAAA;AAC5D,IAAM,MAAA,GAAA,GAAM,MAAO,CAAA,iBAAA,CAAkB,KAAK,CAAA,CAAA;A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AAA,CAAK,EAAE,SAAA,EAAa,EAAA;AACxB,QAAA,SAAA,CAAU,gBAAiB,CAAA;AAAA,UACzB,UAAY,EAAA,MAAA;AAAA,UACZ,SAASC,yCAA2B,CAAA;AAAA,YAClC,aAAe,EAAA,iBAAA;AAAA,YACf,uBAAyB,EAAA;AAAA,cACvB,GAAGJ,2BAAA;AAAA,cACH,GAAGK,oCAAA;AAAA,aACL;AAAA,WACD,CAAA;AAAA,SACF,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;"}
@@ -0,0 +1,23 @@
1
+ import * as _backstage_plugin_auth_node from '@backstage/plugin-auth-node';
2
+ import { PassportOAuthAuthenticatorHelper, PassportProfile, OAuthAuthenticatorResult } from '@backstage/plugin-auth-node';
3
+ import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
4
+
5
+ /** @public */
6
+ declare const oktaAuthenticator: _backstage_plugin_auth_node.OAuthAuthenticator<PassportOAuthAuthenticatorHelper, PassportProfile>;
7
+
8
+ /** @public */
9
+ declare const authModuleOktaProvider: () => _backstage_backend_plugin_api.BackendFeature;
10
+
11
+ /**
12
+ * Available sign-in resolvers for the Okta auth provider.
13
+ *
14
+ * @public
15
+ */
16
+ declare namespace oktaSignInResolvers {
17
+ /**
18
+ * Looks up the user by matching their Okta email to the entity email.
19
+ */
20
+ const emailMatchingUserEntityAnnotation: _backstage_plugin_auth_node.SignInResolverFactory<OAuthAuthenticatorResult<PassportProfile>, unknown>;
21
+ }
22
+
23
+ export { authModuleOktaProvider as default, oktaAuthenticator, oktaSignInResolvers };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@backstage/plugin-auth-backend-module-okta-provider",
3
+ "description": "The okta-provider backend module for the auth plugin.",
4
+ "version": "0.0.0-nightly-20231121021721",
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-20231121021721",
27
+ "@backstage/backend-plugin-api": "^0.0.0-nightly-20231121021721",
28
+ "@backstage/plugin-auth-node": "^0.0.0-nightly-20231121021721",
29
+ "@davidzemon/passport-okta-oauth": "^0.0.5",
30
+ "express": "^4.18.2",
31
+ "passport": "^0.6.0"
32
+ },
33
+ "devDependencies": {
34
+ "@backstage/backend-defaults": "^0.0.0-nightly-20231121021721",
35
+ "@backstage/backend-test-utils": "^0.0.0-nightly-20231121021721",
36
+ "@backstage/cli": "^0.0.0-nightly-20231121021721",
37
+ "@backstage/plugin-auth-backend": "^0.0.0-nightly-20231121021721",
38
+ "supertest": "^6.3.3"
39
+ },
40
+ "configSchema": "config.d.ts",
41
+ "files": [
42
+ "dist",
43
+ "config.d.ts"
44
+ ]
45
+ }