@oauth-spa-kit/core 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ export function toTokenSet(response) {
11
11
  scope: response.scope,
12
12
  };
13
13
  }
14
- async function postTokenOnce({ tokenEndpoint, params, dpopKeyPair, fetchImpl }, dpopNonce) {
14
+ async function postTokenOnce({ tokenEndpoint, buildParams, dpopKeyPair, fetchImpl }, dpopNonce) {
15
15
  const headers = {
16
16
  "Content-Type": "application/x-www-form-urlencoded",
17
17
  };
@@ -23,6 +23,7 @@ async function postTokenOnce({ tokenEndpoint, params, dpopKeyPair, fetchImpl },
23
23
  nonce: dpopNonce,
24
24
  });
25
25
  }
26
+ const params = await buildParams();
26
27
  const response = await fetchImpl(tokenEndpoint, { method: "POST", headers, body: params });
27
28
  const body = await response.json().catch(() => ({}));
28
29
  return { response, body };
@@ -51,19 +52,21 @@ async function postToken(args) {
51
52
  /** RFC 6749 section 4.1.3 -- authorization_code grant, PKCE-verified, private_key_jwt-authenticated. */
52
53
  export async function exchangeAuthorizationCode(args) {
53
54
  const fetchImpl = args.fetchImpl ?? fetch;
54
- const assertionParams = await buildClientAssertionParams(args.config.clientId, args.config.clientAuthentication, args.assertionAudience);
55
- const params = new URLSearchParams({
56
- grant_type: "authorization_code",
57
- client_id: args.config.clientId,
58
- code: args.code,
59
- redirect_uri: args.config.redirectUri,
60
- code_verifier: args.codeVerifier,
61
- ...assertionParams,
62
- });
55
+ const buildParams = async () => {
56
+ const assertionParams = await buildClientAssertionParams(args.config.clientId, args.config.clientAuthentication, args.assertionAudience);
57
+ return new URLSearchParams({
58
+ grant_type: "authorization_code",
59
+ client_id: args.config.clientId,
60
+ code: args.code,
61
+ redirect_uri: args.config.redirectUri,
62
+ code_verifier: args.codeVerifier,
63
+ ...assertionParams,
64
+ });
65
+ };
63
66
  const dpopKeyPair = args.config.dpop === false
64
67
  ? undefined
65
68
  : args.dpopKeyPair ?? await generateDpopKeyPair();
66
- const response = await postToken({ tokenEndpoint: args.tokenEndpoint, params, dpopKeyPair, fetchImpl });
69
+ const response = await postToken({ tokenEndpoint: args.tokenEndpoint, buildParams, dpopKeyPair, fetchImpl });
67
70
  return toTokenSet(response);
68
71
  }
69
72
  /**
@@ -81,17 +84,19 @@ export async function exchangeAuthorizationCode(args) {
81
84
  */
82
85
  export async function exchangeRefreshToken(args) {
83
86
  const fetchImpl = args.fetchImpl ?? fetch;
84
- const assertionParams = await buildClientAssertionParams(args.config.clientId, args.config.clientAuthentication, args.assertionAudience);
85
- const params = new URLSearchParams({
86
- grant_type: "refresh_token",
87
- client_id: args.config.clientId,
88
- refresh_token: args.refreshToken,
89
- ...assertionParams,
90
- });
87
+ const buildParams = async () => {
88
+ const assertionParams = await buildClientAssertionParams(args.config.clientId, args.config.clientAuthentication, args.assertionAudience);
89
+ return new URLSearchParams({
90
+ grant_type: "refresh_token",
91
+ client_id: args.config.clientId,
92
+ refresh_token: args.refreshToken,
93
+ ...assertionParams,
94
+ });
95
+ };
91
96
  const dpopKeyPair = args.config.dpop === false
92
97
  ? undefined
93
98
  : args.dpopKeyPair ?? await generateDpopKeyPair();
94
- const response = await postToken({ tokenEndpoint: args.tokenEndpoint, params, dpopKeyPair, fetchImpl });
99
+ const response = await postToken({ tokenEndpoint: args.tokenEndpoint, buildParams, dpopKeyPair, fetchImpl });
95
100
  const tokenSet = toTokenSet(response);
96
101
  // Some servers omit refresh_token on renewal, meaning "unchanged" -- carry the old one forward.
97
102
  if (!tokenSet.refreshToken)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oauth-spa-kit/core",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Framework- and runtime-agnostic OAuth 2.1 / OIDC primitives (PKCE, discovery, token exchange, DPoP) plus a fetch-based session client. Runs in the browser, Node, and edge runtimes -- no DOM or Node-only APIs.",
5
5
  "license": "MIT",
6
6
  "repository": {