@mitumba/sdk 5.10.0 → 5.12.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.mjs CHANGED
@@ -733,18 +733,23 @@ var OAuthModule = class {
733
733
  );
734
734
  }
735
735
  /**
736
- * Exchange a one-time authorization code for a token pair.
736
+ * Exchange a one-time authorization code for tokens.
737
737
  *
738
738
  * The relying party calls this server-to-server (or from its own origin) with the PKCE verifier
739
739
  * that matches the earlier challenge. The authorization code is single-use — a reused, expired,
740
- * or tampered code is rejected with `400 invalid_grant`. On success the returned tokens are
741
- * persisted into the client session via `setSession`, so the relying party is logged in
742
- * immediately after the exchange. `grant_type` is set to `'authorization_code'` by the SDK.
740
+ * or tampered code is rejected with `400 invalid_grant`. `grant_type` is set to
741
+ * `'authorization_code'` by the SDK.
742
+ *
743
+ * When the result is a Mitumba session (it carries a `refresh_token`, as for the Mitumba
744
+ * marketplace), the tokens are persisted into the client session via `setSession`, so the caller
745
+ * is signed in immediately. Any other relying party receives an access token addressed only to
746
+ * itself and no refresh token; that result is returned untouched and the client session is left
747
+ * as it was, because such a token cannot call Mitumba's APIs or be refreshed.
743
748
  *
744
749
  * @param input - The token exchange request (code, redirect URI, client, PKCE verifier, optional secret)
745
750
  * @param options - Optional per-request options (abort signal, extra headers)
746
- * @returns The access/refresh token pair and granted scope
747
- * @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code) or `401 invalid_client` (wrong secret)
751
+ * @returns The access token, granted scope, and either a refresh token (Mitumba session) or an id_token (relying party)
752
+ * @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code or withdrawn consent), `401 invalid_client` (wrong secret), or `503 temporarily_unavailable` (token signing unavailable)
748
753
  *
749
754
  * @example
750
755
  * ```typescript
@@ -763,10 +768,12 @@ var OAuthModule = class {
763
768
  { ...input, grant_type: "authorization_code" },
764
769
  options
765
770
  );
766
- await this.client.setSession({
767
- access_token: result.access_token,
768
- refresh_token: result.refresh_token
769
- });
771
+ if (result.refresh_token) {
772
+ await this.client.setSession({
773
+ access_token: result.access_token,
774
+ refresh_token: result.refresh_token
775
+ });
776
+ }
770
777
  return result;
771
778
  }
772
779
  /**
@@ -795,13 +802,17 @@ var OAuthModule = class {
795
802
  return this.client.get("/auth/oauth/jwks.json", void 0, options);
796
803
  }
797
804
  /**
798
- * Fetch the userinfo claim set for the current session.
805
+ * Fetch the userinfo claim set.
799
806
  *
800
- * Returns `sub` plus the identity claims the session's granted scopes allow. Requires an
801
- * authenticated session — the SDK attaches the bearer token automatically.
807
+ * Returns `sub` plus the identity claims the token's granted scopes allow. With a Mitumba session
808
+ * the SDK attaches the session's bearer token automatically. A relying party, whose client holds no
809
+ * Mitumba session (`exchangeCode()` does not set one for it), passes its own access token explicitly:
810
+ * `sdk.oauth.userinfo({ headers: { Authorization: `Bearer ${tokens.access_token}` } })`. A custom
811
+ * `Authorization` header never replaces an active session's token.
802
812
  *
803
813
  * @param options - Optional per-request options (abort signal, extra headers)
804
814
  * @returns The userinfo claims
815
+ * @throws {APIError} On `401` with no token, or `401 invalid_token` for a token that is expired, revoked, or no longer consented
805
816
  */
806
817
  async userinfo(options) {
807
818
  return this.client.get("/auth/oauth/userinfo", void 0, options);