Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose refreshTokens method #56

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/sdk/clients/browser/authcode-with-pkce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import type {
BrowserPKCEClientOptions,
} from '../types.js';

import type {
OAuth2CodeExchangeResponse,
} from '../../oauth2-flows/types.js';

const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => {
const { featureFlags, tokenClaims } = utilities;
const sessionManager = options.sessionManager ?? new BrowserSessionManager();
Expand Down Expand Up @@ -267,6 +271,15 @@ const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => {
const getToken = async (): Promise<string> => {
return await client.getToken(sessionManager);
};

/**
* Method makes user of the `refreshTokens` method of the `AuthCodeWithPKCE` client
* to use the refresh token to get new tokens
* @returns {Promise<OAuth2CodeExchangeResponse>}
*/
const refreshTokens = async (): Promise<OAuth2CodeExchangeResponse> => {
return await client.refreshTokens(sessionManager);
};

/**
* Method extracts the provided feature flag from the access token in the
Expand Down Expand Up @@ -314,6 +327,7 @@ const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => {
createOrg,
getClaim,
getToken,
refreshTokens,
register,
getUser,
getFlag,
Expand Down
15 changes: 15 additions & 0 deletions lib/sdk/clients/server/authorization-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import type {
ACClientOptions,
} from '../types.js';

import type {
OAuth2CodeExchangeResponse,
} from '../../oauth2-flows/types.js';

const createAuthorizationCodeClient = (
options: ACClientOptions,
isPKCE: boolean
Expand Down Expand Up @@ -133,6 +137,16 @@ const createAuthorizationCodeClient = (
return await client.getToken(sessionManager);
};

/**
* Method makes user of the `refreshTokens` method of the `AuthCodeAbstract` client
* to use the refresh token to get new tokens
* @param {SessionManager} sessionManager
* @returns {Promise<OAuth2CodeExchangeResponse>}
*/
const refreshTokens = async (sessionManager: SessionManager): Promise<OAuth2CodeExchangeResponse> => {
return await client.refreshTokens(sessionManager);
};

/**
* Method clears the current session and returns the logout URL, redirecting
* to which will clear the user's session on the authorization server.
Expand All @@ -151,6 +165,7 @@ const createAuthorizationCodeClient = (
getUserProfile,
createOrg,
getToken,
refreshTokens,
register,
getUser,
logout,
Expand Down
2 changes: 1 addition & 1 deletion lib/sdk/oauth2-flows/AuthCodeAbstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export abstract class AuthCodeAbstract {
* @param {SessionManager} sessionManager
* @returns {Promise<OAuth2CodeExchangeResponse>}
*/
protected abstract refreshTokens(
public abstract refreshTokens(
sessionManager: SessionManager
): Promise<OAuth2CodeExchangeResponse>;

Expand Down
2 changes: 1 addition & 1 deletion lib/sdk/oauth2-flows/AuthCodeWithPKCE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class AuthCodeWithPKCE extends AuthCodeAbstract {
* @param {SessionManager} sessionManager
* @returns {Promise<OAuth2CodeExchangeResponse>}
*/
protected async refreshTokens(
public async refreshTokens(
sessionManager: SessionManager
): Promise<OAuth2CodeExchangeResponse> {
const refreshToken = await utilities.getRefreshToken(sessionManager);
Expand Down
2 changes: 1 addition & 1 deletion lib/sdk/oauth2-flows/AuthorizationCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class AuthorizationCode extends AuthCodeAbstract {
* @param {SessionManager} sessionManager
* @returns {Promise<OAuth2CodeExchangeResponse>}
*/
protected async refreshTokens(
public async refreshTokens(
sessionManager: SessionManager
): Promise<OAuth2CodeExchangeResponse> {
const refreshToken = await utilities.getRefreshToken(sessionManager);
Expand Down
Loading