@corvushold/guard-sdk 0.16.0 → 0.17.0

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.
package/dist/index.cjs CHANGED
@@ -279,7 +279,7 @@ var HttpClient = class {
279
279
 
280
280
  // package.json
281
281
  var package_default = {
282
- version: "0.16.0"};
282
+ version: "0.17.0"};
283
283
 
284
284
  // src/client.ts
285
285
  function isTenantSelectionRequired(data) {
@@ -1103,6 +1103,47 @@ var GuardClient = class {
1103
1103
  async getOAuth2Metadata() {
1104
1104
  return this.request("/.well-known/oauth-authorization-server", { method: "GET" });
1105
1105
  }
1106
+ /**
1107
+ * Exchange an OAuth2 authorization code for tokens (Authorization Code + PKCE).
1108
+ */
1109
+ async exchangeOAuth2Code(input) {
1110
+ const code = input.code?.trim();
1111
+ const clientID = input.client_id?.trim();
1112
+ const redirectURI = input.redirect_uri?.trim();
1113
+ const codeVerifier = input.code_verifier?.trim();
1114
+ if (!code) throw new Error("code is required");
1115
+ if (!clientID) throw new Error("client_id is required");
1116
+ if (!redirectURI) throw new Error("redirect_uri is required");
1117
+ if (!codeVerifier) throw new Error("code_verifier is required");
1118
+ const body = new URLSearchParams();
1119
+ body.set("grant_type", "authorization_code");
1120
+ body.set("code", code);
1121
+ body.set("client_id", clientID);
1122
+ body.set("redirect_uri", redirectURI);
1123
+ body.set("code_verifier", codeVerifier);
1124
+ const res = await this.request("/oauth/token", {
1125
+ method: "POST",
1126
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
1127
+ body: body.toString()
1128
+ });
1129
+ if (res.meta.status >= 200 && res.meta.status < 300) this.persistTokensFrom(res.data);
1130
+ return res;
1131
+ }
1132
+ /**
1133
+ * Revoke an OAuth2 token (RFC7009). Server returns 200 for unknown tokens as well.
1134
+ */
1135
+ async revokeOAuth2Token(input) {
1136
+ const token = input.token?.trim();
1137
+ if (!token) throw new Error("token is required");
1138
+ const body = new URLSearchParams();
1139
+ body.set("token", token);
1140
+ if (input.token_type_hint) body.set("token_type_hint", input.token_type_hint);
1141
+ return this.request("/oauth/revoke", {
1142
+ method: "POST",
1143
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
1144
+ body: body.toString()
1145
+ });
1146
+ }
1106
1147
  /**
1107
1148
  * Static helper to discover OAuth2 metadata from any Guard API base URL.
1108
1149
  * Useful for auto-configuration before creating a GuardClient instance.