diff --git a/packages/core-api/src/apis/definitions/auth.ts b/packages/core-api/src/apis/definitions/auth.ts index 076a7479d6..109f15b26e 100644 --- a/packages/core-api/src/apis/definitions/auth.ts +++ b/packages/core-api/src/apis/definitions/auth.ts @@ -92,20 +92,6 @@ export type OAuthApi = { ): Promise; }; -/** - * This API provides access to SAML 2 credentials. Verify user access with identity provider. - */ -export type SamlApi = { - getBackstageIdentity( - options?: AuthRequestOptions, - ): Promise; - - getProfile(options?: AuthRequestOptions): Promise; - - // Not sure if this is needed. - logout(): Promise; -}; - /** * This API provides access to OpenID Connect credentials. It lets you request ID tokens, * which can be passed to backend services to prove the user's identity. @@ -328,7 +314,9 @@ export const oauth2ApiRef = createApiRef< /** * Provides authentication for saml based identity providers */ -export const samlAuthApiRef = createApiRef({ +export const samlAuthApiRef = createApiRef< + ProfileInfoApi & BackstageIdentityApi & SessionApi +>({ id: 'core.auth.saml', description: 'Example of how to use SAML custom provider', }); diff --git a/packages/core-api/src/apis/implementations/auth/saml/SamlAuth.ts b/packages/core-api/src/apis/implementations/auth/saml/SamlAuth.ts index 2c8c98ecf6..433d3befe8 100644 --- a/packages/core-api/src/apis/implementations/auth/saml/SamlAuth.ts +++ b/packages/core-api/src/apis/implementations/auth/saml/SamlAuth.ts @@ -23,7 +23,9 @@ import { BackstageIdentity, SessionState, AuthRequestOptions, - SamlApi, + ProfileInfoApi, + BackstageIdentityApi, + SessionApi, } from '../../../definitions/auth'; import { AuthProvider, DiscoveryApi } from '../../../definitions'; import { SamlSession } from './types'; @@ -50,7 +52,7 @@ const DEFAULT_PROVIDER = { icon: SamlIcon, }; -class SamlAuth implements SamlApi { +class SamlAuth implements ProfileInfoApi, BackstageIdentityApi, SessionApi { static create({ discoveryApi, environment = 'development', @@ -80,6 +82,13 @@ class SamlAuth implements SamlApi { constructor(private readonly sessionManager: SessionManager) {} + async signIn() { + await this.getBackstageIdentity({}); + } + async signOut() { + await this.sessionManager.removeSession(); + } + async getBackstageIdentity( options: AuthRequestOptions, ): Promise { @@ -96,10 +105,6 @@ class SamlAuth implements SamlApi { const session = await this.sessionManager.getSession(options); return session?.profile; } - - async logout() { - await this.sessionManager.removeSession(); - } } export default SamlAuth;