Skip to content

Commit 33306ee

Browse files
authored
Merge pull request #67 from Yoshify/feat/optional-commit-on-refresh
feat: allow the ability to refreshTokens without also committing them to the session
2 parents 5a6cdb2 + eac6309 commit 33306ee

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

lib/sdk/oauth2-flows/AuthCodeAbstract.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ export abstract class AuthCodeAbstract {
8888
* Abstract method will implement logic in child classes for refreshing access token
8989
* using refresh token available in current session.
9090
* @param {SessionManager} sessionManager
91+
* @param {boolean} [commitToSession=true] - Optional parameter, determines whether to commit the refreshed tokens to the session. Defaults to true.
9192
* @returns {Promise<OAuth2CodeExchangeResponse>}
9293
*/
9394
public abstract refreshTokens(
94-
sessionManager: SessionManager
95+
sessionManager: SessionManager,
96+
commitToSession?: boolean
9597
): Promise<OAuth2CodeExchangeResponse>;
9698

9799
/**

lib/sdk/oauth2-flows/AuthCodeWithPKCE.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ export class AuthCodeWithPKCE extends AuthCodeAbstract {
6969
* `AuthCodeAbstract` parent class, see corresponding comment in parent class for
7070
* further explanation.
7171
* @param {SessionManager} sessionManager
72+
* @param {boolean} [commitToSession=true] - Optional parameter, determines whether to commit the refreshed tokens to the session. Defaults to true.
7273
* @returns {Promise<OAuth2CodeExchangeResponse>}
7374
*/
7475
public async refreshTokens(
75-
sessionManager: SessionManager
76+
sessionManager: SessionManager,
77+
commitToSession: boolean = true
7678
): Promise<OAuth2CodeExchangeResponse> {
7779
const refreshToken = await utilities.getRefreshToken(sessionManager);
7880
const body = new URLSearchParams({
@@ -82,11 +84,13 @@ export class AuthCodeWithPKCE extends AuthCodeAbstract {
8284
});
8385

8486
const tokens = await this.fetchTokensFor(sessionManager, body, true);
85-
await utilities.commitTokensToSession(
86-
sessionManager,
87-
tokens,
88-
this.tokenValidationDetails
89-
);
87+
if (commitToSession) {
88+
await utilities.commitTokensToSession(
89+
sessionManager,
90+
tokens,
91+
this.tokenValidationDetails
92+
);
93+
}
9094
return tokens;
9195
}
9296

lib/sdk/oauth2-flows/AuthorizationCode.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ export class AuthorizationCode extends AuthCodeAbstract {
5454
* `AuthCodeAbstract` parent class, see corresponding comment in parent class for
5555
* further explanation.
5656
* @param {SessionManager} sessionManager
57+
* @param {boolean} [commitToSession=true] - Optional parameter, determines whether to commit the refreshed tokens to the session. Defaults to true.
5758
* @returns {Promise<OAuth2CodeExchangeResponse>}
5859
*/
5960
public async refreshTokens(
60-
sessionManager: SessionManager
61+
sessionManager: SessionManager,
62+
commitToSession: boolean = true
6163
): Promise<OAuth2CodeExchangeResponse> {
6264
const refreshToken = await utilities.getRefreshToken(sessionManager);
6365

@@ -73,11 +75,13 @@ export class AuthorizationCode extends AuthCodeAbstract {
7375
});
7476

7577
const tokens = await this.fetchTokensFor(sessionManager, body);
76-
await utilities.commitTokensToSession(
77-
sessionManager,
78-
tokens,
79-
this.tokenValidationDetails
80-
);
78+
if (commitToSession) {
79+
await utilities.commitTokensToSession(
80+
sessionManager,
81+
tokens,
82+
this.tokenValidationDetails
83+
);
84+
}
8185
return tokens;
8286
}
8387

0 commit comments

Comments
 (0)