refactor to use sessionApi
This commit is contained in:
@@ -92,20 +92,6 @@ export type OAuthApi = {
|
||||
): Promise<string>;
|
||||
};
|
||||
|
||||
/**
|
||||
* This API provides access to SAML 2 credentials. Verify user access with identity provider.
|
||||
*/
|
||||
export type SamlApi = {
|
||||
getBackstageIdentity(
|
||||
options?: AuthRequestOptions,
|
||||
): Promise<BackstageIdentity | undefined>;
|
||||
|
||||
getProfile(options?: AuthRequestOptions): Promise<ProfileInfo | undefined>;
|
||||
|
||||
// Not sure if this is needed.
|
||||
logout(): Promise<void>;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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<SamlApi>({
|
||||
export const samlAuthApiRef = createApiRef<
|
||||
ProfileInfoApi & BackstageIdentityApi & SessionApi
|
||||
>({
|
||||
id: 'core.auth.saml',
|
||||
description: 'Example of how to use SAML custom provider',
|
||||
});
|
||||
|
||||
@@ -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<SamlSession>) {}
|
||||
|
||||
async signIn() {
|
||||
await this.getBackstageIdentity({});
|
||||
}
|
||||
async signOut() {
|
||||
await this.sessionManager.removeSession();
|
||||
}
|
||||
|
||||
async getBackstageIdentity(
|
||||
options: AuthRequestOptions,
|
||||
): Promise<BackstageIdentity | undefined> {
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user