auth: simplify types and reintroduce deprecated BackstageIdentity

Co-authored-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: blam <ben@blam.sh>
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-12-06 11:55:42 +01:00
parent e847694fbb
commit 73c73b71d1
7 changed files with 50 additions and 26 deletions
+20 -10
View File
@@ -116,13 +116,24 @@ export type AwsAlbProviderOptions = {
};
};
// @public @deprecated
export type BackstageIdentity = BackstageSignInResult;
// @public
export type BackstageIdentityResponse = {
id: string;
entity?: Entity;
token: string;
export interface BackstageIdentityResponse extends BackstageSignInResult {
identity: BackstageUserIdentity;
};
}
// Warning: (ae-missing-release-tag) "BackstageSignInResult" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface BackstageSignInResult {
// @deprecated
entity?: Entity;
// @deprecated
id: string;
token: string;
}
// @public
export type BackstageUserIdentity = {
@@ -504,11 +515,10 @@ export type OAuthRefreshRequest = express.Request<{}> & {
// Warning: (ae-missing-release-tag) "OAuthResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export type OAuthResponse = Omit<
AuthResponse<OAuthProviderInfo>,
'backstageIdentity'
> & {
backstageIdentity?: Omit<BackstageIdentityResponse, 'identity'>;
export type OAuthResponse = {
profile: ProfileInfo;
providerInfo: OAuthProviderInfo;
backstageIdentity?: BackstageSignInResult;
};
// Warning: (ae-missing-release-tag) "OAuthResult" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
@@ -21,6 +21,7 @@ import {
AuthProviderRouteHandlers,
AuthProviderConfig,
BackstageIdentityResponse,
BackstageSignInResult,
} from '../../providers/types';
import {
AuthenticationError,
@@ -232,7 +233,7 @@ export class OAuthAdapter implements AuthProviderRouteHandlers {
* make sure it's populated with all the information we can derive from the user ID.
*/
private async populateIdentity(
identity?: Omit<BackstageIdentityResponse, 'identity'>,
identity?: BackstageSignInResult,
): Promise<BackstageIdentityResponse | undefined> {
if (!identity) {
return undefined;
+7 -7
View File
@@ -17,10 +17,11 @@
import express from 'express';
import { Profile as PassportProfile } from 'passport';
import {
AuthResponse,
RedirectInfo,
BackstageIdentityResponse,
BackstageSignInResult,
ProfileInfo,
} from '../../providers/types';
/**
* Common options for passport.js-based OAuth providers
*/
@@ -50,11 +51,10 @@ export type OAuthResult = {
refreshToken?: string;
};
export type OAuthResponse = Omit<
AuthResponse<OAuthProviderInfo>,
'backstageIdentity'
> & {
backstageIdentity?: Omit<BackstageIdentityResponse, 'identity'>;
export type OAuthResponse = {
profile: ProfileInfo;
providerInfo: OAuthProviderInfo;
backstageIdentity?: BackstageSignInResult;
};
export type OAuthProviderInfo = {
@@ -40,8 +40,10 @@ export type {
// to the frontend
export type {
AuthResponse,
BackstageIdentity,
BackstageUserIdentity,
BackstageIdentityResponse,
BackstageSignInResult,
ProfileInfo,
} from './types';
+16 -7
View File
@@ -164,11 +164,7 @@ export type BackstageUserIdentity = {
ownershipEntityRefs: string[];
};
/**
* Response object containing the {@link BackstageUserIdentity} and the token from the authentication provider.
* @public
*/
export type BackstageIdentityResponse = {
export interface BackstageSignInResult {
/**
* An opaque ID that uniquely identifies the user within Backstage.
*
@@ -192,12 +188,25 @@ export type BackstageIdentityResponse = {
* The token used to authenticate the user within Backstage.
*/
token: string;
}
/**
* The old exported symbol for {@link BackstageSignInResult}.
* @public
* @deprecated Use the `BackstageSignInResult` type instead.
*/
export type BackstageIdentity = BackstageSignInResult;
/**
* Response object containing the {@link BackstageUserIdentity} and the token from the authentication provider.
* @public
*/
export interface BackstageIdentityResponse extends BackstageSignInResult {
/**
* A plaintext description of the identity that is encapsulated within the token.
*/
identity: BackstageUserIdentity;
};
}
/**
* Used to display login information to user, i.e. sidebar popup.
@@ -242,7 +251,7 @@ export type SignInResolver<AuthResult> = (
catalogIdentityClient: CatalogIdentityClient;
logger: Logger;
},
) => Promise<Omit<BackstageIdentityResponse, 'identity'>>;
) => Promise<BackstageSignInResult>;
export type AuthHandlerResult = { profile: ProfileInfo };