packages/core: stick to naming convention of using "scopes" for set of scopes
This commit is contained in:
@@ -99,7 +99,7 @@ class GoogleAuth implements OAuthApi, OpenIdConnectApi {
|
||||
const normalizedScopes = GoogleAuth.normalizeScopes(scope);
|
||||
const session = await this.sessionManager.getSession({
|
||||
optional: false,
|
||||
scope: normalizedScopes,
|
||||
scopes: normalizedScopes,
|
||||
});
|
||||
return session.accessToken;
|
||||
}
|
||||
|
||||
+8
-8
@@ -51,13 +51,13 @@ describe('RefreshingAuthSessionManager', () => {
|
||||
scopes: new Set(['a']),
|
||||
expired: false,
|
||||
});
|
||||
await manager.getSession({ scope: new Set(['a']) });
|
||||
await manager.getSession({ scopes: new Set(['a']) });
|
||||
expect(createSession).toBeCalledTimes(1);
|
||||
|
||||
await manager.getSession({ scope: new Set(['a']) });
|
||||
await manager.getSession({ scopes: new Set(['a']) });
|
||||
expect(createSession).toBeCalledTimes(1);
|
||||
|
||||
await manager.getSession({ scope: new Set(['b']) });
|
||||
await manager.getSession({ scopes: new Set(['b']) });
|
||||
expect(createSession).toBeCalledTimes(2);
|
||||
});
|
||||
|
||||
@@ -77,11 +77,11 @@ describe('RefreshingAuthSessionManager', () => {
|
||||
expired: true,
|
||||
});
|
||||
|
||||
await manager.getSession({ scope: new Set(['a']) });
|
||||
await manager.getSession({ scopes: new Set(['a']) });
|
||||
expect(createSession).toBeCalledTimes(1);
|
||||
expect(refreshSession).toBeCalledTimes(1);
|
||||
|
||||
await manager.getSession({ scope: new Set(['a']) });
|
||||
await manager.getSession({ scopes: new Set(['a']) });
|
||||
expect(createSession).toBeCalledTimes(1);
|
||||
expect(refreshSession).toBeCalledTimes(2);
|
||||
});
|
||||
@@ -95,9 +95,9 @@ describe('RefreshingAuthSessionManager', () => {
|
||||
} as any);
|
||||
|
||||
createSession.mockRejectedValueOnce(new Error('some error'));
|
||||
await expect(manager.getSession({ scope: new Set(['a']) })).rejects.toThrow(
|
||||
'some error',
|
||||
);
|
||||
await expect(
|
||||
manager.getSession({ scopes: new Set(['a']) }),
|
||||
).rejects.toThrow('some error');
|
||||
});
|
||||
|
||||
it('should not get optional session', async () => {
|
||||
|
||||
+8
-8
@@ -70,17 +70,17 @@ export class RefreshingAuthSessionManager<AuthSession>
|
||||
|
||||
async getSession(options: {
|
||||
optional: false;
|
||||
scope?: Set<string>;
|
||||
scopes?: Set<string>;
|
||||
}): Promise<AuthSession>;
|
||||
async getSession(options: {
|
||||
optional?: boolean;
|
||||
scope?: Set<string>;
|
||||
scopes?: Set<string>;
|
||||
}): Promise<AuthSession | undefined>;
|
||||
async getSession(options: {
|
||||
optional?: boolean;
|
||||
scope?: Set<string>;
|
||||
scopes?: Set<string>;
|
||||
}): Promise<AuthSession | undefined> {
|
||||
if (this.sessionExistsAndHasScope(this.currentSession, options.scope)) {
|
||||
if (this.sessionExistsAndHasScope(this.currentSession, options.scopes)) {
|
||||
const shouldRefresh = this.sessionShouldRefreshFunc(this.currentSession!);
|
||||
if (!shouldRefresh) {
|
||||
return this.currentSession!;
|
||||
@@ -122,7 +122,7 @@ export class RefreshingAuthSessionManager<AuthSession>
|
||||
|
||||
// We can call authRequester multiple times, the returned session will contain all requested scopes.
|
||||
this.currentSession = await this.connector.createSession(
|
||||
this.getExtendedScope(options.scope),
|
||||
this.getExtendedScope(options.scopes),
|
||||
);
|
||||
return this.currentSession;
|
||||
}
|
||||
@@ -134,16 +134,16 @@ export class RefreshingAuthSessionManager<AuthSession>
|
||||
|
||||
private sessionExistsAndHasScope(
|
||||
session: AuthSession | undefined,
|
||||
scope?: Set<string>,
|
||||
scopes?: Set<string>,
|
||||
): boolean {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
if (!scope) {
|
||||
if (!scopes) {
|
||||
return true;
|
||||
}
|
||||
const sessionScopes = this.sessionScopesFunc(session);
|
||||
return hasScopes(sessionScopes, scope);
|
||||
return hasScopes(sessionScopes, scopes);
|
||||
}
|
||||
|
||||
private getExtendedScope(scopes?: Set<string>) {
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
export type SessionManager<AuthSession> = {
|
||||
getSession(options: {
|
||||
optional: false;
|
||||
scope?: Set<string>;
|
||||
scopes?: Set<string>;
|
||||
}): Promise<AuthSession>;
|
||||
getSession(options: {
|
||||
optional?: boolean;
|
||||
scope?: Set<string>;
|
||||
scopes?: Set<string>;
|
||||
}): Promise<AuthSession | undefined>;
|
||||
|
||||
removeSession(): Promise<void>;
|
||||
|
||||
Reference in New Issue
Block a user