@backstage/plugin-auth-backend 0.4.4 → 0.4.8
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/CHANGELOG.md +54 -0
- package/config.d.ts +27 -0
- package/dist/index.cjs.js +320 -19
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +156 -97
- package/package.json +11 -10
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { PluginEndpointDiscovery, PluginDatabaseManager } from '@backstage/backe
|
|
|
5
5
|
import { CatalogApi } from '@backstage/catalog-client';
|
|
6
6
|
import { UserEntity, Entity } from '@backstage/catalog-model';
|
|
7
7
|
import { Config } from '@backstage/config';
|
|
8
|
-
import { JSONWebKey } from 'jose';
|
|
9
8
|
import { Profile } from 'passport';
|
|
9
|
+
import { JSONWebKey } from 'jose';
|
|
10
10
|
|
|
11
11
|
/** Represents any form of serializable JWK */
|
|
12
12
|
interface AnyJWK extends Record<string, string> {
|
|
@@ -42,6 +42,101 @@ declare type TokenIssuer = {
|
|
|
42
42
|
}>;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Common options for passport.js-based OAuth providers
|
|
47
|
+
*/
|
|
48
|
+
declare type OAuthProviderOptions = {
|
|
49
|
+
/**
|
|
50
|
+
* Client ID of the auth provider.
|
|
51
|
+
*/
|
|
52
|
+
clientId: string;
|
|
53
|
+
/**
|
|
54
|
+
* Client Secret of the auth provider.
|
|
55
|
+
*/
|
|
56
|
+
clientSecret: string;
|
|
57
|
+
/**
|
|
58
|
+
* Callback URL to be passed to the auth provider to redirect to after the user signs in.
|
|
59
|
+
*/
|
|
60
|
+
callbackUrl: string;
|
|
61
|
+
};
|
|
62
|
+
declare type OAuthResult = {
|
|
63
|
+
fullProfile: Profile;
|
|
64
|
+
params: {
|
|
65
|
+
id_token?: string;
|
|
66
|
+
scope: string;
|
|
67
|
+
expires_in: number;
|
|
68
|
+
};
|
|
69
|
+
accessToken: string;
|
|
70
|
+
refreshToken?: string;
|
|
71
|
+
};
|
|
72
|
+
declare type OAuthResponse = AuthResponse<OAuthProviderInfo>;
|
|
73
|
+
declare type OAuthProviderInfo = {
|
|
74
|
+
/**
|
|
75
|
+
* An access token issued for the signed in user.
|
|
76
|
+
*/
|
|
77
|
+
accessToken: string;
|
|
78
|
+
/**
|
|
79
|
+
* (Optional) Id token issued for the signed in user.
|
|
80
|
+
*/
|
|
81
|
+
idToken?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Expiry of the access token in seconds.
|
|
84
|
+
*/
|
|
85
|
+
expiresInSeconds?: number;
|
|
86
|
+
/**
|
|
87
|
+
* Scopes granted for the access token.
|
|
88
|
+
*/
|
|
89
|
+
scope: string;
|
|
90
|
+
/**
|
|
91
|
+
* A refresh token issued for the signed in user
|
|
92
|
+
*/
|
|
93
|
+
refreshToken?: string;
|
|
94
|
+
};
|
|
95
|
+
declare type OAuthState = {
|
|
96
|
+
nonce: string;
|
|
97
|
+
env: string;
|
|
98
|
+
origin?: string;
|
|
99
|
+
};
|
|
100
|
+
declare type OAuthStartRequest = express.Request<{}> & {
|
|
101
|
+
scope: string;
|
|
102
|
+
state: OAuthState;
|
|
103
|
+
};
|
|
104
|
+
declare type OAuthRefreshRequest = express.Request<{}> & {
|
|
105
|
+
scope: string;
|
|
106
|
+
refreshToken: string;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Any OAuth provider needs to implement this interface which has provider specific
|
|
110
|
+
* handlers for different methods to perform authentication, get access tokens,
|
|
111
|
+
* refresh tokens and perform sign out.
|
|
112
|
+
*/
|
|
113
|
+
interface OAuthHandlers {
|
|
114
|
+
/**
|
|
115
|
+
* This method initiates a sign in request with an auth provider.
|
|
116
|
+
* @param {express.Request} req
|
|
117
|
+
* @param options
|
|
118
|
+
*/
|
|
119
|
+
start(req: OAuthStartRequest): Promise<RedirectInfo>;
|
|
120
|
+
/**
|
|
121
|
+
* Handles the redirect from the auth provider when the user has signed in.
|
|
122
|
+
* @param {express.Request} req
|
|
123
|
+
*/
|
|
124
|
+
handler(req: express.Request): Promise<{
|
|
125
|
+
response: AuthResponse<OAuthProviderInfo>;
|
|
126
|
+
refreshToken?: string;
|
|
127
|
+
}>;
|
|
128
|
+
/**
|
|
129
|
+
* (Optional) Given a refresh token and scope fetches a new access token from the auth provider.
|
|
130
|
+
* @param {string} refreshToken
|
|
131
|
+
* @param {string} scope
|
|
132
|
+
*/
|
|
133
|
+
refresh?(req: OAuthRefreshRequest): Promise<AuthResponse<OAuthProviderInfo>>;
|
|
134
|
+
/**
|
|
135
|
+
* (Optional) Sign out of the auth provider.
|
|
136
|
+
*/
|
|
137
|
+
logout?(): Promise<void>;
|
|
138
|
+
}
|
|
139
|
+
|
|
45
140
|
/**
|
|
46
141
|
* A identity client to interact with auth-backend
|
|
47
142
|
* and authenticate backstage identity tokens
|
|
@@ -293,6 +388,9 @@ declare type AuthHandlerResult = {
|
|
|
293
388
|
* possible to use this function as a way to limit access to a certain group of users.
|
|
294
389
|
*/
|
|
295
390
|
declare type AuthHandler<AuthResult> = (input: AuthResult) => Promise<AuthHandlerResult>;
|
|
391
|
+
declare type StateEncoder = (req: OAuthStartRequest) => Promise<{
|
|
392
|
+
encodedState: string;
|
|
393
|
+
}>;
|
|
296
394
|
|
|
297
395
|
declare class OAuthEnvironmentHandler implements AuthProviderRouteHandlers {
|
|
298
396
|
private readonly handlers;
|
|
@@ -306,101 +404,6 @@ declare class OAuthEnvironmentHandler implements AuthProviderRouteHandlers {
|
|
|
306
404
|
private getProviderForEnv;
|
|
307
405
|
}
|
|
308
406
|
|
|
309
|
-
/**
|
|
310
|
-
* Common options for passport.js-based OAuth providers
|
|
311
|
-
*/
|
|
312
|
-
declare type OAuthProviderOptions = {
|
|
313
|
-
/**
|
|
314
|
-
* Client ID of the auth provider.
|
|
315
|
-
*/
|
|
316
|
-
clientId: string;
|
|
317
|
-
/**
|
|
318
|
-
* Client Secret of the auth provider.
|
|
319
|
-
*/
|
|
320
|
-
clientSecret: string;
|
|
321
|
-
/**
|
|
322
|
-
* Callback URL to be passed to the auth provider to redirect to after the user signs in.
|
|
323
|
-
*/
|
|
324
|
-
callbackUrl: string;
|
|
325
|
-
};
|
|
326
|
-
declare type OAuthResult = {
|
|
327
|
-
fullProfile: Profile;
|
|
328
|
-
params: {
|
|
329
|
-
id_token?: string;
|
|
330
|
-
scope: string;
|
|
331
|
-
expires_in: number;
|
|
332
|
-
};
|
|
333
|
-
accessToken: string;
|
|
334
|
-
refreshToken?: string;
|
|
335
|
-
};
|
|
336
|
-
declare type OAuthResponse = AuthResponse<OAuthProviderInfo>;
|
|
337
|
-
declare type OAuthProviderInfo = {
|
|
338
|
-
/**
|
|
339
|
-
* An access token issued for the signed in user.
|
|
340
|
-
*/
|
|
341
|
-
accessToken: string;
|
|
342
|
-
/**
|
|
343
|
-
* (Optional) Id token issued for the signed in user.
|
|
344
|
-
*/
|
|
345
|
-
idToken?: string;
|
|
346
|
-
/**
|
|
347
|
-
* Expiry of the access token in seconds.
|
|
348
|
-
*/
|
|
349
|
-
expiresInSeconds?: number;
|
|
350
|
-
/**
|
|
351
|
-
* Scopes granted for the access token.
|
|
352
|
-
*/
|
|
353
|
-
scope: string;
|
|
354
|
-
/**
|
|
355
|
-
* A refresh token issued for the signed in user
|
|
356
|
-
*/
|
|
357
|
-
refreshToken?: string;
|
|
358
|
-
};
|
|
359
|
-
declare type OAuthState = {
|
|
360
|
-
nonce: string;
|
|
361
|
-
env: string;
|
|
362
|
-
origin?: string;
|
|
363
|
-
};
|
|
364
|
-
declare type OAuthStartRequest = express.Request<{}> & {
|
|
365
|
-
scope: string;
|
|
366
|
-
state: OAuthState;
|
|
367
|
-
};
|
|
368
|
-
declare type OAuthRefreshRequest = express.Request<{}> & {
|
|
369
|
-
scope: string;
|
|
370
|
-
refreshToken: string;
|
|
371
|
-
};
|
|
372
|
-
/**
|
|
373
|
-
* Any OAuth provider needs to implement this interface which has provider specific
|
|
374
|
-
* handlers for different methods to perform authentication, get access tokens,
|
|
375
|
-
* refresh tokens and perform sign out.
|
|
376
|
-
*/
|
|
377
|
-
interface OAuthHandlers {
|
|
378
|
-
/**
|
|
379
|
-
* This method initiates a sign in request with an auth provider.
|
|
380
|
-
* @param {express.Request} req
|
|
381
|
-
* @param options
|
|
382
|
-
*/
|
|
383
|
-
start(req: OAuthStartRequest): Promise<RedirectInfo>;
|
|
384
|
-
/**
|
|
385
|
-
* Handles the redirect from the auth provider when the user has signed in.
|
|
386
|
-
* @param {express.Request} req
|
|
387
|
-
*/
|
|
388
|
-
handler(req: express.Request): Promise<{
|
|
389
|
-
response: AuthResponse<OAuthProviderInfo>;
|
|
390
|
-
refreshToken?: string;
|
|
391
|
-
}>;
|
|
392
|
-
/**
|
|
393
|
-
* (Optional) Given a refresh token and scope fetches a new access token from the auth provider.
|
|
394
|
-
* @param {string} refreshToken
|
|
395
|
-
* @param {string} scope
|
|
396
|
-
*/
|
|
397
|
-
refresh?(req: OAuthRefreshRequest): Promise<AuthResponse<OAuthProviderInfo>>;
|
|
398
|
-
/**
|
|
399
|
-
* (Optional) Sign out of the auth provider.
|
|
400
|
-
*/
|
|
401
|
-
logout?(): Promise<void>;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
407
|
declare type Options = {
|
|
405
408
|
providerId: string;
|
|
406
409
|
secure: boolean;
|
|
@@ -462,6 +465,23 @@ declare type GithubProviderOptions = {
|
|
|
462
465
|
*/
|
|
463
466
|
resolver?: SignInResolver<GithubOAuthResult>;
|
|
464
467
|
};
|
|
468
|
+
/**
|
|
469
|
+
* The state encoder used to encode the 'state' parameter on the OAuth request.
|
|
470
|
+
*
|
|
471
|
+
* It should return a string that takes the state params (from the request), url encodes the params
|
|
472
|
+
* and finally base64 encodes them.
|
|
473
|
+
*
|
|
474
|
+
* Providing your own stateEncoder will allow you to add addition parameters to the state field.
|
|
475
|
+
*
|
|
476
|
+
* It is typed as follows:
|
|
477
|
+
* export type StateEncoder = (input: OAuthState) => Promise<{encodedState: string}>;
|
|
478
|
+
*
|
|
479
|
+
* Note: the stateEncoder must encode a 'nonce' value and an 'env' value. Without this, the OAuth flow will fail
|
|
480
|
+
* (These two values will be set by the req.state by default)
|
|
481
|
+
*
|
|
482
|
+
* For more information, please see the helper module in ../../oauth/helpers #readState
|
|
483
|
+
*/
|
|
484
|
+
stateEncoder?: StateEncoder;
|
|
465
485
|
};
|
|
466
486
|
declare const createGithubProvider: (options?: GithubProviderOptions | undefined) => AuthProviderFactory;
|
|
467
487
|
|
|
@@ -594,6 +614,45 @@ declare type BitbucketProviderOptions = {
|
|
|
594
614
|
};
|
|
595
615
|
declare const createBitbucketProvider: (options?: BitbucketProviderOptions | undefined) => AuthProviderFactory;
|
|
596
616
|
|
|
617
|
+
declare type AtlassianAuthProviderOptions = OAuthProviderOptions & {
|
|
618
|
+
scopes: string;
|
|
619
|
+
signInResolver?: SignInResolver<OAuthResult>;
|
|
620
|
+
authHandler: AuthHandler<OAuthResult>;
|
|
621
|
+
tokenIssuer: TokenIssuer;
|
|
622
|
+
catalogIdentityClient: CatalogIdentityClient;
|
|
623
|
+
logger: Logger;
|
|
624
|
+
};
|
|
625
|
+
declare class AtlassianAuthProvider implements OAuthHandlers {
|
|
626
|
+
private readonly _strategy;
|
|
627
|
+
private readonly signInResolver?;
|
|
628
|
+
private readonly authHandler;
|
|
629
|
+
private readonly tokenIssuer;
|
|
630
|
+
private readonly catalogIdentityClient;
|
|
631
|
+
private readonly logger;
|
|
632
|
+
constructor(options: AtlassianAuthProviderOptions);
|
|
633
|
+
start(req: OAuthStartRequest): Promise<RedirectInfo>;
|
|
634
|
+
handler(req: express.Request): Promise<{
|
|
635
|
+
response: OAuthResponse;
|
|
636
|
+
refreshToken: string;
|
|
637
|
+
}>;
|
|
638
|
+
private handleResult;
|
|
639
|
+
refresh(req: OAuthRefreshRequest): Promise<OAuthResponse>;
|
|
640
|
+
}
|
|
641
|
+
declare type AtlassianProviderOptions = {
|
|
642
|
+
/**
|
|
643
|
+
* The profile transformation function used to verify and convert the auth response
|
|
644
|
+
* into the profile that will be presented to the user.
|
|
645
|
+
*/
|
|
646
|
+
authHandler?: AuthHandler<OAuthResult>;
|
|
647
|
+
/**
|
|
648
|
+
* Configure sign-in for this provider, without it the provider can not be used to sign users in.
|
|
649
|
+
*/
|
|
650
|
+
signIn?: {
|
|
651
|
+
resolver: SignInResolver<OAuthResult>;
|
|
652
|
+
};
|
|
653
|
+
};
|
|
654
|
+
declare const createAtlassianProvider: (options?: AtlassianProviderOptions | undefined) => AuthProviderFactory;
|
|
655
|
+
|
|
597
656
|
declare type AwsAlbResult = {
|
|
598
657
|
fullProfile: Profile;
|
|
599
658
|
expiresInSeconds?: number;
|
|
@@ -649,4 +708,4 @@ declare type WebMessageResponse = {
|
|
|
649
708
|
declare const postMessageResponse: (res: express.Response, appOrigin: string, response: WebMessageResponse) => void;
|
|
650
709
|
declare const ensuresXRequestedWith: (req: express.Request) => boolean;
|
|
651
710
|
|
|
652
|
-
export { 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, createAwsAlbProvider, createBitbucketProvider, createGithubProvider, createGitlabProvider, createGoogleProvider, createMicrosoftProvider, createOAuth2Provider, createOktaProvider, createOriginFilter, createRouter, factories as defaultAuthProviderFactories, encodeState, ensuresXRequestedWith, googleEmailSignInResolver, microsoftEmailSignInResolver, oktaEmailSignInResolver, postMessageResponse, readState, verifyNonce };
|
|
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 };
|
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.
|
|
4
|
+
"version": "0.4.8",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -30,12 +30,13 @@
|
|
|
30
30
|
"clean": "backstage-cli clean"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@backstage/backend-common": "^0.9.
|
|
34
|
-
"@backstage/catalog-client": "^0.5.
|
|
35
|
-
"@backstage/catalog-model": "^0.9.
|
|
36
|
-
"@backstage/config": "^0.1.
|
|
37
|
-
"@backstage/errors": "^0.1.
|
|
38
|
-
"@backstage/test-utils": "^0.1.
|
|
33
|
+
"@backstage/backend-common": "^0.9.10",
|
|
34
|
+
"@backstage/catalog-client": "^0.5.2",
|
|
35
|
+
"@backstage/catalog-model": "^0.9.7",
|
|
36
|
+
"@backstage/config": "^0.1.11",
|
|
37
|
+
"@backstage/errors": "^0.1.4",
|
|
38
|
+
"@backstage/test-utils": "^0.1.22",
|
|
39
|
+
"@google-cloud/firestore": "^4.15.1",
|
|
39
40
|
"@types/express": "^4.17.6",
|
|
40
41
|
"@types/passport": "^1.0.3",
|
|
41
42
|
"compression": "^1.7.4",
|
|
@@ -72,7 +73,7 @@
|
|
|
72
73
|
"yn": "^4.0.0"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
|
75
|
-
"@backstage/cli": "^0.
|
|
76
|
+
"@backstage/cli": "^0.9.0",
|
|
76
77
|
"@types/body-parser": "^1.19.0",
|
|
77
78
|
"@types/cookie-parser": "^1.4.2",
|
|
78
79
|
"@types/express-session": "^1.17.2",
|
|
@@ -83,7 +84,7 @@
|
|
|
83
84
|
"@types/passport-saml": "^1.1.3",
|
|
84
85
|
"@types/passport-strategy": "^0.2.35",
|
|
85
86
|
"@types/xml2js": "^0.4.7",
|
|
86
|
-
"msw": "^0.
|
|
87
|
+
"msw": "^0.35.0"
|
|
87
88
|
},
|
|
88
89
|
"files": [
|
|
89
90
|
"dist",
|
|
@@ -91,5 +92,5 @@
|
|
|
91
92
|
"config.d.ts"
|
|
92
93
|
],
|
|
93
94
|
"configSchema": "config.d.ts",
|
|
94
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "ddfdcd2b44dc9848cf550cea5346d5f9916a36d9"
|
|
95
96
|
}
|