@backstage/plugin-auth-backend 0.6.0 → 0.7.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
@@ -8,6 +8,7 @@ import { UserEntity, Entity } from '@backstage/catalog-model';
8
8
  import { Profile } from 'passport';
9
9
  import { JSONWebKey } from 'jose';
10
10
  import { TokenSet, UserinfoResponse } from 'openid-client';
11
+ import { JsonValue } from '@backstage/types';
11
12
 
12
13
  /** Represents any form of serializable JWK */
13
14
  interface AnyJWK extends Record<string, string> {
@@ -115,17 +116,16 @@ declare type OAuthRefreshRequest = express.Request<{}> & {
115
116
  * Any OAuth provider needs to implement this interface which has provider specific
116
117
  * handlers for different methods to perform authentication, get access tokens,
117
118
  * refresh tokens and perform sign out.
119
+ *
120
+ * @public
118
121
  */
119
122
  interface OAuthHandlers {
120
123
  /**
121
- * This method initiates a sign in request with an auth provider.
122
- * @param {express.Request} req
123
- * @param options
124
+ * Initiate a sign in request with an auth provider.
124
125
  */
125
126
  start(req: OAuthStartRequest): Promise<RedirectInfo>;
126
127
  /**
127
- * Handles the redirect from the auth provider when the user has signed in.
128
- * @param {express.Request} req
128
+ * Handle the redirect from the auth provider when the user has signed in.
129
129
  */
130
130
  handler(req: express.Request): Promise<{
131
131
  response: OAuthResponse;
@@ -133,8 +133,6 @@ interface OAuthHandlers {
133
133
  }>;
134
134
  /**
135
135
  * (Optional) Given a refresh token and scope fetches a new access token from the auth provider.
136
- * @param {string} refreshToken
137
- * @param {string} scope
138
136
  */
139
137
  refresh?(req: OAuthRefreshRequest): Promise<{
140
138
  response: OAuthResponse;
@@ -224,6 +222,16 @@ declare class CatalogIdentityClient {
224
222
 
225
223
  declare function getEntityClaims(entity: UserEntity): TokenParams['claims'];
226
224
 
225
+ /**
226
+ * The context that is used for auth processing.
227
+ *
228
+ * @public
229
+ */
230
+ declare type AuthResolverContext = {
231
+ tokenIssuer: TokenIssuer;
232
+ catalogIdentityClient: CatalogIdentityClient;
233
+ logger: Logger;
234
+ };
227
235
  declare type AuthProviderConfig = {
228
236
  /**
229
237
  * The protocol://domain[:port] where the app is hosted. This is used to construct the
@@ -255,10 +263,10 @@ declare type RedirectInfo = {
255
263
  *
256
264
  * The routes in the auth backend API are tied to these methods like below
257
265
  *
258
- * /auth/[provider]/start -> start
259
- * /auth/[provider]/handler/frame -> frameHandler
260
- * /auth/[provider]/refresh -> refresh
261
- * /auth/[provider]/logout -> logout
266
+ * `/auth/[provider]/start -> start`
267
+ * `/auth/[provider]/handler/frame -> frameHandler`
268
+ * `/auth/[provider]/refresh -> refresh`
269
+ * `/auth/[provider]/logout -> logout`
262
270
  */
263
271
  interface AuthProviderRouteHandlers {
264
272
  /**
@@ -269,9 +277,6 @@ interface AuthProviderRouteHandlers {
269
277
  * Response
270
278
  * - redirect to the auth provider for the user to sign in or consent.
271
279
  * - sets a nonce cookie and also pass the nonce as 'state' query parameter in the redirect request
272
- *
273
- * @param {express.Request} req
274
- * @param {express.Response} res
275
280
  */
276
281
  start(req: express.Request, res: express.Response): Promise<void>;
277
282
  /**
@@ -283,9 +288,6 @@ interface AuthProviderRouteHandlers {
283
288
  * Response
284
289
  * - postMessage to the window with a payload that contains accessToken, expiryInSeconds?, idToken? and scope.
285
290
  * - sets a refresh token cookie if the auth provider supports refresh tokens
286
- *
287
- * @param {express.Request} req
288
- * @param {express.Response} res
289
291
  */
290
292
  frameHandler(req: express.Request, res: express.Response): Promise<void>;
291
293
  /**
@@ -296,9 +298,6 @@ interface AuthProviderRouteHandlers {
296
298
  * - to contain a refresh token cookie and scope (Optional) query parameter.
297
299
  * Response
298
300
  * - payload with accessToken, expiryInSeconds?, idToken?, scope and user profile information.
299
- *
300
- * @param {express.Request} req
301
- * @param {express.Response} res
302
301
  */
303
302
  refresh?(req: express.Request, res: express.Response): Promise<void>;
304
303
  /**
@@ -306,9 +305,6 @@ interface AuthProviderRouteHandlers {
306
305
  *
307
306
  * Response
308
307
  * - removes the refresh token cookie
309
- *
310
- * @param {express.Request} req
311
- * @param {express.Response} res
312
308
  */
313
309
  logout?(req: express.Request, res: express.Response): Promise<void>;
314
310
  }
@@ -381,12 +377,15 @@ interface BackstageSignInResult {
381
377
  }
382
378
  /**
383
379
  * The old exported symbol for {@link BackstageSignInResult}.
380
+ *
384
381
  * @public
385
- * @deprecated Use the `BackstageSignInResult` type instead.
382
+ * @deprecated Use the {@link BackstageSignInResult} instead.
386
383
  */
387
384
  declare type BackstageIdentity = BackstageSignInResult;
388
385
  /**
389
- * Response object containing the {@link BackstageUserIdentity} and the token from the authentication provider.
386
+ * Response object containing the {@link BackstageUserIdentity} and the token
387
+ * from the authentication provider.
388
+ *
390
389
  * @public
391
390
  */
392
391
  interface BackstageIdentityResponse extends BackstageSignInResult {
@@ -399,7 +398,8 @@ interface BackstageIdentityResponse extends BackstageSignInResult {
399
398
  * Used to display login information to user, i.e. sidebar popup.
400
399
  *
401
400
  * It is also temporarily used as the profile of the signed-in user's Backstage
402
- * identity, but we want to replace that with data from identity and/org catalog service
401
+ * identity, but we want to replace that with data from identity and/org catalog
402
+ * service
403
403
  *
404
404
  * @public
405
405
  */
@@ -419,47 +419,52 @@ declare type ProfileInfo = {
419
419
  picture?: string;
420
420
  };
421
421
  /**
422
- * type of sign in information context, includes the profile information and authentication result which contains auth. related information
422
+ * Type of sign in information context. Includes the profile information and
423
+ * authentication result which contains auth related information.
424
+ *
423
425
  * @public
424
426
  */
425
- declare type SignInInfo<AuthResult> = {
427
+ declare type SignInInfo<TAuthResult> = {
426
428
  /**
427
429
  * The simple profile passed down for use in the frontend.
428
430
  */
429
431
  profile: ProfileInfo;
430
432
  /**
431
- * The authentication result that was received from the authentication provider.
433
+ * The authentication result that was received from the authentication
434
+ * provider.
432
435
  */
433
- result: AuthResult;
436
+ result: TAuthResult;
434
437
  };
435
438
  /**
436
- * Sign in resolver type describes the function which handles the result of a successful authentication
437
- * and it must return a valid {@link BackstageSignInResult}
439
+ * Describes the function which handles the result of a successful
440
+ * authentication. Must return a valid {@link BackstageSignInResult}.
441
+ *
438
442
  * @public
439
443
  */
440
- declare type SignInResolver<AuthResult> = (info: SignInInfo<AuthResult>, context: {
441
- tokenIssuer: TokenIssuer;
442
- catalogIdentityClient: CatalogIdentityClient;
443
- logger: Logger;
444
- }) => Promise<BackstageSignInResult>;
444
+ declare type SignInResolver<TAuthResult> = (info: SignInInfo<TAuthResult>, context: AuthResolverContext) => Promise<BackstageSignInResult>;
445
445
  /**
446
- * The return type of authentication handler which must contain a valid profile information
446
+ * The return type of an authentication handler. Must contain valid profile
447
+ * information.
448
+ *
447
449
  * @public
448
450
  */
449
451
  declare type AuthHandlerResult = {
450
452
  profile: ProfileInfo;
451
453
  };
452
454
  /**
453
- * The AuthHandler function is called every time the user authenticates using the provider.
455
+ * The AuthHandler function is called every time the user authenticates using
456
+ * the provider.
454
457
  *
455
- * The handler should return a profile that represents the session for the user in the frontend.
458
+ * The handler should return a profile that represents the session for the user
459
+ * in the frontend.
456
460
  *
457
- * Throwing an error in the function will cause the authentication to fail, making it
458
- * possible to use this function as a way to limit access to a certain group of users.
461
+ * Throwing an error in the function will cause the authentication to fail,
462
+ * making it possible to use this function as a way to limit access to a certain
463
+ * group of users.
459
464
  *
460
465
  * @public
461
466
  */
462
- declare type AuthHandler<AuthResult> = (input: AuthResult) => Promise<AuthHandlerResult>;
467
+ declare type AuthHandler<TAuthResult> = (input: TAuthResult, context: AuthResolverContext) => Promise<AuthHandlerResult>;
463
468
  declare type StateEncoder = (req: OAuthStartRequest) => Promise<{
464
469
  encodedState: string;
465
470
  }>;
@@ -674,7 +679,7 @@ declare type GithubProviderOptions = {
674
679
  * Providing your own stateEncoder will allow you to add addition parameters to the state field.
675
680
  *
676
681
  * It is typed as follows:
677
- * export type StateEncoder = (input: OAuthState) => Promise<{encodedState: string}>;
682
+ * `export type StateEncoder = (input: OAuthState) => Promise<{encodedState: string}>;`
678
683
  *
679
684
  * Note: the stateEncoder must encode a 'nonce' value and an 'env' value. Without this, the OAuth flow will fail
680
685
  * (These two values will be set by the req.state by default)
@@ -752,6 +757,49 @@ declare type OAuth2ProviderOptions = {
752
757
  };
753
758
  declare const createOAuth2Provider: (options?: OAuth2ProviderOptions | undefined) => AuthProviderFactory;
754
759
 
760
+ /**
761
+ * JWT header extraction result, containing the raw value and the parsed JWT
762
+ * payload.
763
+ *
764
+ * @public
765
+ */
766
+ declare type OAuth2ProxyResult<JWTPayload> = {
767
+ /**
768
+ * Parsed and decoded JWT payload.
769
+ */
770
+ fullProfile: JWTPayload;
771
+ /**
772
+ * Raw JWT token
773
+ */
774
+ accessToken: string;
775
+ };
776
+ /**
777
+ * Options for the oauth2-proxy provider factory
778
+ *
779
+ * @public
780
+ */
781
+ declare type Oauth2ProxyProviderOptions<JWTPayload> = {
782
+ /**
783
+ * Configure an auth handler to generate a profile for the user.
784
+ */
785
+ authHandler: AuthHandler<OAuth2ProxyResult<JWTPayload>>;
786
+ /**
787
+ * Configure sign-in for this provider, without it the provider can not be used to sign users in.
788
+ */
789
+ signIn: {
790
+ /**
791
+ * Maps an auth result to a Backstage identity for the user.
792
+ */
793
+ resolver: SignInResolver<OAuth2ProxyResult<JWTPayload>>;
794
+ };
795
+ };
796
+ /**
797
+ * Factory function for oauth2-proxy auth provider
798
+ *
799
+ * @public
800
+ */
801
+ declare const createOauth2ProxyProvider: <JWTPayload>(options: Oauth2ProxyProviderOptions<JWTPayload>) => AuthProviderFactory;
802
+
755
803
  /**
756
804
  * authentication result for the OIDC which includes the token set and user information (a profile response sent by OIDC server)
757
805
  * @public
@@ -843,12 +891,76 @@ declare type SamlProviderOptions = {
843
891
  /** @public */
844
892
  declare const createSamlProvider: (options?: SamlProviderOptions | undefined) => AuthProviderFactory;
845
893
 
894
+ /**
895
+ * The data extracted from an IAP token.
896
+ *
897
+ * @public
898
+ */
899
+ declare type GcpIapTokenInfo = {
900
+ /**
901
+ * The unique, stable identifier for the user.
902
+ */
903
+ sub: string;
904
+ /**
905
+ * User email address.
906
+ */
907
+ email: string;
908
+ /**
909
+ * Other fields.
910
+ */
911
+ [key: string]: JsonValue;
912
+ };
913
+ /**
914
+ * The result of the initial auth challenge. This is the input to the auth
915
+ * callbacks.
916
+ *
917
+ * @public
918
+ */
919
+ declare type GcpIapResult = {
920
+ /**
921
+ * The data extracted from the IAP token header.
922
+ */
923
+ iapToken: GcpIapTokenInfo;
924
+ };
925
+ /**
926
+ * Options for {@link createGcpIapProvider}.
927
+ *
928
+ * @public
929
+ */
930
+ declare type GcpIapProviderOptions = {
931
+ /**
932
+ * The profile transformation function used to verify and convert the auth
933
+ * response into the profile that will be presented to the user. The default
934
+ * implementation just provides the authenticated email that the IAP
935
+ * presented.
936
+ */
937
+ authHandler?: AuthHandler<GcpIapResult>;
938
+ /**
939
+ * Configures sign-in for this provider.
940
+ */
941
+ signIn: {
942
+ /**
943
+ * Maps an auth result to a Backstage identity for the user.
944
+ */
945
+ resolver: SignInResolver<GcpIapResult>;
946
+ };
947
+ };
948
+
949
+ /**
950
+ * Creates an auth provider for Google Identity-Aware Proxy.
951
+ *
952
+ * @public
953
+ */
954
+ declare function createGcpIapProvider(options: GcpIapProviderOptions): AuthProviderFactory;
955
+
846
956
  declare const factories: {
847
957
  [providerId: string]: AuthProviderFactory;
848
958
  };
849
959
 
850
960
  /**
851
- * Parses token and decorates the BackstageIdentityResponse with identity information sourced from the token
961
+ * Parses a Backstage-issued token and decorates the
962
+ * {@link BackstageIdentityResponse} with identity information sourced from the
963
+ * token.
852
964
  *
853
965
  * @public
854
966
  */
@@ -882,4 +994,4 @@ declare type WebMessageResponse = {
882
994
  declare const postMessageResponse: (res: express.Response, appOrigin: string, response: WebMessageResponse) => void;
883
995
  declare const ensuresXRequestedWith: (req: express.Request) => boolean;
884
996
 
885
- export { AtlassianAuthProvider, AtlassianProviderOptions, Auth0ProviderOptions, 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, OneLoginProviderOptions, ProfileInfo, RouterOptions, SamlAuthResult, SamlProviderOptions, SignInInfo, SignInResolver, TokenIssuer, WebMessageResponse, bitbucketUserIdSignInResolver, bitbucketUsernameSignInResolver, createAtlassianProvider, createAuth0Provider, createAwsAlbProvider, createBitbucketProvider, createGithubProvider, createGitlabProvider, createGoogleProvider, createMicrosoftProvider, createOAuth2Provider, createOidcProvider, createOktaProvider, createOneLoginProvider, createOriginFilter, createRouter, createSamlProvider, factories as defaultAuthProviderFactories, encodeState, ensuresXRequestedWith, getEntityClaims, googleEmailSignInResolver, microsoftEmailSignInResolver, oktaEmailSignInResolver, postMessageResponse, prepareBackstageIdentityResponse, readState, verifyNonce };
997
+ export { AtlassianAuthProvider, AtlassianProviderOptions, Auth0ProviderOptions, AuthHandler, AuthHandlerResult, AuthProviderFactory, AuthProviderFactoryOptions, AuthProviderRouteHandlers, AuthResolverContext, AuthResponse, AwsAlbProviderOptions, BackstageIdentity, BackstageIdentityResponse, BackstageSignInResult, BackstageUserIdentity, BitbucketOAuthResult, BitbucketPassportProfile, BitbucketProviderOptions, CatalogIdentityClient, GcpIapProviderOptions, GcpIapResult, GcpIapTokenInfo, GithubOAuthResult, GithubProviderOptions, GitlabProviderOptions, GoogleProviderOptions, IdentityClient, MicrosoftProviderOptions, OAuth2ProviderOptions, OAuth2ProxyResult, OAuthAdapter, OAuthEnvironmentHandler, OAuthHandlers, OAuthProviderInfo, OAuthProviderOptions, OAuthRefreshRequest, OAuthResponse, OAuthResult, OAuthStartRequest, OAuthState, Oauth2ProxyProviderOptions, OidcAuthResult, OidcProviderOptions, OktaProviderOptions, OneLoginProviderOptions, ProfileInfo, RouterOptions, SamlAuthResult, SamlProviderOptions, SignInInfo, SignInResolver, TokenIssuer, WebMessageResponse, bitbucketUserIdSignInResolver, bitbucketUsernameSignInResolver, createAtlassianProvider, createAuth0Provider, createAwsAlbProvider, createBitbucketProvider, createGcpIapProvider, createGithubProvider, createGitlabProvider, createGoogleProvider, createMicrosoftProvider, createOAuth2Provider, createOauth2ProxyProvider, createOidcProvider, createOktaProvider, createOneLoginProvider, 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.6.0",
4
+ "version": "0.7.0",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -30,13 +30,13 @@
30
30
  "clean": "backstage-cli clean"
31
31
  },
32
32
  "dependencies": {
33
- "@backstage/backend-common": "^0.10.1",
34
- "@backstage/catalog-client": "^0.5.3",
35
- "@backstage/catalog-model": "^0.9.8",
36
- "@backstage/config": "^0.1.11",
37
- "@backstage/errors": "^0.1.5",
38
- "@backstage/test-utils": "^0.2.1",
39
- "@google-cloud/firestore": "^4.15.1",
33
+ "@backstage/backend-common": "^0.10.4",
34
+ "@backstage/catalog-client": "^0.5.5",
35
+ "@backstage/catalog-model": "^0.9.10",
36
+ "@backstage/config": "^0.1.13",
37
+ "@backstage/errors": "^0.2.0",
38
+ "@backstage/types": "^0.1.1",
39
+ "@google-cloud/firestore": "^5.0.2",
40
40
  "@types/express": "^4.17.6",
41
41
  "@types/passport": "^1.0.3",
42
42
  "compression": "^1.7.4",
@@ -46,6 +46,7 @@
46
46
  "express-promise-router": "^4.1.0",
47
47
  "express-session": "^1.17.1",
48
48
  "fs-extra": "9.1.0",
49
+ "google-auth-library": "^7.6.1",
49
50
  "helmet": "^4.0.0",
50
51
  "jose": "^1.27.1",
51
52
  "jwt-decode": "^3.1.0",
@@ -72,7 +73,8 @@
72
73
  "yn": "^4.0.0"
73
74
  },
74
75
  "devDependencies": {
75
- "@backstage/cli": "^0.10.4",
76
+ "@backstage/cli": "^0.12.0",
77
+ "@backstage/test-utils": "^0.2.3",
76
78
  "@types/body-parser": "^1.19.0",
77
79
  "@types/cookie-parser": "^1.4.2",
78
80
  "@types/express-session": "^1.17.2",
@@ -83,7 +85,8 @@
83
85
  "@types/passport-saml": "^1.1.3",
84
86
  "@types/passport-strategy": "^0.2.35",
85
87
  "@types/xml2js": "^0.4.7",
86
- "msw": "^0.35.0"
88
+ "msw": "^0.35.0",
89
+ "supertest": "^6.1.3"
87
90
  },
88
91
  "files": [
89
92
  "dist",
@@ -91,5 +94,5 @@
91
94
  "config.d.ts"
92
95
  ],
93
96
  "configSchema": "config.d.ts",
94
- "gitHead": "4b2a8ed96ff427735c872a72c1864321ef698436"
97
+ "gitHead": "600d6e3c854bbfb12a0078ca6f726d1c0d1fea0b"
95
98
  }