@backstage/plugin-auth-backend 0.10.1 → 0.12.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.
@@ -0,0 +1,908 @@
1
+ /// <reference types="node" />
2
+ import express from 'express';
3
+ import { Logger } from 'winston';
4
+ import { Config } from '@backstage/config';
5
+ import { TokenManager, PluginEndpointDiscovery, PluginDatabaseManager } from '@backstage/backend-common';
6
+ import { CatalogApi } from '@backstage/catalog-client';
7
+ import { BackstageSignInResult, BackstageIdentityResponse } from '@backstage/plugin-auth-node';
8
+ import { Profile } from 'passport';
9
+ import { UserEntity } from '@backstage/catalog-model';
10
+ import { TokenSet, UserinfoResponse } from 'openid-client';
11
+ import { JsonValue } from '@backstage/types';
12
+
13
+ /** Represents any form of serializable JWK */
14
+ interface AnyJWK extends Record<string, string> {
15
+ use: 'sig';
16
+ alg: string;
17
+ kid: string;
18
+ kty: string;
19
+ }
20
+ /** Parameters used to issue new ID Tokens */
21
+ declare type TokenParams = {
22
+ /** The claims that will be embedded within the token */
23
+ claims: {
24
+ /** The token subject, i.e. User ID */
25
+ sub: string;
26
+ /** A list of entity references that the user claims ownership through */
27
+ ent?: string[];
28
+ };
29
+ };
30
+ /**
31
+ * A TokenIssuer is able to issue verifiable ID Tokens on demand.
32
+ */
33
+ declare type TokenIssuer = {
34
+ /**
35
+ * Issues a new ID Token
36
+ */
37
+ issueToken(params: TokenParams): Promise<string>;
38
+ /**
39
+ * List all public keys that are currently being used to sign tokens, or have been used
40
+ * in the past within the token expiration time, including a grace period.
41
+ */
42
+ listPublicKeys(): Promise<{
43
+ keys: AnyJWK[];
44
+ }>;
45
+ };
46
+
47
+ /**
48
+ * Common options for passport.js-based OAuth providers
49
+ */
50
+ declare type OAuthProviderOptions = {
51
+ /**
52
+ * Client ID of the auth provider.
53
+ */
54
+ clientId: string;
55
+ /**
56
+ * Client Secret of the auth provider.
57
+ */
58
+ clientSecret: string;
59
+ /**
60
+ * Callback URL to be passed to the auth provider to redirect to after the user signs in.
61
+ */
62
+ callbackUrl: string;
63
+ };
64
+ declare type OAuthResult = {
65
+ fullProfile: Profile;
66
+ params: {
67
+ id_token?: string;
68
+ scope: string;
69
+ expires_in: number;
70
+ };
71
+ accessToken: string;
72
+ refreshToken?: string;
73
+ };
74
+ /**
75
+ * The expected response from an OAuth flow.
76
+ *
77
+ * @public
78
+ */
79
+ declare type OAuthResponse = {
80
+ profile: ProfileInfo;
81
+ providerInfo: OAuthProviderInfo;
82
+ backstageIdentity?: BackstageSignInResult;
83
+ };
84
+ declare type OAuthProviderInfo = {
85
+ /**
86
+ * An access token issued for the signed in user.
87
+ */
88
+ accessToken: string;
89
+ /**
90
+ * (Optional) Id token issued for the signed in user.
91
+ */
92
+ idToken?: string;
93
+ /**
94
+ * Expiry of the access token in seconds.
95
+ */
96
+ expiresInSeconds?: number;
97
+ /**
98
+ * Scopes granted for the access token.
99
+ */
100
+ scope: string;
101
+ };
102
+ declare type OAuthState = {
103
+ nonce: string;
104
+ env: string;
105
+ origin?: string;
106
+ scope?: string;
107
+ };
108
+ declare type OAuthStartRequest = express.Request<{}> & {
109
+ scope: string;
110
+ state: OAuthState;
111
+ };
112
+ declare type OAuthRefreshRequest = express.Request<{}> & {
113
+ scope: string;
114
+ refreshToken: string;
115
+ };
116
+ /**
117
+ * Any OAuth provider needs to implement this interface which has provider specific
118
+ * handlers for different methods to perform authentication, get access tokens,
119
+ * refresh tokens and perform sign out.
120
+ *
121
+ * @public
122
+ */
123
+ interface OAuthHandlers {
124
+ /**
125
+ * Initiate a sign in request with an auth provider.
126
+ */
127
+ start(req: OAuthStartRequest): Promise<RedirectInfo>;
128
+ /**
129
+ * Handle the redirect from the auth provider when the user has signed in.
130
+ */
131
+ handler(req: express.Request): Promise<{
132
+ response: OAuthResponse;
133
+ refreshToken?: string;
134
+ }>;
135
+ /**
136
+ * (Optional) Given a refresh token and scope fetches a new access token from the auth provider.
137
+ */
138
+ refresh?(req: OAuthRefreshRequest): Promise<{
139
+ response: OAuthResponse;
140
+ refreshToken?: string;
141
+ }>;
142
+ /**
143
+ * (Optional) Sign out of the auth provider.
144
+ */
145
+ logout?(): Promise<void>;
146
+ }
147
+
148
+ declare type UserQuery = {
149
+ annotations: Record<string, string>;
150
+ };
151
+ declare type MemberClaimQuery = {
152
+ entityRefs: string[];
153
+ logger?: Logger;
154
+ };
155
+ /**
156
+ * A catalog client tailored for reading out identity data from the catalog.
157
+ */
158
+ declare class CatalogIdentityClient {
159
+ private readonly catalogApi;
160
+ private readonly tokenManager;
161
+ constructor(options: {
162
+ catalogApi: CatalogApi;
163
+ tokenManager: TokenManager;
164
+ });
165
+ /**
166
+ * Looks up a single user using a query.
167
+ *
168
+ * Throws a NotFoundError or ConflictError if 0 or multiple users are found.
169
+ */
170
+ findUser(query: UserQuery): Promise<UserEntity>;
171
+ /**
172
+ * Resolve additional entity claims from the catalog, using the passed-in entity names. Designed
173
+ * to be used within a `signInResolver` where additional entity claims might be provided, but
174
+ * group membership and transient group membership lean on imported catalog relations.
175
+ *
176
+ * Returns a superset of the entity names that can be passed directly to `issueToken` as `ent`.
177
+ */
178
+ resolveCatalogMembership(query: MemberClaimQuery): Promise<string[]>;
179
+ }
180
+
181
+ declare function getEntityClaims(entity: UserEntity): TokenParams['claims'];
182
+
183
+ /**
184
+ * The context that is used for auth processing.
185
+ *
186
+ * @public
187
+ */
188
+ declare type AuthResolverContext = {
189
+ tokenIssuer: TokenIssuer;
190
+ catalogIdentityClient: CatalogIdentityClient;
191
+ logger: Logger;
192
+ };
193
+ /**
194
+ * The callback used to resolve the cookie configuration for auth providers that use cookies.
195
+ * @public
196
+ */
197
+ declare type CookieConfigurer = (ctx: {
198
+ /** ID of the auth provider that this configuration applies to */
199
+ providerId: string;
200
+ /** The externally reachable base URL of the auth-backend plugin */
201
+ baseUrl: string;
202
+ /** The configured callback URL of the auth provider */
203
+ callbackUrl: string;
204
+ }) => {
205
+ domain: string;
206
+ path: string;
207
+ secure: boolean;
208
+ };
209
+ declare type AuthProviderConfig = {
210
+ /**
211
+ * The protocol://domain[:port] where the app is hosted. This is used to construct the
212
+ * callbackURL to redirect to once the user signs in to the auth provider.
213
+ */
214
+ baseUrl: string;
215
+ /**
216
+ * The base URL of the app as provided by app.baseUrl
217
+ */
218
+ appUrl: string;
219
+ /**
220
+ * A function that is called to check whether an origin is allowed to receive the authentication result.
221
+ */
222
+ isOriginAllowed: (origin: string) => boolean;
223
+ /**
224
+ * The function used to resolve cookie configuration based on the auth provider options.
225
+ */
226
+ cookieConfigurer?: CookieConfigurer;
227
+ };
228
+ declare type RedirectInfo = {
229
+ /**
230
+ * URL to redirect to
231
+ */
232
+ url: string;
233
+ /**
234
+ * Status code to use for the redirect
235
+ */
236
+ status?: number;
237
+ };
238
+ /**
239
+ * Any Auth provider needs to implement this interface which handles the routes in the
240
+ * auth backend. Any auth API requests from the frontend reaches these methods.
241
+ *
242
+ * The routes in the auth backend API are tied to these methods like below
243
+ *
244
+ * `/auth/[provider]/start -> start`
245
+ * `/auth/[provider]/handler/frame -> frameHandler`
246
+ * `/auth/[provider]/refresh -> refresh`
247
+ * `/auth/[provider]/logout -> logout`
248
+ */
249
+ interface AuthProviderRouteHandlers {
250
+ /**
251
+ * Handles the start route of the API. This initiates a sign in request with an auth provider.
252
+ *
253
+ * Request
254
+ * - scopes for the auth request (Optional)
255
+ * Response
256
+ * - redirect to the auth provider for the user to sign in or consent.
257
+ * - sets a nonce cookie and also pass the nonce as 'state' query parameter in the redirect request
258
+ */
259
+ start(req: express.Request, res: express.Response): Promise<void>;
260
+ /**
261
+ * Once the user signs in or consents in the OAuth screen, the auth provider redirects to the
262
+ * callbackURL which is handled by this method.
263
+ *
264
+ * Request
265
+ * - to contain a nonce cookie and a 'state' query parameter
266
+ * Response
267
+ * - postMessage to the window with a payload that contains accessToken, expiryInSeconds?, idToken? and scope.
268
+ * - sets a refresh token cookie if the auth provider supports refresh tokens
269
+ */
270
+ frameHandler(req: express.Request, res: express.Response): Promise<void>;
271
+ /**
272
+ * (Optional) If the auth provider supports refresh tokens then this method handles
273
+ * requests to get a new access token.
274
+ *
275
+ * Request
276
+ * - to contain a refresh token cookie and scope (Optional) query parameter.
277
+ * Response
278
+ * - payload with accessToken, expiryInSeconds?, idToken?, scope and user profile information.
279
+ */
280
+ refresh?(req: express.Request, res: express.Response): Promise<void>;
281
+ /**
282
+ * (Optional) Handles sign out requests
283
+ *
284
+ * Response
285
+ * - removes the refresh token cookie
286
+ */
287
+ logout?(req: express.Request, res: express.Response): Promise<void>;
288
+ }
289
+ declare type AuthProviderFactoryOptions = {
290
+ providerId: string;
291
+ globalConfig: AuthProviderConfig;
292
+ config: Config;
293
+ logger: Logger;
294
+ tokenManager: TokenManager;
295
+ tokenIssuer: TokenIssuer;
296
+ discovery: PluginEndpointDiscovery;
297
+ catalogApi: CatalogApi;
298
+ };
299
+ declare type AuthProviderFactory = (options: AuthProviderFactoryOptions) => AuthProviderRouteHandlers;
300
+ declare type AuthResponse<ProviderInfo> = {
301
+ providerInfo: ProviderInfo;
302
+ profile: ProfileInfo;
303
+ backstageIdentity?: BackstageIdentityResponse;
304
+ };
305
+ /**
306
+ * Used to display login information to user, i.e. sidebar popup.
307
+ *
308
+ * It is also temporarily used as the profile of the signed-in user's Backstage
309
+ * identity, but we want to replace that with data from identity and/org catalog
310
+ * service
311
+ *
312
+ * @public
313
+ */
314
+ declare type ProfileInfo = {
315
+ /**
316
+ * Email ID of the signed in user.
317
+ */
318
+ email?: string;
319
+ /**
320
+ * Display name that can be presented to the signed in user.
321
+ */
322
+ displayName?: string;
323
+ /**
324
+ * URL to an image that can be used as the display image or avatar of the
325
+ * signed in user.
326
+ */
327
+ picture?: string;
328
+ };
329
+ /**
330
+ * Type of sign in information context. Includes the profile information and
331
+ * authentication result which contains auth related information.
332
+ *
333
+ * @public
334
+ */
335
+ declare type SignInInfo<TAuthResult> = {
336
+ /**
337
+ * The simple profile passed down for use in the frontend.
338
+ */
339
+ profile: ProfileInfo;
340
+ /**
341
+ * The authentication result that was received from the authentication
342
+ * provider.
343
+ */
344
+ result: TAuthResult;
345
+ };
346
+ /**
347
+ * Describes the function which handles the result of a successful
348
+ * authentication. Must return a valid {@link @backstage/plugin-auth-node#BackstageSignInResult}.
349
+ *
350
+ * @public
351
+ */
352
+ declare type SignInResolver<TAuthResult> = (info: SignInInfo<TAuthResult>, context: AuthResolverContext) => Promise<BackstageSignInResult>;
353
+ /**
354
+ * The return type of an authentication handler. Must contain valid profile
355
+ * information.
356
+ *
357
+ * @public
358
+ */
359
+ declare type AuthHandlerResult = {
360
+ profile: ProfileInfo;
361
+ };
362
+ /**
363
+ * The AuthHandler function is called every time the user authenticates using
364
+ * the provider.
365
+ *
366
+ * The handler should return a profile that represents the session for the user
367
+ * in the frontend.
368
+ *
369
+ * Throwing an error in the function will cause the authentication to fail,
370
+ * making it possible to use this function as a way to limit access to a certain
371
+ * group of users.
372
+ *
373
+ * @public
374
+ */
375
+ declare type AuthHandler<TAuthResult> = (input: TAuthResult, context: AuthResolverContext) => Promise<AuthHandlerResult>;
376
+ declare type StateEncoder = (req: OAuthStartRequest) => Promise<{
377
+ encodedState: string;
378
+ }>;
379
+
380
+ declare class OAuthEnvironmentHandler implements AuthProviderRouteHandlers {
381
+ private readonly handlers;
382
+ static mapConfig(config: Config, factoryFunc: (envConfig: Config) => AuthProviderRouteHandlers): OAuthEnvironmentHandler;
383
+ constructor(handlers: Map<string, AuthProviderRouteHandlers>);
384
+ start(req: express.Request, res: express.Response): Promise<void>;
385
+ frameHandler(req: express.Request, res: express.Response): Promise<void>;
386
+ refresh(req: express.Request, res: express.Response): Promise<void>;
387
+ logout(req: express.Request, res: express.Response): Promise<void>;
388
+ private getRequestFromEnv;
389
+ private getProviderForEnv;
390
+ }
391
+
392
+ declare type Options = {
393
+ providerId: string;
394
+ secure: boolean;
395
+ disableRefresh?: boolean;
396
+ persistScopes?: boolean;
397
+ cookieDomain: string;
398
+ cookiePath: string;
399
+ appOrigin: string;
400
+ tokenIssuer: TokenIssuer;
401
+ isOriginAllowed: (origin: string) => boolean;
402
+ callbackUrl: string;
403
+ };
404
+ declare class OAuthAdapter implements AuthProviderRouteHandlers {
405
+ private readonly handlers;
406
+ private readonly options;
407
+ static fromConfig(config: AuthProviderConfig, handlers: OAuthHandlers, options: Pick<Options, 'providerId' | 'persistScopes' | 'disableRefresh' | 'tokenIssuer' | 'callbackUrl'>): OAuthAdapter;
408
+ private readonly baseCookieOptions;
409
+ constructor(handlers: OAuthHandlers, options: Options);
410
+ start(req: express.Request, res: express.Response): Promise<void>;
411
+ frameHandler(req: express.Request, res: express.Response): Promise<void>;
412
+ logout(req: express.Request, res: express.Response): Promise<void>;
413
+ refresh(req: express.Request, res: express.Response): Promise<void>;
414
+ /**
415
+ * If the response from the OAuth provider includes a Backstage identity, we
416
+ * make sure it's populated with all the information we can derive from the user ID.
417
+ */
418
+ private populateIdentity;
419
+ private setNonceCookie;
420
+ private setGrantedScopeCookie;
421
+ private getGrantedScopeFromCookie;
422
+ private setRefreshTokenCookie;
423
+ private removeRefreshTokenCookie;
424
+ }
425
+
426
+ declare const readState: (stateString: string) => OAuthState;
427
+ declare const encodeState: (state: OAuthState) => string;
428
+ declare const verifyNonce: (req: express.Request, providerId: string) => void;
429
+
430
+ declare type AtlassianAuthProviderOptions = OAuthProviderOptions & {
431
+ scopes: string;
432
+ signInResolver?: SignInResolver<OAuthResult>;
433
+ authHandler: AuthHandler<OAuthResult>;
434
+ tokenIssuer: TokenIssuer;
435
+ catalogIdentityClient: CatalogIdentityClient;
436
+ logger: Logger;
437
+ };
438
+ declare class AtlassianAuthProvider implements OAuthHandlers {
439
+ private readonly _strategy;
440
+ private readonly signInResolver?;
441
+ private readonly authHandler;
442
+ private readonly tokenIssuer;
443
+ private readonly catalogIdentityClient;
444
+ private readonly logger;
445
+ constructor(options: AtlassianAuthProviderOptions);
446
+ start(req: OAuthStartRequest): Promise<RedirectInfo>;
447
+ handler(req: express.Request): Promise<{
448
+ response: OAuthResponse;
449
+ refreshToken: string | undefined;
450
+ }>;
451
+ private handleResult;
452
+ refresh(req: OAuthRefreshRequest): Promise<{
453
+ response: OAuthResponse;
454
+ refreshToken: string | undefined;
455
+ }>;
456
+ }
457
+ declare type AtlassianProviderOptions = {
458
+ /**
459
+ * The profile transformation function used to verify and convert the auth response
460
+ * into the profile that will be presented to the user.
461
+ */
462
+ authHandler?: AuthHandler<OAuthResult>;
463
+ /**
464
+ * Configure sign-in for this provider, without it the provider can not be used to sign users in.
465
+ */
466
+ signIn?: {
467
+ resolver: SignInResolver<OAuthResult>;
468
+ };
469
+ };
470
+ declare const createAtlassianProvider: (options?: AtlassianProviderOptions | undefined) => AuthProviderFactory;
471
+
472
+ /** @public */
473
+ declare type Auth0ProviderOptions = {
474
+ /**
475
+ * The profile transformation function used to verify and convert the auth response
476
+ * into the profile that will be presented to the user.
477
+ */
478
+ authHandler?: AuthHandler<OAuthResult>;
479
+ /**
480
+ * Configure sign-in for this provider, without it the provider can not be used to sign users in.
481
+ */
482
+ signIn?: {
483
+ /**
484
+ * Maps an auth result to a Backstage identity for the user.
485
+ */
486
+ resolver: SignInResolver<OAuthResult>;
487
+ };
488
+ };
489
+ /** @public */
490
+ declare const createAuth0Provider: (options?: Auth0ProviderOptions | undefined) => AuthProviderFactory;
491
+
492
+ declare type AwsAlbResult = {
493
+ fullProfile: Profile;
494
+ expiresInSeconds?: number;
495
+ accessToken: string;
496
+ };
497
+ declare type AwsAlbProviderOptions = {
498
+ /**
499
+ * The profile transformation function used to verify and convert the auth response
500
+ * into the profile that will be presented to the user.
501
+ */
502
+ authHandler?: AuthHandler<AwsAlbResult>;
503
+ /**
504
+ * Configure sign-in for this provider, without it the provider can not be used to sign users in.
505
+ */
506
+ signIn: {
507
+ /**
508
+ * Maps an auth result to a Backstage identity for the user.
509
+ */
510
+ resolver: SignInResolver<AwsAlbResult>;
511
+ };
512
+ };
513
+ declare const createAwsAlbProvider: (options?: AwsAlbProviderOptions | undefined) => AuthProviderFactory;
514
+
515
+ declare type BitbucketOAuthResult = {
516
+ fullProfile: BitbucketPassportProfile;
517
+ params: {
518
+ id_token?: string;
519
+ scope: string;
520
+ expires_in: number;
521
+ };
522
+ accessToken: string;
523
+ refreshToken?: string;
524
+ };
525
+ declare type BitbucketPassportProfile = Profile & {
526
+ id?: string;
527
+ displayName?: string;
528
+ username?: string;
529
+ avatarUrl?: string;
530
+ _json?: {
531
+ links?: {
532
+ avatar?: {
533
+ href?: string;
534
+ };
535
+ };
536
+ };
537
+ };
538
+ declare const bitbucketUsernameSignInResolver: SignInResolver<BitbucketOAuthResult>;
539
+ declare const bitbucketUserIdSignInResolver: SignInResolver<BitbucketOAuthResult>;
540
+ declare type BitbucketProviderOptions = {
541
+ /**
542
+ * The profile transformation function used to verify and convert the auth response
543
+ * into the profile that will be presented to the user.
544
+ */
545
+ authHandler?: AuthHandler<OAuthResult>;
546
+ /**
547
+ * Configure sign-in for this provider, without it the provider can not be used to sign users in.
548
+ */
549
+ signIn?: {
550
+ /**
551
+ * Maps an auth result to a Backstage identity for the user.
552
+ */
553
+ resolver: SignInResolver<OAuthResult>;
554
+ };
555
+ };
556
+ declare const createBitbucketProvider: (options?: BitbucketProviderOptions | undefined) => AuthProviderFactory;
557
+
558
+ declare type GithubOAuthResult = {
559
+ fullProfile: Profile;
560
+ params: {
561
+ scope: string;
562
+ expires_in?: string;
563
+ refresh_token_expires_in?: string;
564
+ };
565
+ accessToken: string;
566
+ refreshToken?: string;
567
+ };
568
+ declare type GithubProviderOptions = {
569
+ /**
570
+ * The profile transformation function used to verify and convert the auth response
571
+ * into the profile that will be presented to the user.
572
+ */
573
+ authHandler?: AuthHandler<GithubOAuthResult>;
574
+ /**
575
+ * Configure sign-in for this provider, without it the provider can not be used to sign users in.
576
+ */
577
+ signIn?: {
578
+ /**
579
+ * Maps an auth result to a Backstage identity for the user.
580
+ */
581
+ resolver?: SignInResolver<GithubOAuthResult>;
582
+ };
583
+ /**
584
+ * The state encoder used to encode the 'state' parameter on the OAuth request.
585
+ *
586
+ * It should return a string that takes the state params (from the request), url encodes the params
587
+ * and finally base64 encodes them.
588
+ *
589
+ * Providing your own stateEncoder will allow you to add addition parameters to the state field.
590
+ *
591
+ * It is typed as follows:
592
+ * `export type StateEncoder = (input: OAuthState) => Promise<{encodedState: string}>;`
593
+ *
594
+ * Note: the stateEncoder must encode a 'nonce' value and an 'env' value. Without this, the OAuth flow will fail
595
+ * (These two values will be set by the req.state by default)
596
+ *
597
+ * For more information, please see the helper module in ../../oauth/helpers #readState
598
+ */
599
+ stateEncoder?: StateEncoder;
600
+ };
601
+ declare const createGithubProvider: (options?: GithubProviderOptions | undefined) => AuthProviderFactory;
602
+
603
+ declare type GitlabProviderOptions = {
604
+ /**
605
+ * The profile transformation function used to verify and convert the auth response
606
+ * into the profile that will be presented to the user.
607
+ */
608
+ authHandler?: AuthHandler<OAuthResult>;
609
+ /**
610
+ * Configure sign-in for this provider, without it the provider can not be used to sign users in.
611
+ */
612
+ /**
613
+ * Maps an auth result to a Backstage identity for the user.
614
+ *
615
+ * Set to `'email'` to use the default email-based sign in resolver, which will search
616
+ * the catalog for a single user entity that has a matching `microsoft.com/email` annotation.
617
+ */
618
+ signIn?: {
619
+ resolver?: SignInResolver<OAuthResult>;
620
+ };
621
+ };
622
+ declare const createGitlabProvider: (options?: GitlabProviderOptions | undefined) => AuthProviderFactory;
623
+
624
+ declare const googleEmailSignInResolver: SignInResolver<OAuthResult>;
625
+ declare type GoogleProviderOptions = {
626
+ /**
627
+ * The profile transformation function used to verify and convert the auth response
628
+ * into the profile that will be presented to the user.
629
+ */
630
+ authHandler?: AuthHandler<OAuthResult>;
631
+ /**
632
+ * Configure sign-in for this provider, without it the provider can not be used to sign users in.
633
+ */
634
+ signIn?: {
635
+ /**
636
+ * Maps an auth result to a Backstage identity for the user.
637
+ */
638
+ resolver?: SignInResolver<OAuthResult>;
639
+ };
640
+ };
641
+ declare const createGoogleProvider: (options?: GoogleProviderOptions | undefined) => AuthProviderFactory;
642
+
643
+ declare const microsoftEmailSignInResolver: SignInResolver<OAuthResult>;
644
+ declare type MicrosoftProviderOptions = {
645
+ /**
646
+ * The profile transformation function used to verify and convert the auth response
647
+ * into the profile that will be presented to the user.
648
+ */
649
+ authHandler?: AuthHandler<OAuthResult>;
650
+ /**
651
+ * Configure sign-in for this provider, without it the provider can not be used to sign users in.
652
+ */
653
+ signIn?: {
654
+ /**
655
+ * Maps an auth result to a Backstage identity for the user.
656
+ */
657
+ resolver?: SignInResolver<OAuthResult>;
658
+ };
659
+ };
660
+ declare const createMicrosoftProvider: (options?: MicrosoftProviderOptions | undefined) => AuthProviderFactory;
661
+
662
+ declare type OAuth2ProviderOptions = {
663
+ authHandler?: AuthHandler<OAuthResult>;
664
+ signIn?: {
665
+ resolver?: SignInResolver<OAuthResult>;
666
+ };
667
+ };
668
+ declare const createOAuth2Provider: (options?: OAuth2ProviderOptions | undefined) => AuthProviderFactory;
669
+
670
+ /**
671
+ * JWT header extraction result, containing the raw value and the parsed JWT
672
+ * payload.
673
+ *
674
+ * @public
675
+ */
676
+ declare type OAuth2ProxyResult<JWTPayload> = {
677
+ /**
678
+ * Parsed and decoded JWT payload.
679
+ */
680
+ fullProfile: JWTPayload;
681
+ /**
682
+ * Raw JWT token
683
+ */
684
+ accessToken: string;
685
+ };
686
+ /**
687
+ * Options for the oauth2-proxy provider factory
688
+ *
689
+ * @public
690
+ */
691
+ declare type Oauth2ProxyProviderOptions<JWTPayload> = {
692
+ /**
693
+ * Configure an auth handler to generate a profile for the user.
694
+ */
695
+ authHandler: AuthHandler<OAuth2ProxyResult<JWTPayload>>;
696
+ /**
697
+ * Configure sign-in for this provider, without it the provider can not be used to sign users in.
698
+ */
699
+ signIn: {
700
+ /**
701
+ * Maps an auth result to a Backstage identity for the user.
702
+ */
703
+ resolver: SignInResolver<OAuth2ProxyResult<JWTPayload>>;
704
+ };
705
+ };
706
+ /**
707
+ * Factory function for oauth2-proxy auth provider
708
+ *
709
+ * @public
710
+ */
711
+ declare const createOauth2ProxyProvider: <JWTPayload>(options: Oauth2ProxyProviderOptions<JWTPayload>) => AuthProviderFactory;
712
+
713
+ /**
714
+ * authentication result for the OIDC which includes the token set and user information (a profile response sent by OIDC server)
715
+ * @public
716
+ */
717
+ declare type OidcAuthResult = {
718
+ tokenset: TokenSet;
719
+ userinfo: UserinfoResponse;
720
+ };
721
+ /**
722
+ * OIDC provider callback options. An auth handler and a sign in resolver
723
+ * can be passed while creating a OIDC provider.
724
+ *
725
+ * authHandler : called after sign in was successful, a new object must be returned which includes a profile
726
+ * signInResolver: called after sign in was successful, expects to return a new {@link @backstage/plugin-auth-node#BackstageSignInResult}
727
+ *
728
+ * Both options are optional. There is fallback for authHandler where the default handler expect an e-mail explicitly
729
+ * otherwise it throws an error
730
+ *
731
+ * @public
732
+ */
733
+ declare type OidcProviderOptions = {
734
+ authHandler?: AuthHandler<OidcAuthResult>;
735
+ signIn?: {
736
+ resolver?: SignInResolver<OidcAuthResult>;
737
+ };
738
+ };
739
+ declare const createOidcProvider: (options?: OidcProviderOptions | undefined) => AuthProviderFactory;
740
+
741
+ declare const oktaEmailSignInResolver: SignInResolver<OAuthResult>;
742
+ declare type OktaProviderOptions = {
743
+ /**
744
+ * The profile transformation function used to verify and convert the auth response
745
+ * into the profile that will be presented to the user.
746
+ */
747
+ authHandler?: AuthHandler<OAuthResult>;
748
+ /**
749
+ * Configure sign-in for this provider, without it the provider can not be used to sign users in.
750
+ */
751
+ signIn?: {
752
+ /**
753
+ * Maps an auth result to a Backstage identity for the user.
754
+ */
755
+ resolver?: SignInResolver<OAuthResult>;
756
+ };
757
+ };
758
+ declare const createOktaProvider: (_options?: OktaProviderOptions | undefined) => AuthProviderFactory;
759
+
760
+ /** @public */
761
+ declare type OneLoginProviderOptions = {
762
+ /**
763
+ * The profile transformation function used to verify and convert the auth response
764
+ * into the profile that will be presented to the user.
765
+ */
766
+ authHandler?: AuthHandler<OAuthResult>;
767
+ /**
768
+ * Configure sign-in for this provider, without it the provider can not be used to sign users in.
769
+ */
770
+ signIn?: {
771
+ /**
772
+ * Maps an auth result to a Backstage identity for the user.
773
+ */
774
+ resolver: SignInResolver<OAuthResult>;
775
+ };
776
+ };
777
+ /** @public */
778
+ declare const createOneLoginProvider: (options?: OneLoginProviderOptions | undefined) => AuthProviderFactory;
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
+
804
+ /**
805
+ * The data extracted from an IAP token.
806
+ *
807
+ * @public
808
+ */
809
+ declare type GcpIapTokenInfo = {
810
+ /**
811
+ * The unique, stable identifier for the user.
812
+ */
813
+ sub: string;
814
+ /**
815
+ * User email address.
816
+ */
817
+ email: string;
818
+ /**
819
+ * Other fields.
820
+ */
821
+ [key: string]: JsonValue;
822
+ };
823
+ /**
824
+ * The result of the initial auth challenge. This is the input to the auth
825
+ * callbacks.
826
+ *
827
+ * @public
828
+ */
829
+ declare type GcpIapResult = {
830
+ /**
831
+ * The data extracted from the IAP token header.
832
+ */
833
+ iapToken: GcpIapTokenInfo;
834
+ };
835
+ /**
836
+ * Options for {@link createGcpIapProvider}.
837
+ *
838
+ * @public
839
+ */
840
+ declare type GcpIapProviderOptions = {
841
+ /**
842
+ * The profile transformation function used to verify and convert the auth
843
+ * response into the profile that will be presented to the user. The default
844
+ * implementation just provides the authenticated email that the IAP
845
+ * presented.
846
+ */
847
+ authHandler?: AuthHandler<GcpIapResult>;
848
+ /**
849
+ * Configures sign-in for this provider.
850
+ */
851
+ signIn: {
852
+ /**
853
+ * Maps an auth result to a Backstage identity for the user.
854
+ */
855
+ resolver: SignInResolver<GcpIapResult>;
856
+ };
857
+ };
858
+
859
+ /**
860
+ * Creates an auth provider for Google Identity-Aware Proxy.
861
+ *
862
+ * @public
863
+ */
864
+ declare function createGcpIapProvider(options: GcpIapProviderOptions): AuthProviderFactory;
865
+
866
+ declare const factories: {
867
+ [providerId: string]: AuthProviderFactory;
868
+ };
869
+
870
+ /**
871
+ * Parses a Backstage-issued token and decorates the
872
+ * {@link @backstage/plugin-auth-node#BackstageIdentityResponse} with identity information sourced from the
873
+ * token.
874
+ *
875
+ * @public
876
+ */
877
+ declare function prepareBackstageIdentityResponse(result: BackstageSignInResult): BackstageIdentityResponse;
878
+
879
+ declare type ProviderFactories = {
880
+ [s: string]: AuthProviderFactory;
881
+ };
882
+ interface RouterOptions {
883
+ logger: Logger;
884
+ database: PluginDatabaseManager;
885
+ config: Config;
886
+ discovery: PluginEndpointDiscovery;
887
+ tokenManager: TokenManager;
888
+ providerFactories?: ProviderFactories;
889
+ }
890
+ declare function createRouter(options: RouterOptions): Promise<express.Router>;
891
+ declare function createOriginFilter(config: Config): (origin: string) => boolean;
892
+
893
+ /**
894
+ * Payload sent as a post message after the auth request is complete.
895
+ * If successful then has a valid payload with Auth information else contains an error.
896
+ */
897
+ declare type WebMessageResponse = {
898
+ type: 'authorization_response';
899
+ response: AuthResponse<unknown>;
900
+ } | {
901
+ type: 'authorization_response';
902
+ error: Error;
903
+ };
904
+
905
+ declare const postMessageResponse: (res: express.Response, appOrigin: string, response: WebMessageResponse) => void;
906
+ declare const ensuresXRequestedWith: (req: express.Request) => boolean;
907
+
908
+ export { AtlassianAuthProvider, AtlassianProviderOptions, Auth0ProviderOptions, AuthHandler, AuthHandlerResult, AuthProviderFactory, AuthProviderFactoryOptions, AuthProviderRouteHandlers, AuthResolverContext, AuthResponse, AwsAlbProviderOptions, BitbucketOAuthResult, BitbucketPassportProfile, BitbucketProviderOptions, CatalogIdentityClient, CookieConfigurer, GcpIapProviderOptions, GcpIapResult, GcpIapTokenInfo, GithubOAuthResult, GithubProviderOptions, GitlabProviderOptions, GoogleProviderOptions, 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 };