@backstage/plugin-auth-backend 0.4.9 → 0.5.2
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 +52 -0
- package/dist/index.cjs.js +445 -328
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +152 -20
- package/package.json +8 -8
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
|
-
|
|
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:
|
|
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<
|
|
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<
|
|
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,9 +220,11 @@ 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(
|
|
223
|
+
resolveCatalogMembership(query: MemberClaimQuery): Promise<string[]>;
|
|
214
224
|
}
|
|
215
225
|
|
|
226
|
+
declare function getEntityClaims(entity: UserEntity): TokenParams['claims'];
|
|
227
|
+
|
|
216
228
|
declare type AuthProviderConfig = {
|
|
217
229
|
/**
|
|
218
230
|
* The protocol://domain[:port] where the app is hosted. This is used to construct the
|
|
@@ -314,37 +326,83 @@ declare type AuthProviderFactory = (options: AuthProviderFactoryOptions) => Auth
|
|
|
314
326
|
declare type AuthResponse<ProviderInfo> = {
|
|
315
327
|
providerInfo: ProviderInfo;
|
|
316
328
|
profile: ProfileInfo;
|
|
317
|
-
backstageIdentity?:
|
|
329
|
+
backstageIdentity?: BackstageIdentityResponse;
|
|
318
330
|
};
|
|
319
|
-
|
|
331
|
+
/**
|
|
332
|
+
* User identity information within Backstage.
|
|
333
|
+
*
|
|
334
|
+
* @public
|
|
335
|
+
*/
|
|
336
|
+
declare type BackstageUserIdentity = {
|
|
320
337
|
/**
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
* 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'.
|
|
324
340
|
*/
|
|
325
|
-
|
|
341
|
+
type: 'user';
|
|
326
342
|
/**
|
|
327
|
-
*
|
|
328
|
-
*
|
|
343
|
+
* The entityRef of the user in the catalog.
|
|
344
|
+
* For example User:default/sandra
|
|
329
345
|
*/
|
|
330
|
-
|
|
346
|
+
userEntityRef: string;
|
|
331
347
|
/**
|
|
332
|
-
* The
|
|
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
|
|
333
367
|
*/
|
|
334
|
-
|
|
368
|
+
id: string;
|
|
335
369
|
/**
|
|
336
370
|
* The entity that the user is represented by within Backstage.
|
|
337
371
|
*
|
|
338
372
|
* This entity may or may not exist within the Catalog, and it can be used
|
|
339
373
|
* to read and store additional metadata about the user.
|
|
374
|
+
*
|
|
375
|
+
* @deprecated Use the `identity` field instead.
|
|
340
376
|
*/
|
|
341
377
|
entity?: Entity;
|
|
342
|
-
|
|
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
|
+
}
|
|
343
399
|
/**
|
|
344
400
|
* Used to display login information to user, i.e. sidebar popup.
|
|
345
401
|
*
|
|
346
402
|
* It is also temporarily used as the profile of the signed-in user's Backstage
|
|
347
403
|
* identity, but we want to replace that with data from identity and/org catalog service
|
|
404
|
+
*
|
|
405
|
+
* @public
|
|
348
406
|
*/
|
|
349
407
|
declare type ProfileInfo = {
|
|
350
408
|
/**
|
|
@@ -361,6 +419,10 @@ declare type ProfileInfo = {
|
|
|
361
419
|
*/
|
|
362
420
|
picture?: string;
|
|
363
421
|
};
|
|
422
|
+
/**
|
|
423
|
+
* type of sign in information context, includes the profile information and authentication result which contains auth. related information
|
|
424
|
+
* @public
|
|
425
|
+
*/
|
|
364
426
|
declare type SignInInfo<AuthResult> = {
|
|
365
427
|
/**
|
|
366
428
|
* The simple profile passed down for use in the frontend.
|
|
@@ -371,11 +433,20 @@ declare type SignInInfo<AuthResult> = {
|
|
|
371
433
|
*/
|
|
372
434
|
result: AuthResult;
|
|
373
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
|
+
*/
|
|
374
441
|
declare type SignInResolver<AuthResult> = (info: SignInInfo<AuthResult>, context: {
|
|
375
442
|
tokenIssuer: TokenIssuer;
|
|
376
443
|
catalogIdentityClient: CatalogIdentityClient;
|
|
377
444
|
logger: Logger;
|
|
378
|
-
}) => Promise<
|
|
445
|
+
}) => Promise<BackstageSignInResult>;
|
|
446
|
+
/**
|
|
447
|
+
* The return type of authentication handler which must contain a valid profile information
|
|
448
|
+
* @public
|
|
449
|
+
*/
|
|
379
450
|
declare type AuthHandlerResult = {
|
|
380
451
|
profile: ProfileInfo;
|
|
381
452
|
};
|
|
@@ -386,6 +457,8 @@ declare type AuthHandlerResult = {
|
|
|
386
457
|
*
|
|
387
458
|
* Throwing an error in the function will cause the authentication to fail, making it
|
|
388
459
|
* possible to use this function as a way to limit access to a certain group of users.
|
|
460
|
+
*
|
|
461
|
+
* @public
|
|
389
462
|
*/
|
|
390
463
|
declare type AuthHandler<AuthResult> = (input: AuthResult) => Promise<AuthHandlerResult>;
|
|
391
464
|
declare type StateEncoder = (req: OAuthStartRequest) => Promise<{
|
|
@@ -552,6 +625,34 @@ declare type OAuth2ProviderOptions = {
|
|
|
552
625
|
};
|
|
553
626
|
declare const createOAuth2Provider: (options?: OAuth2ProviderOptions | undefined) => AuthProviderFactory;
|
|
554
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
|
+
|
|
555
656
|
declare const oktaEmailSignInResolver: SignInResolver<OAuthResult>;
|
|
556
657
|
declare type OktaProviderOptions = {
|
|
557
658
|
/**
|
|
@@ -676,10 +777,41 @@ declare type AwsAlbProviderOptions = {
|
|
|
676
777
|
};
|
|
677
778
|
declare const createAwsAlbProvider: (options?: AwsAlbProviderOptions | undefined) => AuthProviderFactory;
|
|
678
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
|
+
|
|
679
804
|
declare const factories: {
|
|
680
805
|
[providerId: string]: AuthProviderFactory;
|
|
681
806
|
};
|
|
682
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
|
+
|
|
683
815
|
declare type ProviderFactories = {
|
|
684
816
|
[s: string]: AuthProviderFactory;
|
|
685
817
|
};
|
|
@@ -690,7 +822,7 @@ interface RouterOptions {
|
|
|
690
822
|
discovery: PluginEndpointDiscovery;
|
|
691
823
|
providerFactories?: ProviderFactories;
|
|
692
824
|
}
|
|
693
|
-
declare function createRouter(
|
|
825
|
+
declare function createRouter(options: RouterOptions): Promise<express.Router>;
|
|
694
826
|
declare function createOriginFilter(config: Config): (origin: string) => boolean;
|
|
695
827
|
|
|
696
828
|
/**
|
|
@@ -708,4 +840,4 @@ declare type WebMessageResponse = {
|
|
|
708
840
|
declare const postMessageResponse: (res: express.Response, appOrigin: string, response: WebMessageResponse) => void;
|
|
709
841
|
declare const ensuresXRequestedWith: (req: express.Request) => boolean;
|
|
710
842
|
|
|
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 };
|
|
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.
|
|
4
|
+
"version": "0.5.2",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -30,19 +30,18 @@
|
|
|
30
30
|
"clean": "backstage-cli clean"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@backstage/backend-common": "^0.
|
|
34
|
-
"@backstage/catalog-client": "^0.5.
|
|
35
|
-
"@backstage/catalog-model": "^0.9.
|
|
33
|
+
"@backstage/backend-common": "^0.10.0",
|
|
34
|
+
"@backstage/catalog-client": "^0.5.3",
|
|
35
|
+
"@backstage/catalog-model": "^0.9.8",
|
|
36
36
|
"@backstage/config": "^0.1.11",
|
|
37
37
|
"@backstage/errors": "^0.1.5",
|
|
38
|
-
"@backstage/test-utils": "^0.
|
|
38
|
+
"@backstage/test-utils": "^0.2.0",
|
|
39
39
|
"@google-cloud/firestore": "^4.15.1",
|
|
40
40
|
"@types/express": "^4.17.6",
|
|
41
41
|
"@types/passport": "^1.0.3",
|
|
42
42
|
"compression": "^1.7.4",
|
|
43
43
|
"cookie-parser": "^1.4.5",
|
|
44
44
|
"cors": "^2.8.5",
|
|
45
|
-
"cross-fetch": "^3.0.6",
|
|
46
45
|
"express": "^4.17.1",
|
|
47
46
|
"express-promise-router": "^4.1.0",
|
|
48
47
|
"express-session": "^1.17.1",
|
|
@@ -57,6 +56,7 @@
|
|
|
57
56
|
"minimatch": "^3.0.3",
|
|
58
57
|
"morgan": "^1.10.0",
|
|
59
58
|
"node-cache": "^5.1.2",
|
|
59
|
+
"node-fetch": "^2.6.1",
|
|
60
60
|
"openid-client": "^4.2.1",
|
|
61
61
|
"passport": "^0.4.1",
|
|
62
62
|
"passport-bitbucket-oauth2": "^0.1.2",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"yn": "^4.0.0"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"@backstage/cli": "^0.
|
|
76
|
+
"@backstage/cli": "^0.10.3",
|
|
77
77
|
"@types/body-parser": "^1.19.0",
|
|
78
78
|
"@types/cookie-parser": "^1.4.2",
|
|
79
79
|
"@types/express-session": "^1.17.2",
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"config.d.ts"
|
|
93
93
|
],
|
|
94
94
|
"configSchema": "config.d.ts",
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "b315430f9dfcfa19ab0dd90f5b4ac6904938fba7"
|
|
96
96
|
}
|