@backstage/plugin-auth-backend 0.6.1 → 0.8.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
@@ -116,17 +116,16 @@ declare type OAuthRefreshRequest = express.Request<{}> & {
116
116
  * Any OAuth provider needs to implement this interface which has provider specific
117
117
  * handlers for different methods to perform authentication, get access tokens,
118
118
  * refresh tokens and perform sign out.
119
+ *
120
+ * @public
119
121
  */
120
122
  interface OAuthHandlers {
121
123
  /**
122
- * This method initiates a sign in request with an auth provider.
123
- * @param {express.Request} req
124
- * @param options
124
+ * Initiate a sign in request with an auth provider.
125
125
  */
126
126
  start(req: OAuthStartRequest): Promise<RedirectInfo>;
127
127
  /**
128
- * Handles the redirect from the auth provider when the user has signed in.
129
- * @param {express.Request} req
128
+ * Handle the redirect from the auth provider when the user has signed in.
130
129
  */
131
130
  handler(req: express.Request): Promise<{
132
131
  response: OAuthResponse;
@@ -134,8 +133,6 @@ interface OAuthHandlers {
134
133
  }>;
135
134
  /**
136
135
  * (Optional) Given a refresh token and scope fetches a new access token from the auth provider.
137
- * @param {string} refreshToken
138
- * @param {string} scope
139
136
  */
140
137
  refresh?(req: OAuthRefreshRequest): Promise<{
141
138
  response: OAuthResponse;
@@ -225,6 +222,16 @@ declare class CatalogIdentityClient {
225
222
 
226
223
  declare function getEntityClaims(entity: UserEntity): TokenParams['claims'];
227
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
+ };
228
235
  declare type AuthProviderConfig = {
229
236
  /**
230
237
  * The protocol://domain[:port] where the app is hosted. This is used to construct the
@@ -256,10 +263,10 @@ declare type RedirectInfo = {
256
263
  *
257
264
  * The routes in the auth backend API are tied to these methods like below
258
265
  *
259
- * /auth/[provider]/start -> start
260
- * /auth/[provider]/handler/frame -> frameHandler
261
- * /auth/[provider]/refresh -> refresh
262
- * /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`
263
270
  */
264
271
  interface AuthProviderRouteHandlers {
265
272
  /**
@@ -270,9 +277,6 @@ interface AuthProviderRouteHandlers {
270
277
  * Response
271
278
  * - redirect to the auth provider for the user to sign in or consent.
272
279
  * - sets a nonce cookie and also pass the nonce as 'state' query parameter in the redirect request
273
- *
274
- * @param {express.Request} req
275
- * @param {express.Response} res
276
280
  */
277
281
  start(req: express.Request, res: express.Response): Promise<void>;
278
282
  /**
@@ -284,9 +288,6 @@ interface AuthProviderRouteHandlers {
284
288
  * Response
285
289
  * - postMessage to the window with a payload that contains accessToken, expiryInSeconds?, idToken? and scope.
286
290
  * - sets a refresh token cookie if the auth provider supports refresh tokens
287
- *
288
- * @param {express.Request} req
289
- * @param {express.Response} res
290
291
  */
291
292
  frameHandler(req: express.Request, res: express.Response): Promise<void>;
292
293
  /**
@@ -297,9 +298,6 @@ interface AuthProviderRouteHandlers {
297
298
  * - to contain a refresh token cookie and scope (Optional) query parameter.
298
299
  * Response
299
300
  * - payload with accessToken, expiryInSeconds?, idToken?, scope and user profile information.
300
- *
301
- * @param {express.Request} req
302
- * @param {express.Response} res
303
301
  */
304
302
  refresh?(req: express.Request, res: express.Response): Promise<void>;
305
303
  /**
@@ -307,9 +305,6 @@ interface AuthProviderRouteHandlers {
307
305
  *
308
306
  * Response
309
307
  * - removes the refresh token cookie
310
- *
311
- * @param {express.Request} req
312
- * @param {express.Response} res
313
308
  */
314
309
  logout?(req: express.Request, res: express.Response): Promise<void>;
315
310
  }
@@ -446,11 +441,7 @@ declare type SignInInfo<TAuthResult> = {
446
441
  *
447
442
  * @public
448
443
  */
449
- declare type SignInResolver<TAuthResult> = (info: SignInInfo<TAuthResult>, context: {
450
- tokenIssuer: TokenIssuer;
451
- catalogIdentityClient: CatalogIdentityClient;
452
- logger: Logger;
453
- }) => Promise<BackstageSignInResult>;
444
+ declare type SignInResolver<TAuthResult> = (info: SignInInfo<TAuthResult>, context: AuthResolverContext) => Promise<BackstageSignInResult>;
454
445
  /**
455
446
  * The return type of an authentication handler. Must contain valid profile
456
447
  * information.
@@ -473,7 +464,7 @@ declare type AuthHandlerResult = {
473
464
  *
474
465
  * @public
475
466
  */
476
- declare type AuthHandler<TAuthResult> = (input: TAuthResult) => Promise<AuthHandlerResult>;
467
+ declare type AuthHandler<TAuthResult> = (input: TAuthResult, context: AuthResolverContext) => Promise<AuthHandlerResult>;
477
468
  declare type StateEncoder = (req: OAuthStartRequest) => Promise<{
478
469
  encodedState: string;
479
470
  }>;
@@ -500,11 +491,12 @@ declare type Options = {
500
491
  appOrigin: string;
501
492
  tokenIssuer: TokenIssuer;
502
493
  isOriginAllowed: (origin: string) => boolean;
494
+ callbackUrl?: string;
503
495
  };
504
496
  declare class OAuthAdapter implements AuthProviderRouteHandlers {
505
497
  private readonly handlers;
506
498
  private readonly options;
507
- static fromConfig(config: AuthProviderConfig, handlers: OAuthHandlers, options: Pick<Options, 'providerId' | 'persistScopes' | 'disableRefresh' | 'tokenIssuer'>): OAuthAdapter;
499
+ static fromConfig(config: AuthProviderConfig, handlers: OAuthHandlers, options: Pick<Options, 'providerId' | 'persistScopes' | 'disableRefresh' | 'tokenIssuer' | 'callbackUrl'>): OAuthAdapter;
508
500
  constructor(handlers: OAuthHandlers, options: Options);
509
501
  start(req: express.Request, res: express.Response): Promise<void>;
510
502
  frameHandler(req: express.Request, res: express.Response): Promise<void>;
@@ -688,7 +680,7 @@ declare type GithubProviderOptions = {
688
680
  * Providing your own stateEncoder will allow you to add addition parameters to the state field.
689
681
  *
690
682
  * It is typed as follows:
691
- * export type StateEncoder = (input: OAuthState) => Promise<{encodedState: string}>;
683
+ * `export type StateEncoder = (input: OAuthState) => Promise<{encodedState: string}>;`
692
684
  *
693
685
  * Note: the stateEncoder must encode a 'nonce' value and an 'env' value. Without this, the OAuth flow will fail
694
686
  * (These two values will be set by the req.state by default)
@@ -766,6 +758,49 @@ declare type OAuth2ProviderOptions = {
766
758
  };
767
759
  declare const createOAuth2Provider: (options?: OAuth2ProviderOptions | undefined) => AuthProviderFactory;
768
760
 
761
+ /**
762
+ * JWT header extraction result, containing the raw value and the parsed JWT
763
+ * payload.
764
+ *
765
+ * @public
766
+ */
767
+ declare type OAuth2ProxyResult<JWTPayload> = {
768
+ /**
769
+ * Parsed and decoded JWT payload.
770
+ */
771
+ fullProfile: JWTPayload;
772
+ /**
773
+ * Raw JWT token
774
+ */
775
+ accessToken: string;
776
+ };
777
+ /**
778
+ * Options for the oauth2-proxy provider factory
779
+ *
780
+ * @public
781
+ */
782
+ declare type Oauth2ProxyProviderOptions<JWTPayload> = {
783
+ /**
784
+ * Configure an auth handler to generate a profile for the user.
785
+ */
786
+ authHandler: AuthHandler<OAuth2ProxyResult<JWTPayload>>;
787
+ /**
788
+ * Configure sign-in for this provider, without it the provider can not be used to sign users in.
789
+ */
790
+ signIn: {
791
+ /**
792
+ * Maps an auth result to a Backstage identity for the user.
793
+ */
794
+ resolver: SignInResolver<OAuth2ProxyResult<JWTPayload>>;
795
+ };
796
+ };
797
+ /**
798
+ * Factory function for oauth2-proxy auth provider
799
+ *
800
+ * @public
801
+ */
802
+ declare const createOauth2ProxyProvider: <JWTPayload>(options: Oauth2ProxyProviderOptions<JWTPayload>) => AuthProviderFactory;
803
+
769
804
  /**
770
805
  * authentication result for the OIDC which includes the token set and user information (a profile response sent by OIDC server)
771
806
  * @public
@@ -960,4 +995,4 @@ declare type WebMessageResponse = {
960
995
  declare const postMessageResponse: (res: express.Response, appOrigin: string, response: WebMessageResponse) => void;
961
996
  declare const ensuresXRequestedWith: (req: express.Request) => boolean;
962
997
 
963
- export { AtlassianAuthProvider, AtlassianProviderOptions, Auth0ProviderOptions, AuthHandler, AuthHandlerResult, AuthProviderFactory, AuthProviderFactoryOptions, AuthProviderRouteHandlers, AuthResponse, AwsAlbProviderOptions, BackstageIdentity, BackstageIdentityResponse, BackstageSignInResult, BackstageUserIdentity, BitbucketOAuthResult, BitbucketPassportProfile, BitbucketProviderOptions, CatalogIdentityClient, GcpIapProviderOptions, GcpIapResult, GcpIapTokenInfo, 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, createGcpIapProvider, createGithubProvider, createGitlabProvider, createGoogleProvider, createMicrosoftProvider, createOAuth2Provider, createOidcProvider, createOktaProvider, createOneLoginProvider, createOriginFilter, createRouter, createSamlProvider, factories as defaultAuthProviderFactories, encodeState, ensuresXRequestedWith, getEntityClaims, googleEmailSignInResolver, microsoftEmailSignInResolver, oktaEmailSignInResolver, postMessageResponse, prepareBackstageIdentityResponse, readState, verifyNonce };
998
+ 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.1",
4
+ "version": "0.8.0",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -30,14 +30,13 @@
30
30
  "clean": "backstage-cli clean"
31
31
  },
32
32
  "dependencies": {
33
- "@backstage/backend-common": "^0.10.2",
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",
33
+ "@backstage/backend-common": "^0.10.5",
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",
39
38
  "@backstage/types": "^0.1.1",
40
- "@google-cloud/firestore": "^4.15.1",
39
+ "@google-cloud/firestore": "^5.0.2",
41
40
  "@types/express": "^4.17.6",
42
41
  "@types/passport": "^1.0.3",
43
42
  "compression": "^1.7.4",
@@ -74,7 +73,8 @@
74
73
  "yn": "^4.0.0"
75
74
  },
76
75
  "devDependencies": {
77
- "@backstage/cli": "^0.10.5",
76
+ "@backstage/cli": "^0.13.0",
77
+ "@backstage/test-utils": "^0.2.3",
78
78
  "@types/body-parser": "^1.19.0",
79
79
  "@types/cookie-parser": "^1.4.2",
80
80
  "@types/express-session": "^1.17.2",
@@ -94,5 +94,5 @@
94
94
  "config.d.ts"
95
95
  ],
96
96
  "configSchema": "config.d.ts",
97
- "gitHead": "ffdb98aa2973366d48ff1774a7f892bc0c926e7e"
97
+ "gitHead": "493394603a2c47ea1d141159af9bc7bb84fac9e5"
98
98
  }