@backstage/plugin-auth-backend 0.4.7 → 0.5.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/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ import { UserEntity, Entity } from '@backstage/catalog-model';
7
7
  import { Config } from '@backstage/config';
8
8
  import { Profile } from 'passport';
9
9
  import { JSONWebKey } from 'jose';
10
+ import { TokenSet, UserinfoResponse } from 'openid-client';
10
11
 
11
12
  /** Represents any form of serializable JWK */
12
13
  interface AnyJWK extends Record<string, string> {
@@ -69,7 +70,16 @@ declare type OAuthResult = {
69
70
  accessToken: string;
70
71
  refreshToken?: string;
71
72
  };
72
- declare type OAuthResponse = AuthResponse<OAuthProviderInfo>;
73
+ /**
74
+ * The expected response from an OAuth flow.
75
+ *
76
+ * @public
77
+ */
78
+ declare type OAuthResponse = {
79
+ profile: ProfileInfo;
80
+ providerInfo: OAuthProviderInfo;
81
+ backstageIdentity?: BackstageSignInResult;
82
+ };
73
83
  declare type OAuthProviderInfo = {
74
84
  /**
75
85
  * An access token issued for the signed in user.
@@ -122,7 +132,7 @@ interface OAuthHandlers {
122
132
  * @param {express.Request} req
123
133
  */
124
134
  handler(req: express.Request): Promise<{
125
- response: AuthResponse<OAuthProviderInfo>;
135
+ response: OAuthResponse;
126
136
  refreshToken?: string;
127
137
  }>;
128
138
  /**
@@ -130,7 +140,7 @@ interface OAuthHandlers {
130
140
  * @param {string} refreshToken
131
141
  * @param {string} scope
132
142
  */
133
- refresh?(req: OAuthRefreshRequest): Promise<AuthResponse<OAuthProviderInfo>>;
143
+ refresh?(req: OAuthRefreshRequest): Promise<OAuthResponse>;
134
144
  /**
135
145
  * (Optional) Sign out of the auth provider.
136
146
  */
@@ -157,7 +167,7 @@ declare class IdentityClient {
157
167
  * Returns a BackstageIdentity (user) matching the token.
158
168
  * The method throws an error if verification fails.
159
169
  */
160
- authenticate(token: string | undefined): Promise<BackstageIdentity>;
170
+ authenticate(token: string | undefined): Promise<BackstageIdentityResponse>;
161
171
  /**
162
172
  * Parses the given authorization header and returns
163
173
  * the bearer token, or null if no bearer token is given
@@ -210,9 +220,11 @@ declare class CatalogIdentityClient {
210
220
  *
211
221
  * Returns a superset of the entity names that can be passed directly to `issueToken` as `ent`.
212
222
  */
213
- resolveCatalogMembership({ entityRefs, logger, }: MemberClaimQuery): Promise<string[]>;
223
+ resolveCatalogMembership(query: MemberClaimQuery): Promise<string[]>;
214
224
  }
215
225
 
226
+ declare function getEntityClaims(entity: UserEntity): TokenParams['claims'];
227
+
216
228
  declare type AuthProviderConfig = {
217
229
  /**
218
230
  * The protocol://domain[:port] where the app is hosted. This is used to construct the
@@ -314,37 +326,83 @@ declare type AuthProviderFactory = (options: AuthProviderFactoryOptions) => Auth
314
326
  declare type AuthResponse<ProviderInfo> = {
315
327
  providerInfo: ProviderInfo;
316
328
  profile: ProfileInfo;
317
- backstageIdentity?: BackstageIdentity;
329
+ backstageIdentity?: BackstageIdentityResponse;
318
330
  };
319
- declare type BackstageIdentity = {
331
+ /**
332
+ * User identity information within Backstage.
333
+ *
334
+ * @public
335
+ */
336
+ declare type BackstageUserIdentity = {
320
337
  /**
321
- * An opaque ID that uniquely identifies the user within Backstage.
322
- *
323
- * This is typically the same as the user entity `metadata.name`.
338
+ * The type of identity that this structure represents. In the frontend app
339
+ * this will currently always be 'user'.
324
340
  */
325
- id: string;
341
+ type: 'user';
326
342
  /**
327
- * This is deprecated, use `token` instead.
328
- * @deprecated
343
+ * The entityRef of the user in the catalog.
344
+ * For example User:default/sandra
329
345
  */
330
- idToken?: string;
346
+ userEntityRef: string;
331
347
  /**
332
- * The token used to authenticate the user within Backstage.
348
+ * The user and group entities that the user claims ownership through
333
349
  */
334
- token?: string;
350
+ ownershipEntityRefs: string[];
351
+ };
352
+ /**
353
+ * A representation of a successful Backstage sign-in.
354
+ *
355
+ * Compared to the {@link BackstageIdentityResponse} this type omits
356
+ * the decoded identity information embedded in the token.
357
+ *
358
+ * @public
359
+ */
360
+ interface BackstageSignInResult {
361
+ /**
362
+ * An opaque ID that uniquely identifies the user within Backstage.
363
+ *
364
+ * This is typically the same as the user entity `metadata.name`.
365
+ *
366
+ * @deprecated Use the `identity` field instead
367
+ */
368
+ id: string;
335
369
  /**
336
370
  * The entity that the user is represented by within Backstage.
337
371
  *
338
372
  * This entity may or may not exist within the Catalog, and it can be used
339
373
  * to read and store additional metadata about the user.
374
+ *
375
+ * @deprecated Use the `identity` field instead.
340
376
  */
341
377
  entity?: Entity;
342
- };
378
+ /**
379
+ * The token used to authenticate the user within Backstage.
380
+ */
381
+ token: string;
382
+ }
383
+ /**
384
+ * The old exported symbol for {@link BackstageSignInResult}.
385
+ * @public
386
+ * @deprecated Use the `BackstageSignInResult` type instead.
387
+ */
388
+ declare type BackstageIdentity = BackstageSignInResult;
389
+ /**
390
+ * Response object containing the {@link BackstageUserIdentity} and the token from the authentication provider.
391
+ * @public
392
+ */
393
+ interface BackstageIdentityResponse extends BackstageSignInResult {
394
+ /**
395
+ * A plaintext description of the identity that is encapsulated within the token.
396
+ */
397
+ identity: BackstageUserIdentity;
398
+ }
343
399
  /**
344
400
  * Used to display login information to user, i.e. sidebar popup.
345
401
  *
346
402
  * It is also temporarily used as the profile of the signed-in user's Backstage
347
403
  * identity, but we want to replace that with data from identity and/org catalog service
404
+ *
405
+ * @public
348
406
  */
349
407
  declare type ProfileInfo = {
350
408
  /**
@@ -375,7 +433,7 @@ declare type SignInResolver<AuthResult> = (info: SignInInfo<AuthResult>, context
375
433
  tokenIssuer: TokenIssuer;
376
434
  catalogIdentityClient: CatalogIdentityClient;
377
435
  logger: Logger;
378
- }) => Promise<BackstageIdentity>;
436
+ }) => Promise<BackstageSignInResult>;
379
437
  declare type AuthHandlerResult = {
380
438
  profile: ProfileInfo;
381
439
  };
@@ -552,6 +610,18 @@ declare type OAuth2ProviderOptions = {
552
610
  };
553
611
  declare const createOAuth2Provider: (options?: OAuth2ProviderOptions | undefined) => AuthProviderFactory;
554
612
 
613
+ declare type AuthResult = {
614
+ tokenset: TokenSet;
615
+ userinfo: UserinfoResponse;
616
+ };
617
+ declare type OidcProviderOptions = {
618
+ authHandler?: AuthHandler<AuthResult>;
619
+ signIn?: {
620
+ resolver?: SignInResolver<AuthResult>;
621
+ };
622
+ };
623
+ declare const createOidcProvider: (options?: OidcProviderOptions | undefined) => AuthProviderFactory;
624
+
555
625
  declare const oktaEmailSignInResolver: SignInResolver<OAuthResult>;
556
626
  declare type OktaProviderOptions = {
557
627
  /**
@@ -676,10 +746,41 @@ declare type AwsAlbProviderOptions = {
676
746
  };
677
747
  declare const createAwsAlbProvider: (options?: AwsAlbProviderOptions | undefined) => AuthProviderFactory;
678
748
 
749
+ /** @public */
750
+ declare type SamlAuthResult = {
751
+ fullProfile: any;
752
+ };
753
+ /** @public */
754
+ declare type SamlProviderOptions = {
755
+ /**
756
+ * The profile transformation function used to verify and convert the auth response
757
+ * into the profile that will be presented to the user.
758
+ */
759
+ authHandler?: AuthHandler<SamlAuthResult>;
760
+ /**
761
+ * Configure sign-in for this provider, without it the provider can not be used to sign users in.
762
+ */
763
+ signIn?: {
764
+ /**
765
+ * Maps an auth result to a Backstage identity for the user.
766
+ */
767
+ resolver?: SignInResolver<SamlAuthResult>;
768
+ };
769
+ };
770
+ /** @public */
771
+ declare const createSamlProvider: (options?: SamlProviderOptions | undefined) => AuthProviderFactory;
772
+
679
773
  declare const factories: {
680
774
  [providerId: string]: AuthProviderFactory;
681
775
  };
682
776
 
777
+ /**
778
+ * Parses token and decorates the BackstageIdentityResponse with identity information sourced from the token
779
+ *
780
+ * @public
781
+ */
782
+ declare function prepareBackstageIdentityResponse(result: BackstageSignInResult): BackstageIdentityResponse;
783
+
683
784
  declare type ProviderFactories = {
684
785
  [s: string]: AuthProviderFactory;
685
786
  };
@@ -690,7 +791,7 @@ interface RouterOptions {
690
791
  discovery: PluginEndpointDiscovery;
691
792
  providerFactories?: ProviderFactories;
692
793
  }
693
- declare function createRouter({ logger, config, discovery, database, providerFactories, }: RouterOptions): Promise<express.Router>;
794
+ declare function createRouter(options: RouterOptions): Promise<express.Router>;
694
795
  declare function createOriginFilter(config: Config): (origin: string) => boolean;
695
796
 
696
797
  /**
@@ -708,4 +809,4 @@ declare type WebMessageResponse = {
708
809
  declare const postMessageResponse: (res: express.Response, appOrigin: string, response: WebMessageResponse) => void;
709
810
  declare const ensuresXRequestedWith: (req: express.Request) => boolean;
710
811
 
711
- export { AtlassianAuthProvider, AtlassianProviderOptions, AuthProviderFactory, AuthProviderFactoryOptions, AuthProviderRouteHandlers, AuthResponse, AwsAlbProviderOptions, BackstageIdentity, BitbucketOAuthResult, BitbucketPassportProfile, BitbucketProviderOptions, GithubOAuthResult, GithubProviderOptions, GitlabProviderOptions, GoogleProviderOptions, IdentityClient, MicrosoftProviderOptions, OAuth2ProviderOptions, OAuthAdapter, OAuthEnvironmentHandler, OAuthHandlers, OAuthProviderInfo, OAuthProviderOptions, OAuthRefreshRequest, OAuthResponse, OAuthResult, OAuthStartRequest, OAuthState, OktaProviderOptions, ProfileInfo, RouterOptions, TokenIssuer, WebMessageResponse, bitbucketUserIdSignInResolver, bitbucketUsernameSignInResolver, createAtlassianProvider, createAwsAlbProvider, createBitbucketProvider, createGithubProvider, createGitlabProvider, createGoogleProvider, createMicrosoftProvider, createOAuth2Provider, createOktaProvider, createOriginFilter, createRouter, factories as defaultAuthProviderFactories, encodeState, ensuresXRequestedWith, googleEmailSignInResolver, microsoftEmailSignInResolver, oktaEmailSignInResolver, postMessageResponse, readState, verifyNonce };
812
+ export { AtlassianAuthProvider, AtlassianProviderOptions, AuthProviderFactory, AuthProviderFactoryOptions, AuthProviderRouteHandlers, AuthResponse, AwsAlbProviderOptions, BackstageIdentity, BackstageIdentityResponse, BackstageSignInResult, BackstageUserIdentity, BitbucketOAuthResult, BitbucketPassportProfile, BitbucketProviderOptions, CatalogIdentityClient, GithubOAuthResult, GithubProviderOptions, GitlabProviderOptions, GoogleProviderOptions, IdentityClient, MicrosoftProviderOptions, OAuth2ProviderOptions, OAuthAdapter, OAuthEnvironmentHandler, OAuthHandlers, OAuthProviderInfo, OAuthProviderOptions, OAuthRefreshRequest, OAuthResponse, OAuthResult, OAuthStartRequest, OAuthState, OktaProviderOptions, ProfileInfo, RouterOptions, SamlAuthResult, SamlProviderOptions, TokenIssuer, WebMessageResponse, bitbucketUserIdSignInResolver, bitbucketUsernameSignInResolver, createAtlassianProvider, createAwsAlbProvider, createBitbucketProvider, createGithubProvider, createGitlabProvider, createGoogleProvider, createMicrosoftProvider, createOAuth2Provider, createOidcProvider, createOktaProvider, createOriginFilter, createRouter, createSamlProvider, factories as defaultAuthProviderFactories, encodeState, ensuresXRequestedWith, getEntityClaims, googleEmailSignInResolver, microsoftEmailSignInResolver, oktaEmailSignInResolver, postMessageResponse, prepareBackstageIdentityResponse, readState, verifyNonce };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/plugin-auth-backend",
3
3
  "description": "A Backstage backend plugin that handles authentication",
4
- "version": "0.4.7",
4
+ "version": "0.5.0",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -30,19 +30,18 @@
30
30
  "clean": "backstage-cli clean"
31
31
  },
32
32
  "dependencies": {
33
- "@backstage/backend-common": "^0.9.9",
34
- "@backstage/catalog-client": "^0.5.1",
35
- "@backstage/catalog-model": "^0.9.6",
33
+ "@backstage/backend-common": "^0.9.13",
34
+ "@backstage/catalog-client": "^0.5.2",
35
+ "@backstage/catalog-model": "^0.9.7",
36
36
  "@backstage/config": "^0.1.11",
37
- "@backstage/errors": "^0.1.4",
38
- "@backstage/test-utils": "^0.1.21",
37
+ "@backstage/errors": "^0.1.5",
38
+ "@backstage/test-utils": "^0.1.24",
39
39
  "@google-cloud/firestore": "^4.15.1",
40
40
  "@types/express": "^4.17.6",
41
41
  "@types/passport": "^1.0.3",
42
42
  "compression": "^1.7.4",
43
43
  "cookie-parser": "^1.4.5",
44
44
  "cors": "^2.8.5",
45
- "cross-fetch": "^3.0.6",
46
45
  "express": "^4.17.1",
47
46
  "express-promise-router": "^4.1.0",
48
47
  "express-session": "^1.17.1",
@@ -57,6 +56,7 @@
57
56
  "minimatch": "^3.0.3",
58
57
  "morgan": "^1.10.0",
59
58
  "node-cache": "^5.1.2",
59
+ "node-fetch": "^2.6.1",
60
60
  "openid-client": "^4.2.1",
61
61
  "passport": "^0.4.1",
62
62
  "passport-bitbucket-oauth2": "^0.1.2",
@@ -73,7 +73,7 @@
73
73
  "yn": "^4.0.0"
74
74
  },
75
75
  "devDependencies": {
76
- "@backstage/cli": "^0.8.2",
76
+ "@backstage/cli": "^0.10.1",
77
77
  "@types/body-parser": "^1.19.0",
78
78
  "@types/cookie-parser": "^1.4.2",
79
79
  "@types/express-session": "^1.17.2",
@@ -92,5 +92,5 @@
92
92
  "config.d.ts"
93
93
  ],
94
94
  "configSchema": "config.d.ts",
95
- "gitHead": "5bdaccc40b4a814cf0b45d429f15a3afacc2f60b"
95
+ "gitHead": "562be0b43016294e27af3ad024191bb86b13b1c1"
96
96
  }