diff --git a/.changeset/metal-crabs-wash.md b/.changeset/metal-crabs-wash.md new file mode 100644 index 0000000000..6ecb50ef67 --- /dev/null +++ b/.changeset/metal-crabs-wash.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-auth-backend': minor +--- + +Renamed the `RedirectInfo` type to `OAuthStartResponse` diff --git a/plugins/auth-backend/api-report.md b/plugins/auth-backend/api-report.md index be295f65f5..43bf2f3fa2 100644 --- a/plugins/auth-backend/api-report.md +++ b/plugins/auth-backend/api-report.md @@ -317,7 +317,7 @@ export interface OAuthHandlers { response: OAuthResponse; refreshToken?: string; }>; - start(req: OAuthStartRequest): Promise; + start(req: OAuthStartRequest): Promise; } // @public (undocumented) @@ -366,6 +366,12 @@ export type OAuthStartRequest = express.Request<{}> & { state: OAuthState; }; +// @public (undocumented) +export type OAuthStartResponse = { + url: string; + status?: number; +}; + // @public (undocumented) export type OAuthState = { nonce: string; @@ -654,12 +660,6 @@ export const providers: Readonly<{ // @public (undocumented) export const readState: (stateString: string) => OAuthState; -// @public (undocumented) -export type RedirectInfo = { - url: string; - status?: number; -}; - // @public (undocumented) export interface RouterOptions { // (undocumented) diff --git a/plugins/auth-backend/src/lib/oauth/types.ts b/plugins/auth-backend/src/lib/oauth/types.ts index bfe0aaff50..e8b5282aad 100644 --- a/plugins/auth-backend/src/lib/oauth/types.ts +++ b/plugins/auth-backend/src/lib/oauth/types.ts @@ -17,7 +17,7 @@ import express from 'express'; import { Profile as PassportProfile } from 'passport'; import { BackstageSignInResult } from '@backstage/plugin-auth-node'; -import { RedirectInfo, ProfileInfo } from '../../providers/types'; +import { OAuthStartResponse, ProfileInfo } from '../../providers/types'; /** * Common options for passport.js-based OAuth providers @@ -115,7 +115,7 @@ export interface OAuthHandlers { /** * Initiate a sign in request with an auth provider. */ - start(req: OAuthStartRequest): Promise; + start(req: OAuthStartRequest): Promise; /** * Handle the redirect from the auth provider when the user has signed in. diff --git a/plugins/auth-backend/src/lib/passport/PassportStrategyHelper.test.ts b/plugins/auth-backend/src/lib/passport/PassportStrategyHelper.test.ts index 893be26852..660b96f018 100644 --- a/plugins/auth-backend/src/lib/passport/PassportStrategyHelper.test.ts +++ b/plugins/auth-backend/src/lib/passport/PassportStrategyHelper.test.ts @@ -33,7 +33,7 @@ describe('PassportStrategyHelper', () => { } describe('executeRedirectStrategy', () => { - it('should call authenticate and resolve with RedirectInfo', async () => { + it('should call authenticate and resolve with OAuthStartResponse', async () => { const mockStrategy = new MyCustomRedirectStrategy(); const spyAuthenticate = jest.spyOn(mockStrategy, 'authenticate'); const redirectStrategyPromise = executeRedirectStrategy( diff --git a/plugins/auth-backend/src/lib/passport/PassportStrategyHelper.ts b/plugins/auth-backend/src/lib/passport/PassportStrategyHelper.ts index 6117736e21..16377f17f2 100644 --- a/plugins/auth-backend/src/lib/passport/PassportStrategyHelper.ts +++ b/plugins/auth-backend/src/lib/passport/PassportStrategyHelper.ts @@ -20,7 +20,7 @@ import jwtDecoder from 'jwt-decode'; import { InternalOAuthError } from 'passport-oauth2'; import { PassportProfile } from './types'; -import { ProfileInfo, RedirectInfo } from '../../providers/types'; +import { ProfileInfo, OAuthStartResponse } from '../../providers/types'; export type PassportDoneCallback = ( err?: Error, @@ -77,7 +77,7 @@ export const executeRedirectStrategy = async ( req: express.Request, providerStrategy: passport.Strategy, options: Record, -): Promise => { +): Promise => { return new Promise(resolve => { const strategy = Object.create(providerStrategy); strategy.redirect = (url: string, status?: number) => { diff --git a/plugins/auth-backend/src/providers/atlassian/provider.ts b/plugins/auth-backend/src/providers/atlassian/provider.ts index eb6890a5a4..e02d899fb1 100644 --- a/plugins/auth-backend/src/providers/atlassian/provider.ts +++ b/plugins/auth-backend/src/providers/atlassian/provider.ts @@ -38,7 +38,7 @@ import { import { AuthHandler, AuthResolverContext, - RedirectInfo, + OAuthStartResponse, SignInResolver, } from '../types'; import express from 'express'; @@ -94,7 +94,7 @@ export class AtlassianAuthProvider implements OAuthHandlers { ); } - async start(req: OAuthStartRequest): Promise { + async start(req: OAuthStartRequest): Promise { return await executeRedirectStrategy(req, this._strategy, { state: encodeState(req.state), }); diff --git a/plugins/auth-backend/src/providers/auth0/provider.ts b/plugins/auth-backend/src/providers/auth0/provider.ts index a53f504f50..8e0255ebe6 100644 --- a/plugins/auth-backend/src/providers/auth0/provider.ts +++ b/plugins/auth-backend/src/providers/auth0/provider.ts @@ -37,7 +37,7 @@ import { PassportDoneCallback, } from '../../lib/passport'; import { - RedirectInfo, + OAuthStartResponse, AuthHandler, SignInResolver, AuthResolverContext, @@ -98,7 +98,7 @@ export class Auth0AuthProvider implements OAuthHandlers { ); } - async start(req: OAuthStartRequest): Promise { + async start(req: OAuthStartRequest): Promise { return await executeRedirectStrategy(req, this._strategy, { accessType: 'offline', prompt: 'consent', diff --git a/plugins/auth-backend/src/providers/bitbucket/provider.ts b/plugins/auth-backend/src/providers/bitbucket/provider.ts index 0bbebd2097..cfa30e9a73 100644 --- a/plugins/auth-backend/src/providers/bitbucket/provider.ts +++ b/plugins/auth-backend/src/providers/bitbucket/provider.ts @@ -39,7 +39,7 @@ import { import { createAuthProviderIntegration } from '../createAuthProviderIntegration'; import { AuthHandler, - RedirectInfo, + OAuthStartResponse, SignInResolver, AuthResolverContext, } from '../types'; @@ -121,7 +121,7 @@ export class BitbucketAuthProvider implements OAuthHandlers { ); } - async start(req: OAuthStartRequest): Promise { + async start(req: OAuthStartRequest): Promise { return await executeRedirectStrategy(req, this._strategy, { accessType: 'offline', prompt: 'consent', diff --git a/plugins/auth-backend/src/providers/github/provider.ts b/plugins/auth-backend/src/providers/github/provider.ts index 4ac91516a3..7571b4a327 100644 --- a/plugins/auth-backend/src/providers/github/provider.ts +++ b/plugins/auth-backend/src/providers/github/provider.ts @@ -26,7 +26,7 @@ import { PassportDoneCallback, } from '../../lib/passport'; import { - RedirectInfo, + OAuthStartResponse, AuthHandler, SignInResolver, StateEncoder, @@ -107,7 +107,7 @@ export class GithubAuthProvider implements OAuthHandlers { ); } - async start(req: OAuthStartRequest): Promise { + async start(req: OAuthStartRequest): Promise { return await executeRedirectStrategy(req, this._strategy, { scope: req.scope, state: (await this.stateEncoder(req)).encodedState, diff --git a/plugins/auth-backend/src/providers/gitlab/provider.ts b/plugins/auth-backend/src/providers/gitlab/provider.ts index c24c2e128d..7f5489d391 100644 --- a/plugins/auth-backend/src/providers/gitlab/provider.ts +++ b/plugins/auth-backend/src/providers/gitlab/provider.ts @@ -25,7 +25,7 @@ import { PassportDoneCallback, } from '../../lib/passport'; import { - RedirectInfo, + OAuthStartResponse, SignInResolver, AuthHandler, AuthResolverContext, @@ -110,7 +110,7 @@ export class GitlabAuthProvider implements OAuthHandlers { ); } - async start(req: OAuthStartRequest): Promise { + async start(req: OAuthStartRequest): Promise { return await executeRedirectStrategy(req, this._strategy, { scope: req.scope, state: encodeState(req.state), diff --git a/plugins/auth-backend/src/providers/google/provider.ts b/plugins/auth-backend/src/providers/google/provider.ts index f60d4e9947..7689cd1a3a 100644 --- a/plugins/auth-backend/src/providers/google/provider.ts +++ b/plugins/auth-backend/src/providers/google/provider.ts @@ -39,7 +39,7 @@ import { import { AuthHandler, AuthResolverContext, - RedirectInfo, + OAuthStartResponse, SignInResolver, } from '../types'; import { createAuthProviderIntegration } from '../createAuthProviderIntegration'; @@ -98,7 +98,7 @@ export class GoogleAuthProvider implements OAuthHandlers { ); } - async start(req: OAuthStartRequest): Promise { + async start(req: OAuthStartRequest): Promise { return await executeRedirectStrategy(req, this.strategy, { accessType: 'offline', prompt: 'consent', diff --git a/plugins/auth-backend/src/providers/index.ts b/plugins/auth-backend/src/providers/index.ts index e0860d3f78..67d3a62990 100644 --- a/plugins/auth-backend/src/providers/index.ts +++ b/plugins/auth-backend/src/providers/index.ts @@ -49,7 +49,7 @@ export type { StateEncoder, AuthResponse, ProfileInfo, - RedirectInfo, + OAuthStartResponse, } from './types'; export { prepareBackstageIdentityResponse } from './prepareBackstageIdentityResponse'; diff --git a/plugins/auth-backend/src/providers/microsoft/provider.ts b/plugins/auth-backend/src/providers/microsoft/provider.ts index db79dba225..fd2a1529a7 100644 --- a/plugins/auth-backend/src/providers/microsoft/provider.ts +++ b/plugins/auth-backend/src/providers/microsoft/provider.ts @@ -38,7 +38,7 @@ import { } from '../../lib/passport'; import { AuthHandler, - RedirectInfo, + OAuthStartResponse, SignInResolver, AuthResolverContext, } from '../types'; @@ -97,7 +97,7 @@ export class MicrosoftAuthProvider implements OAuthHandlers { ); } - async start(req: OAuthStartRequest): Promise { + async start(req: OAuthStartRequest): Promise { return await executeRedirectStrategy(req, this._strategy, { scope: req.scope, state: encodeState(req.state), diff --git a/plugins/auth-backend/src/providers/oauth2/provider.ts b/plugins/auth-backend/src/providers/oauth2/provider.ts index 6fa649c421..3e7720b14a 100644 --- a/plugins/auth-backend/src/providers/oauth2/provider.ts +++ b/plugins/auth-backend/src/providers/oauth2/provider.ts @@ -39,7 +39,7 @@ import { import { AuthHandler, AuthResolverContext, - RedirectInfo, + OAuthStartResponse, SignInResolver, } from '../types'; import { createAuthProviderIntegration } from '../createAuthProviderIntegration'; @@ -114,7 +114,7 @@ export class OAuth2AuthProvider implements OAuthHandlers { ); } - async start(req: OAuthStartRequest): Promise { + async start(req: OAuthStartRequest): Promise { return await executeRedirectStrategy(req, this._strategy, { accessType: 'offline', prompt: 'consent', diff --git a/plugins/auth-backend/src/providers/oidc/provider.ts b/plugins/auth-backend/src/providers/oidc/provider.ts index eb963a3711..bce8ba843b 100644 --- a/plugins/auth-backend/src/providers/oidc/provider.ts +++ b/plugins/auth-backend/src/providers/oidc/provider.ts @@ -40,7 +40,7 @@ import { import { AuthHandler, AuthResolverContext, - RedirectInfo, + OAuthStartResponse, SignInResolver, } from '../types'; import { createAuthProviderIntegration } from '../createAuthProviderIntegration'; @@ -91,7 +91,7 @@ export class OidcAuthProvider implements OAuthHandlers { this.resolverContext = options.resolverContext; } - async start(req: OAuthStartRequest): Promise { + async start(req: OAuthStartRequest): Promise { const { strategy } = await this.implementation; const options: Record = { scope: req.scope || this.scope || 'openid profile email', diff --git a/plugins/auth-backend/src/providers/okta/provider.ts b/plugins/auth-backend/src/providers/okta/provider.ts index cb686f17e9..05e0451bdb 100644 --- a/plugins/auth-backend/src/providers/okta/provider.ts +++ b/plugins/auth-backend/src/providers/okta/provider.ts @@ -38,7 +38,7 @@ import { } from '../../lib/passport'; import { AuthHandler, - RedirectInfo, + OAuthStartResponse, SignInResolver, AuthResolverContext, } from '../types'; @@ -125,7 +125,7 @@ export class OktaAuthProvider implements OAuthHandlers { ); } - async start(req: OAuthStartRequest): Promise { + async start(req: OAuthStartRequest): Promise { return await executeRedirectStrategy(req, this.strategy, { accessType: 'offline', prompt: 'consent', diff --git a/plugins/auth-backend/src/providers/onelogin/provider.ts b/plugins/auth-backend/src/providers/onelogin/provider.ts index 59b57b3851..ac636f92cc 100644 --- a/plugins/auth-backend/src/providers/onelogin/provider.ts +++ b/plugins/auth-backend/src/providers/onelogin/provider.ts @@ -37,7 +37,7 @@ import { PassportDoneCallback, } from '../../lib/passport'; import { - RedirectInfo, + OAuthStartResponse, AuthHandler, SignInResolver, AuthResolverContext, @@ -95,7 +95,7 @@ export class OneLoginProvider implements OAuthHandlers { }, ); } - async start(req: OAuthStartRequest): Promise { + async start(req: OAuthStartRequest): Promise { return await executeRedirectStrategy(req, this._strategy, { accessType: 'offline', prompt: 'consent', diff --git a/plugins/auth-backend/src/providers/types.ts b/plugins/auth-backend/src/providers/types.ts index f0f94f1936..574afade79 100644 --- a/plugins/auth-backend/src/providers/types.ts +++ b/plugins/auth-backend/src/providers/types.ts @@ -127,7 +127,7 @@ export type AuthProviderConfig = { }; /** @public */ -export type RedirectInfo = { +export type OAuthStartResponse = { /** * URL to redirect to */