@backstage/plugin-auth-backend 0.0.0-nightly-202111222339 → 0.0.0-nightly-2021111622350

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,7 +220,7 @@ 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
 
216
226
  declare function getEntityClaims(entity: UserEntity): TokenParams['claims'];
@@ -316,37 +326,83 @@ declare type AuthProviderFactory = (options: AuthProviderFactoryOptions) => Auth
316
326
  declare type AuthResponse<ProviderInfo> = {
317
327
  providerInfo: ProviderInfo;
318
328
  profile: ProfileInfo;
319
- backstageIdentity?: BackstageIdentity;
329
+ backstageIdentity?: BackstageIdentityResponse;
320
330
  };
321
- declare type BackstageIdentity = {
331
+ /**
332
+ * User identity information within Backstage.
333
+ *
334
+ * @public
335
+ */
336
+ declare type BackstageUserIdentity = {
322
337
  /**
323
- * An opaque ID that uniquely identifies the user within Backstage.
324
- *
325
- * 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'.
326
340
  */
327
- id: string;
341
+ type: 'user';
328
342
  /**
329
- * This is deprecated, use `token` instead.
330
- * @deprecated
343
+ * The entityRef of the user in the catalog.
344
+ * For example User:default/sandra
331
345
  */
332
- idToken?: string;
346
+ userEntityRef: string;
333
347
  /**
334
- * The token used to authenticate the user within Backstage.
348
+ * The user and group entities that the user claims ownership through
349
+ */
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
335
367
  */
336
- token?: string;
368
+ id: string;
337
369
  /**
338
370
  * The entity that the user is represented by within Backstage.
339
371
  *
340
372
  * This entity may or may not exist within the Catalog, and it can be used
341
373
  * to read and store additional metadata about the user.
374
+ *
375
+ * @deprecated Use the `identity` field instead.
342
376
  */
343
377
  entity?: Entity;
344
- };
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
+ }
345
399
  /**
346
400
  * Used to display login information to user, i.e. sidebar popup.
347
401
  *
348
402
  * It is also temporarily used as the profile of the signed-in user's Backstage
349
403
  * identity, but we want to replace that with data from identity and/org catalog service
404
+ *
405
+ * @public
350
406
  */
351
407
  declare type ProfileInfo = {
352
408
  /**
@@ -363,6 +419,10 @@ declare type ProfileInfo = {
363
419
  */
364
420
  picture?: string;
365
421
  };
422
+ /**
423
+ * type of sign in information context, includes the profile information and authentication result which contains auth. related information
424
+ * @public
425
+ */
366
426
  declare type SignInInfo<AuthResult> = {
367
427
  /**
368
428
  * The simple profile passed down for use in the frontend.
@@ -373,11 +433,20 @@ declare type SignInInfo<AuthResult> = {
373
433
  */
374
434
  result: AuthResult;
375
435
  };
436
+ /**
437
+ * Sign in resolver type describes the function which handles the result of a successful authentication
438
+ * and it must return a valid {@link BackstageSignInResult}
439
+ * @public
440
+ */
376
441
  declare type SignInResolver<AuthResult> = (info: SignInInfo<AuthResult>, context: {
377
442
  tokenIssuer: TokenIssuer;
378
443
  catalogIdentityClient: CatalogIdentityClient;
379
444
  logger: Logger;
380
- }) => Promise<BackstageIdentity>;
445
+ }) => Promise<BackstageSignInResult>;
446
+ /**
447
+ * The return type of authentication handler which must contain a valid profile information
448
+ * @public
449
+ */
381
450
  declare type AuthHandlerResult = {
382
451
  profile: ProfileInfo;
383
452
  };
@@ -388,6 +457,8 @@ declare type AuthHandlerResult = {
388
457
  *
389
458
  * Throwing an error in the function will cause the authentication to fail, making it
390
459
  * possible to use this function as a way to limit access to a certain group of users.
460
+ *
461
+ * @public
391
462
  */
392
463
  declare type AuthHandler<AuthResult> = (input: AuthResult) => Promise<AuthHandlerResult>;
393
464
  declare type StateEncoder = (req: OAuthStartRequest) => Promise<{
@@ -554,6 +625,34 @@ declare type OAuth2ProviderOptions = {
554
625
  };
555
626
  declare const createOAuth2Provider: (options?: OAuth2ProviderOptions | undefined) => AuthProviderFactory;
556
627
 
628
+ /**
629
+ * authentication result for the OIDC which includes the token set and user information (a profile response sent by OIDC server)
630
+ * @public
631
+ */
632
+ declare type OidcAuthResult = {
633
+ tokenset: TokenSet;
634
+ userinfo: UserinfoResponse;
635
+ };
636
+ /**
637
+ * OIDC provider callback options. An auth handler and a sign in resolver
638
+ * can be passed while creating a OIDC provider.
639
+ *
640
+ * authHandler : called after sign in was successful, a new object must be returned which includes a profile
641
+ * signInResolver: called after sign in was successful, expects to return a new {@link BackstageSignInResult}
642
+ *
643
+ * Both options are optional. There is fallback for authHandler where the default handler expect an e-mail explicitly
644
+ * otherwise it throws an error
645
+ *
646
+ * @public
647
+ */
648
+ declare type OidcProviderOptions = {
649
+ authHandler?: AuthHandler<OidcAuthResult>;
650
+ signIn?: {
651
+ resolver?: SignInResolver<OidcAuthResult>;
652
+ };
653
+ };
654
+ declare const createOidcProvider: (options?: OidcProviderOptions | undefined) => AuthProviderFactory;
655
+
557
656
  declare const oktaEmailSignInResolver: SignInResolver<OAuthResult>;
558
657
  declare type OktaProviderOptions = {
559
658
  /**
@@ -678,10 +777,41 @@ declare type AwsAlbProviderOptions = {
678
777
  };
679
778
  declare const createAwsAlbProvider: (options?: AwsAlbProviderOptions | undefined) => AuthProviderFactory;
680
779
 
780
+ /** @public */
781
+ declare type SamlAuthResult = {
782
+ fullProfile: any;
783
+ };
784
+ /** @public */
785
+ declare type SamlProviderOptions = {
786
+ /**
787
+ * The profile transformation function used to verify and convert the auth response
788
+ * into the profile that will be presented to the user.
789
+ */
790
+ authHandler?: AuthHandler<SamlAuthResult>;
791
+ /**
792
+ * Configure sign-in for this provider, without it the provider can not be used to sign users in.
793
+ */
794
+ signIn?: {
795
+ /**
796
+ * Maps an auth result to a Backstage identity for the user.
797
+ */
798
+ resolver?: SignInResolver<SamlAuthResult>;
799
+ };
800
+ };
801
+ /** @public */
802
+ declare const createSamlProvider: (options?: SamlProviderOptions | undefined) => AuthProviderFactory;
803
+
681
804
  declare const factories: {
682
805
  [providerId: string]: AuthProviderFactory;
683
806
  };
684
807
 
808
+ /**
809
+ * Parses token and decorates the BackstageIdentityResponse with identity information sourced from the token
810
+ *
811
+ * @public
812
+ */
813
+ declare function prepareBackstageIdentityResponse(result: BackstageSignInResult): BackstageIdentityResponse;
814
+
685
815
  declare type ProviderFactories = {
686
816
  [s: string]: AuthProviderFactory;
687
817
  };
@@ -692,7 +822,7 @@ interface RouterOptions {
692
822
  discovery: PluginEndpointDiscovery;
693
823
  providerFactories?: ProviderFactories;
694
824
  }
695
- declare function createRouter({ logger, config, discovery, database, providerFactories, }: RouterOptions): Promise<express.Router>;
825
+ declare function createRouter(options: RouterOptions): Promise<express.Router>;
696
826
  declare function createOriginFilter(config: Config): (origin: string) => boolean;
697
827
 
698
828
  /**
@@ -710,4 +840,4 @@ declare type WebMessageResponse = {
710
840
  declare const postMessageResponse: (res: express.Response, appOrigin: string, response: WebMessageResponse) => void;
711
841
  declare const ensuresXRequestedWith: (req: express.Request) => boolean;
712
842
 
713
- export { AtlassianAuthProvider, AtlassianProviderOptions, AuthProviderFactory, AuthProviderFactoryOptions, AuthProviderRouteHandlers, AuthResponse, AwsAlbProviderOptions, BackstageIdentity, BitbucketOAuthResult, BitbucketPassportProfile, BitbucketProviderOptions, CatalogIdentityClient, 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, getEntityClaims, googleEmailSignInResolver, microsoftEmailSignInResolver, oktaEmailSignInResolver, postMessageResponse, readState, verifyNonce };
843
+ export { AtlassianAuthProvider, AtlassianProviderOptions, AuthHandler, AuthHandlerResult, 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, OidcAuthResult, OidcProviderOptions, OktaProviderOptions, ProfileInfo, RouterOptions, SamlAuthResult, SamlProviderOptions, SignInInfo, SignInResolver, 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.0.0-nightly-202111222339",
4
+ "version": "0.0.0-nightly-2021111622350",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -30,12 +30,12 @@
30
30
  "clean": "backstage-cli clean"
31
31
  },
32
32
  "dependencies": {
33
- "@backstage/backend-common": "^0.0.0-nightly-202111222339",
34
- "@backstage/catalog-client": "^0.0.0-nightly-202111222339",
35
- "@backstage/catalog-model": "^0.0.0-nightly-202111222339",
33
+ "@backstage/backend-common": "^0.0.0-nightly-2021111622350",
34
+ "@backstage/catalog-client": "^0.5.2",
35
+ "@backstage/catalog-model": "^0.0.0-nightly-2021111622350",
36
36
  "@backstage/config": "^0.1.11",
37
- "@backstage/errors": "^0.0.0-nightly-202111222339",
38
- "@backstage/test-utils": "^0.0.0-nightly-202111222339",
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",
@@ -73,7 +73,7 @@
73
73
  "yn": "^4.0.0"
74
74
  },
75
75
  "devDependencies": {
76
- "@backstage/cli": "^0.0.0-nightly-202111222339",
76
+ "@backstage/cli": "^0.0.0-nightly-2021111622350",
77
77
  "@types/body-parser": "^1.19.0",
78
78
  "@types/cookie-parser": "^1.4.2",
79
79
  "@types/express-session": "^1.17.2",