Skip to content

Commit 68fd6bc

Browse files
authored
Merge pull request #56 from kinde-oss/peter/feat-expose-refreshTokens-method
feat: expose refreshTokens method
2 parents 5e27c7f + a20b84b commit 68fd6bc

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

lib/sdk/clients/browser/authcode-with-pkce.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import type {
1616
BrowserPKCEClientOptions,
1717
} from '../types.js';
1818

19+
import type {
20+
OAuth2CodeExchangeResponse,
21+
} from '../../oauth2-flows/types.js';
22+
1923
const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => {
2024
const { featureFlags, tokenClaims } = utilities;
2125
const sessionManager = options.sessionManager ?? new BrowserSessionManager();
@@ -267,6 +271,15 @@ const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => {
267271
const getToken = async (): Promise<string> => {
268272
return await client.getToken(sessionManager);
269273
};
274+
275+
/**
276+
* Method makes user of the `refreshTokens` method of the `AuthCodeWithPKCE` client
277+
* to use the refresh token to get new tokens
278+
* @returns {Promise<OAuth2CodeExchangeResponse>}
279+
*/
280+
const refreshTokens = async (): Promise<OAuth2CodeExchangeResponse> => {
281+
return await client.refreshTokens(sessionManager);
282+
};
270283

271284
/**
272285
* Method extracts the provided feature flag from the access token in the
@@ -314,6 +327,7 @@ const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => {
314327
createOrg,
315328
getClaim,
316329
getToken,
330+
refreshTokens,
317331
register,
318332
getUser,
319333
getFlag,

lib/sdk/clients/server/authorization-code.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import type {
1111
ACClientOptions,
1212
} from '../types.js';
1313

14+
import type {
15+
OAuth2CodeExchangeResponse,
16+
} from '../../oauth2-flows/types.js';
17+
1418
const createAuthorizationCodeClient = (
1519
options: ACClientOptions,
1620
isPKCE: boolean
@@ -133,6 +137,16 @@ const createAuthorizationCodeClient = (
133137
return await client.getToken(sessionManager);
134138
};
135139

140+
/**
141+
* Method makes user of the `refreshTokens` method of the `AuthCodeAbstract` client
142+
* to use the refresh token to get new tokens
143+
* @param {SessionManager} sessionManager
144+
* @returns {Promise<OAuth2CodeExchangeResponse>}
145+
*/
146+
const refreshTokens = async (sessionManager: SessionManager): Promise<OAuth2CodeExchangeResponse> => {
147+
return await client.refreshTokens(sessionManager);
148+
};
149+
136150
/**
137151
* Method clears the current session and returns the logout URL, redirecting
138152
* to which will clear the user's session on the authorization server.
@@ -151,6 +165,7 @@ const createAuthorizationCodeClient = (
151165
getUserProfile,
152166
createOrg,
153167
getToken,
168+
refreshTokens,
154169
register,
155170
getUser,
156171
logout,

lib/sdk/oauth2-flows/AuthCodeAbstract.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export abstract class AuthCodeAbstract {
7575
* @param {SessionManager} sessionManager
7676
* @returns {Promise<OAuth2CodeExchangeResponse>}
7777
*/
78-
protected abstract refreshTokens(
78+
public abstract refreshTokens(
7979
sessionManager: SessionManager
8080
): Promise<OAuth2CodeExchangeResponse>;
8181

lib/sdk/oauth2-flows/AuthCodeWithPKCE.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class AuthCodeWithPKCE extends AuthCodeAbstract {
7171
* @param {SessionManager} sessionManager
7272
* @returns {Promise<OAuth2CodeExchangeResponse>}
7373
*/
74-
protected async refreshTokens(
74+
public async refreshTokens(
7575
sessionManager: SessionManager
7676
): Promise<OAuth2CodeExchangeResponse> {
7777
const refreshToken = await utilities.getRefreshToken(sessionManager);

lib/sdk/oauth2-flows/AuthorizationCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class AuthorizationCode extends AuthCodeAbstract {
5656
* @param {SessionManager} sessionManager
5757
* @returns {Promise<OAuth2CodeExchangeResponse>}
5858
*/
59-
protected async refreshTokens(
59+
public async refreshTokens(
6060
sessionManager: SessionManager
6161
): Promise<OAuth2CodeExchangeResponse> {
6262
const refreshToken = await utilities.getRefreshToken(sessionManager);

0 commit comments

Comments
 (0)