feat(auth-backend): mark authHandler context as required parameter
Signed-off-by: Dominik Schwank <dominik.schwank@sda.se>
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
---
|
||||
'@backstage/plugin-auth-backend': patch
|
||||
'@backstage/plugin-auth-backend': minor
|
||||
---
|
||||
|
||||
Add new authentication provider: OAuth2Proxy
|
||||
Add new authentication provider to support the oauth2-proxy.
|
||||
|
||||
**BREAKING** The `AuthHandler` requires now an `AuthResolverContext` parameter. This aligns with the
|
||||
behavior of the `SignInResolver`.
|
||||
|
||||
@@ -59,17 +59,10 @@ export type Auth0ProviderOptions = {
|
||||
};
|
||||
};
|
||||
|
||||
// @public
|
||||
export type AuthContext = {
|
||||
tokenIssuer: TokenIssuer;
|
||||
catalogIdentityClient: CatalogIdentityClient;
|
||||
logger: Logger_2;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type AuthHandler<TAuthResult> = (
|
||||
input: TAuthResult,
|
||||
context?: AuthContext,
|
||||
context: AuthResolverContext,
|
||||
) => Promise<AuthHandlerResult>;
|
||||
|
||||
// @public
|
||||
@@ -107,6 +100,13 @@ export interface AuthProviderRouteHandlers {
|
||||
start(req: express.Request, res: express.Response): Promise<void>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type AuthResolverContext = {
|
||||
tokenIssuer: TokenIssuer;
|
||||
catalogIdentityClient: CatalogIdentityClient;
|
||||
logger: Logger_2;
|
||||
};
|
||||
|
||||
// Warning: (ae-missing-release-tag) "AuthResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
@@ -691,7 +691,7 @@ export type SignInInfo<TAuthResult> = {
|
||||
// @public
|
||||
export type SignInResolver<TAuthResult> = (
|
||||
info: SignInInfo<TAuthResult>,
|
||||
context: AuthContext,
|
||||
context: AuthResolverContext,
|
||||
) => Promise<BackstageSignInResult>;
|
||||
|
||||
// Warning: (ae-missing-release-tag) "TokenIssuer" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
|
||||
@@ -120,7 +120,12 @@ export class AtlassianAuthProvider implements OAuthHandlers {
|
||||
}
|
||||
|
||||
private async handleResult(result: OAuthResult): Promise<OAuthResponse> {
|
||||
const { profile } = await this.authHandler(result);
|
||||
const context = {
|
||||
logger: this.logger,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
};
|
||||
const { profile } = await this.authHandler(result, context);
|
||||
|
||||
const response: OAuthResponse = {
|
||||
providerInfo: {
|
||||
@@ -138,11 +143,7 @@ export class AtlassianAuthProvider implements OAuthHandlers {
|
||||
result,
|
||||
profile,
|
||||
},
|
||||
{
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
logger: this.logger,
|
||||
},
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,12 @@ export class Auth0AuthProvider implements OAuthHandlers {
|
||||
}
|
||||
|
||||
private async handleResult(result: OAuthResult) {
|
||||
const { profile } = await this.authHandler(result);
|
||||
const context = {
|
||||
logger: this.logger,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
};
|
||||
const { profile } = await this.authHandler(result, context);
|
||||
|
||||
const response: OAuthResponse = {
|
||||
providerInfo: {
|
||||
@@ -167,11 +172,7 @@ export class Auth0AuthProvider implements OAuthHandlers {
|
||||
result,
|
||||
profile,
|
||||
},
|
||||
{
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
logger: this.logger,
|
||||
},
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -182,17 +182,18 @@ export class AwsAlbAuthProvider implements AuthProviderRouteHandlers {
|
||||
}
|
||||
|
||||
private async handleResult(result: AwsAlbResult): Promise<AwsAlbResponse> {
|
||||
const { profile } = await this.authHandler(result);
|
||||
const context = {
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
logger: this.logger,
|
||||
};
|
||||
const { profile } = await this.authHandler(result, context);
|
||||
const backstageIdentity = await this.signInResolver(
|
||||
{
|
||||
result,
|
||||
profile,
|
||||
},
|
||||
{
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
logger: this.logger,
|
||||
},
|
||||
context,
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -174,7 +174,12 @@ export class BitbucketAuthProvider implements OAuthHandlers {
|
||||
private async handleResult(result: BitbucketOAuthResult) {
|
||||
result.fullProfile.avatarUrl =
|
||||
result.fullProfile._json!.links!.avatar!.href;
|
||||
const { profile } = await this.authHandler(result);
|
||||
const context = {
|
||||
logger: this.logger,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
};
|
||||
const { profile } = await this.authHandler(result, context);
|
||||
|
||||
const response: OAuthResponse = {
|
||||
providerInfo: {
|
||||
@@ -192,11 +197,7 @@ export class BitbucketAuthProvider implements OAuthHandlers {
|
||||
result,
|
||||
profile,
|
||||
},
|
||||
{
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
logger: this.logger,
|
||||
},
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,16 +71,17 @@ export class GcpIapProvider implements AuthProviderRouteHandlers {
|
||||
req.header(IAP_JWT_HEADER),
|
||||
this.tokenValidator,
|
||||
);
|
||||
const context = {
|
||||
logger: this.logger,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
};
|
||||
|
||||
const { profile } = await this.authHandler(result);
|
||||
const { profile } = await this.authHandler(result, context);
|
||||
|
||||
const backstageIdentity = await this.signInResolver(
|
||||
{ profile, result },
|
||||
{
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
logger: this.logger,
|
||||
},
|
||||
context,
|
||||
);
|
||||
|
||||
const response: GcpIapResponse = {
|
||||
|
||||
@@ -152,7 +152,12 @@ export class GithubAuthProvider implements OAuthHandlers {
|
||||
}
|
||||
|
||||
private async handleResult(result: GithubOAuthResult) {
|
||||
const { profile } = await this.authHandler(result);
|
||||
const context = {
|
||||
logger: this.logger,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
};
|
||||
const { profile } = await this.authHandler(result, context);
|
||||
|
||||
const expiresInStr = result.params.expires_in;
|
||||
const response: OAuthResponse = {
|
||||
@@ -171,11 +176,7 @@ export class GithubAuthProvider implements OAuthHandlers {
|
||||
result,
|
||||
profile,
|
||||
},
|
||||
{
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
logger: this.logger,
|
||||
},
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -167,7 +167,12 @@ export class GitlabAuthProvider implements OAuthHandlers {
|
||||
}
|
||||
|
||||
private async handleResult(result: OAuthResult): Promise<OAuthResponse> {
|
||||
const { profile } = await this.authHandler(result);
|
||||
const context = {
|
||||
logger: this.logger,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
};
|
||||
const { profile } = await this.authHandler(result, context);
|
||||
|
||||
const response: OAuthResponse = {
|
||||
providerInfo: {
|
||||
@@ -185,11 +190,7 @@ export class GitlabAuthProvider implements OAuthHandlers {
|
||||
result,
|
||||
profile,
|
||||
},
|
||||
{
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
logger: this.logger,
|
||||
},
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,12 @@ export class GoogleAuthProvider implements OAuthHandlers {
|
||||
}
|
||||
|
||||
private async handleResult(result: OAuthResult) {
|
||||
const { profile } = await this.authHandler(result);
|
||||
const context = {
|
||||
logger: this.logger,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
};
|
||||
const { profile } = await this.authHandler(result, context);
|
||||
|
||||
const response: OAuthResponse = {
|
||||
providerInfo: {
|
||||
@@ -166,11 +171,7 @@ export class GoogleAuthProvider implements OAuthHandlers {
|
||||
result,
|
||||
profile,
|
||||
},
|
||||
{
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
logger: this.logger,
|
||||
},
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ export type {
|
||||
AuthProviderFactoryOptions,
|
||||
AuthProviderFactory,
|
||||
AuthHandler,
|
||||
AuthContext,
|
||||
AuthResolverContext,
|
||||
AuthHandlerResult,
|
||||
SignInResolver,
|
||||
SignInInfo,
|
||||
|
||||
@@ -143,7 +143,12 @@ export class MicrosoftAuthProvider implements OAuthHandlers {
|
||||
const photo = await this.getUserPhoto(result.accessToken);
|
||||
result.fullProfile.photos = photo ? [{ value: photo }] : undefined;
|
||||
|
||||
const { profile } = await this.authHandler(result);
|
||||
const context = {
|
||||
logger: this.logger,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
};
|
||||
const { profile } = await this.authHandler(result, context);
|
||||
|
||||
const response: OAuthResponse = {
|
||||
providerInfo: {
|
||||
@@ -161,11 +166,7 @@ export class MicrosoftAuthProvider implements OAuthHandlers {
|
||||
result,
|
||||
profile,
|
||||
},
|
||||
{
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
logger: this.logger,
|
||||
},
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +163,12 @@ export class OAuth2AuthProvider implements OAuthHandlers {
|
||||
}
|
||||
|
||||
private async handleResult(result: OAuthResult) {
|
||||
const { profile } = await this.authHandler(result);
|
||||
const context = {
|
||||
logger: this.logger,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
};
|
||||
const { profile } = await this.authHandler(result, context);
|
||||
|
||||
const response: OAuthResponse = {
|
||||
providerInfo: {
|
||||
@@ -181,11 +186,7 @@ export class OAuth2AuthProvider implements OAuthHandlers {
|
||||
result,
|
||||
profile,
|
||||
},
|
||||
{
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
logger: this.logger,
|
||||
},
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +182,12 @@ export class OidcAuthProvider implements OAuthHandlers {
|
||||
// Use this function to grab the user profile info from the token
|
||||
// Then populate the profile with it
|
||||
private async handleResult(result: OidcAuthResult): Promise<OAuthResponse> {
|
||||
const { profile } = await this.authHandler(result);
|
||||
const context = {
|
||||
logger: this.logger,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
};
|
||||
const { profile } = await this.authHandler(result, context);
|
||||
const response: OAuthResponse = {
|
||||
providerInfo: {
|
||||
idToken: result.tokenset.id_token,
|
||||
@@ -198,11 +203,7 @@ export class OidcAuthProvider implements OAuthHandlers {
|
||||
result,
|
||||
profile,
|
||||
},
|
||||
{
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
logger: this.logger,
|
||||
},
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,12 @@ export class OktaAuthProvider implements OAuthHandlers {
|
||||
}
|
||||
|
||||
private async handleResult(result: OAuthResult) {
|
||||
const { profile } = await this._authHandler(result);
|
||||
const context = {
|
||||
logger: this._logger,
|
||||
catalogIdentityClient: this._catalogIdentityClient,
|
||||
tokenIssuer: this._tokenIssuer,
|
||||
};
|
||||
const { profile } = await this._authHandler(result, context);
|
||||
|
||||
const response: OAuthResponse = {
|
||||
providerInfo: {
|
||||
@@ -187,11 +192,7 @@ export class OktaAuthProvider implements OAuthHandlers {
|
||||
result,
|
||||
profile,
|
||||
},
|
||||
{
|
||||
tokenIssuer: this._tokenIssuer,
|
||||
catalogIdentityClient: this._catalogIdentityClient,
|
||||
logger: this._logger,
|
||||
},
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,12 @@ export class OneLoginProvider implements OAuthHandlers {
|
||||
}
|
||||
|
||||
private async handleResult(result: OAuthResult) {
|
||||
const { profile } = await this.authHandler(result);
|
||||
const context = {
|
||||
logger: this.logger,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
};
|
||||
const { profile } = await this.authHandler(result, context);
|
||||
|
||||
const response: OAuthResponse = {
|
||||
providerInfo: {
|
||||
@@ -166,11 +171,7 @@ export class OneLoginProvider implements OAuthHandlers {
|
||||
result,
|
||||
profile,
|
||||
},
|
||||
{
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
logger: this.logger,
|
||||
},
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,12 +93,18 @@ export class SamlAuthProvider implements AuthProviderRouteHandlers {
|
||||
res: express.Response,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const context = {
|
||||
logger: this.logger,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
};
|
||||
|
||||
const { result } = await executeFrameHandlerStrategy<SamlAuthResult>(
|
||||
req,
|
||||
this.strategy,
|
||||
);
|
||||
|
||||
const { profile } = await this.authHandler(result);
|
||||
const { profile } = await this.authHandler(result, context);
|
||||
|
||||
const response: AuthResponse<{}> = {
|
||||
profile,
|
||||
@@ -111,11 +117,7 @@ export class SamlAuthProvider implements AuthProviderRouteHandlers {
|
||||
result,
|
||||
profile,
|
||||
},
|
||||
{
|
||||
tokenIssuer: this.tokenIssuer,
|
||||
catalogIdentityClient: this.catalogIdentityClient,
|
||||
logger: this.logger,
|
||||
},
|
||||
context,
|
||||
);
|
||||
|
||||
response.backstageIdentity =
|
||||
|
||||
@@ -29,7 +29,7 @@ import { CatalogIdentityClient } from '../lib/catalog';
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type AuthContext = {
|
||||
export type AuthResolverContext = {
|
||||
tokenIssuer: TokenIssuer;
|
||||
catalogIdentityClient: CatalogIdentityClient;
|
||||
logger: Logger;
|
||||
@@ -270,7 +270,7 @@ export type SignInInfo<TAuthResult> = {
|
||||
*/
|
||||
export type SignInResolver<TAuthResult> = (
|
||||
info: SignInInfo<TAuthResult>,
|
||||
context: AuthContext,
|
||||
context: AuthResolverContext,
|
||||
) => Promise<BackstageSignInResult>;
|
||||
|
||||
/**
|
||||
@@ -296,7 +296,7 @@ export type AuthHandlerResult = { profile: ProfileInfo };
|
||||
*/
|
||||
export type AuthHandler<TAuthResult> = (
|
||||
input: TAuthResult,
|
||||
context?: AuthContext,
|
||||
context: AuthResolverContext,
|
||||
) => Promise<AuthHandlerResult>;
|
||||
|
||||
export type StateEncoder = (
|
||||
|
||||
Reference in New Issue
Block a user