release-2021-11-18 packages/core-app-api/src/apis/implementations/auth/*

Signed-off-by: Colton Padden <colton.padden@fastmail.com>
This commit is contained in:
Colton Padden
2021-12-15 13:52:11 -05:00
parent 0cad4e741f
commit cdf2c76a39
6 changed files with 48 additions and 46 deletions
+1
View File
@@ -4,3 +4,4 @@
- Remove deprecated `@backstage/core-app-api@createApp` which has been replaced by `@backstage/app-defaults#createApp`
- Remove deprecated type `BackstagePluginWithAnyOutput`
- Remove deprecated constructors for `GithubAuth`, `OAuth2`, and `SamlAuth` as the `create` method should be used instead
-11
View File
@@ -395,10 +395,6 @@ export type FlatRoutesProps = {
// @public
export class GithubAuth implements OAuthApi, SessionApi {
// Warning: (ae-forgotten-export) The symbol "SessionManager" needs to be exported by the entry point index.d.ts
//
// @deprecated
constructor(sessionManager: SessionManager<GithubSession>);
// (undocumented)
static create(options: OAuthApiCreateOptions): GithubAuth;
// (undocumented)
@@ -475,11 +471,6 @@ export class OAuth2
BackstageIdentityApi,
SessionApi
{
// @deprecated
constructor(options: {
sessionManager: SessionManager<OAuth2Session>;
scopeTransform: (scopes: string[]) => string[];
});
// (undocumented)
static create(options: OAuth2CreateOptions): OAuth2;
// (undocumented)
@@ -560,8 +551,6 @@ export type OneLoginAuthCreateOptions = {
export class SamlAuth
implements ProfileInfoApi, BackstageIdentityApi, SessionApi
{
// @deprecated
constructor(sessionManager: SessionManager<SamlSession>);
// (undocumented)
static create(options: AuthApiCreateOptions): SamlAuth;
// (undocumented)
@@ -118,10 +118,9 @@ export default class GithubAuth implements OAuthApi, SessionApi {
return new GithubAuth(sessionManagerMux);
}
/**
* @deprecated will be made private in the future. Use create method instead.
*/
constructor(private readonly sessionManager: SessionManager<GithubSession>) {}
private constructor(
private readonly sessionManager: SessionManager<GithubSession>,
) {}
async signIn() {
await this.getAccessToken();
@@ -15,6 +15,8 @@
*/
import OAuth2 from './OAuth2';
import MockOAuthApi from '../../OAuthRequestApi/MockOAuthApi';
import { UrlPatternDiscovery } from '../../DiscoveryApi';
const theFuture = new Date(Date.now() + 3600000);
const thePast = new Date(Date.now() - 10);
@@ -23,14 +25,24 @@ const PREFIX = 'https://www.googleapis.com/auth/';
const scopeTransform = (x: string[]) => x;
let getSession = jest.fn();
jest.mock('../../../../lib/AuthSessionManager', () => ({
...(jest.requireActual('../../../../lib/AuthSessionManager') as any),
RefreshingAuthSessionManager: class {
getSession = getSession;
},
}));
describe('OAuth2', () => {
it('should get refreshed access token', async () => {
const getSession = jest.fn().mockResolvedValue({
getSession = jest.fn().mockResolvedValue({
providerInfo: { accessToken: 'access-token', expiresAt: theFuture },
});
const oauth2 = new OAuth2({
sessionManager: { getSession } as any,
scopeTransform,
const oauth2 = OAuth2.create({
scopeTransform: scopeTransform,
oauthRequestApi: new MockOAuthApi(),
discoveryApi: UrlPatternDiscovery.compile('http://example.com'),
});
expect(await oauth2.getAccessToken('my-scope my-scope2')).toBe(
@@ -43,12 +55,13 @@ describe('OAuth2', () => {
});
it('should transform scopes', async () => {
const getSession = jest.fn().mockResolvedValue({
getSession = jest.fn().mockResolvedValue({
providerInfo: { accessToken: 'access-token', expiresAt: theFuture },
});
const oauth2 = new OAuth2({
sessionManager: { getSession } as any,
const oauth2 = OAuth2.create({
scopeTransform: scopes => scopes.map(scope => `my-prefix/${scope}`),
oauthRequestApi: new MockOAuthApi(),
discoveryApi: UrlPatternDiscovery.compile('http://example.com'),
});
expect(await oauth2.getAccessToken('my-scope')).toBe('access-token');
@@ -59,12 +72,13 @@ describe('OAuth2', () => {
});
it('should get refreshed id token', async () => {
const getSession = jest.fn().mockResolvedValue({
getSession = jest.fn().mockResolvedValue({
providerInfo: { idToken: 'id-token', expiresAt: theFuture },
});
const oauth2 = new OAuth2({
sessionManager: { getSession } as any,
scopeTransform,
const oauth2 = OAuth2.create({
scopeTransform: scopeTransform,
oauthRequestApi: new MockOAuthApi(),
discoveryApi: UrlPatternDiscovery.compile('http://example.com'),
});
expect(await oauth2.getIdToken()).toBe('id-token');
@@ -72,12 +86,13 @@ describe('OAuth2', () => {
});
it('should get optional id token', async () => {
const getSession = jest.fn().mockResolvedValue({
getSession = jest.fn().mockResolvedValue({
providerInfo: { idToken: 'id-token', expiresAt: theFuture },
});
const oauth2 = new OAuth2({
sessionManager: { getSession } as any,
scopeTransform,
const oauth2 = OAuth2.create({
scopeTransform: scopes => scopes.map(scope => `my-prefix/${scope}`),
oauthRequestApi: new MockOAuthApi(),
discoveryApi: UrlPatternDiscovery.compile('http://example.com'),
});
expect(await oauth2.getIdToken({ optional: true })).toBe('id-token');
@@ -87,7 +102,7 @@ describe('OAuth2', () => {
it('should share popup closed errors', async () => {
const error = new Error('NOPE');
error.name = 'RejectedError';
const getSession = jest
getSession = jest
.fn()
.mockResolvedValueOnce({
providerInfo: {
@@ -97,9 +112,10 @@ describe('OAuth2', () => {
},
})
.mockRejectedValue(error);
const oauth2 = new OAuth2({
sessionManager: { getSession } as any,
scopeTransform,
const oauth2 = OAuth2.create({
scopeTransform: scopes => scopes.map(scope => `my-prefix/${scope}`),
oauthRequestApi: new MockOAuthApi(),
discoveryApi: UrlPatternDiscovery.compile('http://example.com'),
});
// Make sure we have a session before we do the double request, so that we get past the !this.currentSession check
@@ -120,7 +136,7 @@ describe('OAuth2', () => {
scopes: new Set(),
},
};
const getSession = jest
getSession = jest
.fn()
.mockResolvedValueOnce(initialSession)
.mockResolvedValue({
@@ -130,9 +146,10 @@ describe('OAuth2', () => {
scopes: new Set(),
},
});
const oauth2 = new OAuth2({
sessionManager: { getSession } as any,
scopeTransform,
const oauth2 = OAuth2.create({
scopeTransform: scopes => scopes.map(scope => `my-prefix/${scope}`),
oauthRequestApi: new MockOAuthApi(),
discoveryApi: UrlPatternDiscovery.compile('http://example.com'),
});
// Grab the expired session first
@@ -120,10 +120,7 @@ export default class OAuth2
private readonly sessionManager: SessionManager<OAuth2Session>;
private readonly scopeTransform: (scopes: string[]) => string[];
/**
* @deprecated will be made private in the future. Use create method instead.
*/
constructor(options: {
private constructor(options: {
sessionManager: SessionManager<OAuth2Session>;
scopeTransform: (scopes: string[]) => string[];
}) {
@@ -81,10 +81,9 @@ export default class SamlAuth
return this.sessionManager.sessionState$();
}
/**
* @deprecated will be made private in the future. Use create method instead.
*/
constructor(private readonly sessionManager: SessionManager<SamlSession>) {}
private constructor(
private readonly sessionManager: SessionManager<SamlSession>,
) {}
async signIn() {
await this.getBackstageIdentity({});