@mitumba/sdk 5.11.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.d.mts CHANGED
@@ -1442,13 +1442,24 @@ interface OAuthTokenExchangeInput {
1442
1442
  client_secret?: string;
1443
1443
  }
1444
1444
  /**
1445
- * Result of a successful token exchange: the access/refresh token pair and its metadata.
1445
+ * Result of a successful token exchange.
1446
+ *
1447
+ * What a client receives depends on its registration:
1448
+ *
1449
+ * - **The Mitumba marketplace** receives a Mitumba session: `access_token` plus `refresh_token`.
1450
+ * - **Every other relying party** receives an access token addressed only to itself (its `aud` is the
1451
+ * client's `client_id`), limited to the consented `scope`, plus an `id_token`. There is **no**
1452
+ * `refresh_token`: renew by repeating the authorization flow (silently with `prompt=none` where the
1453
+ * client is permitted). Verify both tokens against the published JWKS (`getJwks()`). The access
1454
+ * token is not accepted by Mitumba's APIs, only by `userinfo()` and the relying party's own API.
1446
1455
  */
1447
1456
  interface OAuthTokenResult {
1448
1457
  /** The access token (JWT) for authenticated requests. */
1449
1458
  access_token: string;
1450
- /** The refresh token used to rotate the access token. */
1451
- refresh_token: string;
1459
+ /** The refresh token used to rotate the access token. Present only for a Mitumba session. */
1460
+ refresh_token?: string;
1461
+ /** The OpenID Connect ID token (ES256). Always present for a relying party. */
1462
+ id_token?: string;
1452
1463
  /** Lifetime of the access token in seconds. */
1453
1464
  expires_in: number;
1454
1465
  /** Always `'Bearer'`. */
@@ -3169,18 +3180,23 @@ declare class OAuthModule {
3169
3180
  */
3170
3181
  authorize(input: OAuthAuthorizeInput, options?: RequestOptions): Promise<OAuthAuthorizeResult | OAuthConsentRequired>;
3171
3182
  /**
3172
- * Exchange a one-time authorization code for a token pair.
3183
+ * Exchange a one-time authorization code for tokens.
3173
3184
  *
3174
3185
  * The relying party calls this server-to-server (or from its own origin) with the PKCE verifier
3175
3186
  * that matches the earlier challenge. The authorization code is single-use — a reused, expired,
3176
- * or tampered code is rejected with `400 invalid_grant`. On success the returned tokens are
3177
- * persisted into the client session via `setSession`, so the relying party is logged in
3178
- * immediately after the exchange. `grant_type` is set to `'authorization_code'` by the SDK.
3187
+ * or tampered code is rejected with `400 invalid_grant`. `grant_type` is set to
3188
+ * `'authorization_code'` by the SDK.
3189
+ *
3190
+ * When the result is a Mitumba session (it carries a `refresh_token`, as for the Mitumba
3191
+ * marketplace), the tokens are persisted into the client session via `setSession`, so the caller
3192
+ * is signed in immediately. Any other relying party receives an access token addressed only to
3193
+ * itself and no refresh token; that result is returned untouched and the client session is left
3194
+ * as it was, because such a token cannot call Mitumba's APIs or be refreshed.
3179
3195
  *
3180
3196
  * @param input - The token exchange request (code, redirect URI, client, PKCE verifier, optional secret)
3181
3197
  * @param options - Optional per-request options (abort signal, extra headers)
3182
- * @returns The access/refresh token pair and granted scope
3183
- * @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code) or `401 invalid_client` (wrong secret)
3198
+ * @returns The access token, granted scope, and either a refresh token (Mitumba session) or an id_token (relying party)
3199
+ * @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)
3184
3200
  *
3185
3201
  * @example
3186
3202
  * ```typescript
@@ -3216,13 +3232,17 @@ declare class OAuthModule {
3216
3232
  */
3217
3233
  getJwks(options?: RequestOptions): Promise<Jwks>;
3218
3234
  /**
3219
- * Fetch the userinfo claim set for the current session.
3235
+ * Fetch the userinfo claim set.
3220
3236
  *
3221
- * Returns `sub` plus the identity claims the session's granted scopes allow. Requires an
3222
- * authenticated session — the SDK attaches the bearer token automatically.
3237
+ * Returns `sub` plus the identity claims the token's granted scopes allow. With a Mitumba session
3238
+ * the SDK attaches the session's bearer token automatically. A relying party, whose client holds no
3239
+ * Mitumba session (`exchangeCode()` does not set one for it), passes its own access token explicitly:
3240
+ * `sdk.oauth.userinfo({ headers: { Authorization: `Bearer ${tokens.access_token}` } })`. A custom
3241
+ * `Authorization` header never replaces an active session's token.
3223
3242
  *
3224
3243
  * @param options - Optional per-request options (abort signal, extra headers)
3225
3244
  * @returns The userinfo claims
3245
+ * @throws {APIError} On `401` with no token, or `401 invalid_token` for a token that is expired, revoked, or no longer consented
3226
3246
  */
3227
3247
  userinfo(options?: RequestOptions): Promise<UserInfo>;
3228
3248
  /**
package/dist/index.d.ts CHANGED
@@ -1442,13 +1442,24 @@ interface OAuthTokenExchangeInput {
1442
1442
  client_secret?: string;
1443
1443
  }
1444
1444
  /**
1445
- * Result of a successful token exchange: the access/refresh token pair and its metadata.
1445
+ * Result of a successful token exchange.
1446
+ *
1447
+ * What a client receives depends on its registration:
1448
+ *
1449
+ * - **The Mitumba marketplace** receives a Mitumba session: `access_token` plus `refresh_token`.
1450
+ * - **Every other relying party** receives an access token addressed only to itself (its `aud` is the
1451
+ * client's `client_id`), limited to the consented `scope`, plus an `id_token`. There is **no**
1452
+ * `refresh_token`: renew by repeating the authorization flow (silently with `prompt=none` where the
1453
+ * client is permitted). Verify both tokens against the published JWKS (`getJwks()`). The access
1454
+ * token is not accepted by Mitumba's APIs, only by `userinfo()` and the relying party's own API.
1446
1455
  */
1447
1456
  interface OAuthTokenResult {
1448
1457
  /** The access token (JWT) for authenticated requests. */
1449
1458
  access_token: string;
1450
- /** The refresh token used to rotate the access token. */
1451
- refresh_token: string;
1459
+ /** The refresh token used to rotate the access token. Present only for a Mitumba session. */
1460
+ refresh_token?: string;
1461
+ /** The OpenID Connect ID token (ES256). Always present for a relying party. */
1462
+ id_token?: string;
1452
1463
  /** Lifetime of the access token in seconds. */
1453
1464
  expires_in: number;
1454
1465
  /** Always `'Bearer'`. */
@@ -3169,18 +3180,23 @@ declare class OAuthModule {
3169
3180
  */
3170
3181
  authorize(input: OAuthAuthorizeInput, options?: RequestOptions): Promise<OAuthAuthorizeResult | OAuthConsentRequired>;
3171
3182
  /**
3172
- * Exchange a one-time authorization code for a token pair.
3183
+ * Exchange a one-time authorization code for tokens.
3173
3184
  *
3174
3185
  * The relying party calls this server-to-server (or from its own origin) with the PKCE verifier
3175
3186
  * that matches the earlier challenge. The authorization code is single-use — a reused, expired,
3176
- * or tampered code is rejected with `400 invalid_grant`. On success the returned tokens are
3177
- * persisted into the client session via `setSession`, so the relying party is logged in
3178
- * immediately after the exchange. `grant_type` is set to `'authorization_code'` by the SDK.
3187
+ * or tampered code is rejected with `400 invalid_grant`. `grant_type` is set to
3188
+ * `'authorization_code'` by the SDK.
3189
+ *
3190
+ * When the result is a Mitumba session (it carries a `refresh_token`, as for the Mitumba
3191
+ * marketplace), the tokens are persisted into the client session via `setSession`, so the caller
3192
+ * is signed in immediately. Any other relying party receives an access token addressed only to
3193
+ * itself and no refresh token; that result is returned untouched and the client session is left
3194
+ * as it was, because such a token cannot call Mitumba's APIs or be refreshed.
3179
3195
  *
3180
3196
  * @param input - The token exchange request (code, redirect URI, client, PKCE verifier, optional secret)
3181
3197
  * @param options - Optional per-request options (abort signal, extra headers)
3182
- * @returns The access/refresh token pair and granted scope
3183
- * @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code) or `401 invalid_client` (wrong secret)
3198
+ * @returns The access token, granted scope, and either a refresh token (Mitumba session) or an id_token (relying party)
3199
+ * @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)
3184
3200
  *
3185
3201
  * @example
3186
3202
  * ```typescript
@@ -3216,13 +3232,17 @@ declare class OAuthModule {
3216
3232
  */
3217
3233
  getJwks(options?: RequestOptions): Promise<Jwks>;
3218
3234
  /**
3219
- * Fetch the userinfo claim set for the current session.
3235
+ * Fetch the userinfo claim set.
3220
3236
  *
3221
- * Returns `sub` plus the identity claims the session's granted scopes allow. Requires an
3222
- * authenticated session — the SDK attaches the bearer token automatically.
3237
+ * Returns `sub` plus the identity claims the token's granted scopes allow. With a Mitumba session
3238
+ * the SDK attaches the session's bearer token automatically. A relying party, whose client holds no
3239
+ * Mitumba session (`exchangeCode()` does not set one for it), passes its own access token explicitly:
3240
+ * `sdk.oauth.userinfo({ headers: { Authorization: `Bearer ${tokens.access_token}` } })`. A custom
3241
+ * `Authorization` header never replaces an active session's token.
3223
3242
  *
3224
3243
  * @param options - Optional per-request options (abort signal, extra headers)
3225
3244
  * @returns The userinfo claims
3245
+ * @throws {APIError} On `401` with no token, or `401 invalid_token` for a token that is expired, revoked, or no longer consented
3226
3246
  */
3227
3247
  userinfo(options?: RequestOptions): Promise<UserInfo>;
3228
3248
  /**
package/dist/index.js CHANGED
@@ -735,18 +735,23 @@ var OAuthModule = class {
735
735
  );
736
736
  }
737
737
  /**
738
- * Exchange a one-time authorization code for a token pair.
738
+ * Exchange a one-time authorization code for tokens.
739
739
  *
740
740
  * The relying party calls this server-to-server (or from its own origin) with the PKCE verifier
741
741
  * that matches the earlier challenge. The authorization code is single-use — a reused, expired,
742
- * or tampered code is rejected with `400 invalid_grant`. On success the returned tokens are
743
- * persisted into the client session via `setSession`, so the relying party is logged in
744
- * immediately after the exchange. `grant_type` is set to `'authorization_code'` by the SDK.
742
+ * or tampered code is rejected with `400 invalid_grant`. `grant_type` is set to
743
+ * `'authorization_code'` by the SDK.
744
+ *
745
+ * When the result is a Mitumba session (it carries a `refresh_token`, as for the Mitumba
746
+ * marketplace), the tokens are persisted into the client session via `setSession`, so the caller
747
+ * is signed in immediately. Any other relying party receives an access token addressed only to
748
+ * itself and no refresh token; that result is returned untouched and the client session is left
749
+ * as it was, because such a token cannot call Mitumba's APIs or be refreshed.
745
750
  *
746
751
  * @param input - The token exchange request (code, redirect URI, client, PKCE verifier, optional secret)
747
752
  * @param options - Optional per-request options (abort signal, extra headers)
748
- * @returns The access/refresh token pair and granted scope
749
- * @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code) or `401 invalid_client` (wrong secret)
753
+ * @returns The access token, granted scope, and either a refresh token (Mitumba session) or an id_token (relying party)
754
+ * @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)
750
755
  *
751
756
  * @example
752
757
  * ```typescript
@@ -765,10 +770,12 @@ var OAuthModule = class {
765
770
  { ...input, grant_type: "authorization_code" },
766
771
  options
767
772
  );
768
- await this.client.setSession({
769
- access_token: result.access_token,
770
- refresh_token: result.refresh_token
771
- });
773
+ if (result.refresh_token) {
774
+ await this.client.setSession({
775
+ access_token: result.access_token,
776
+ refresh_token: result.refresh_token
777
+ });
778
+ }
772
779
  return result;
773
780
  }
774
781
  /**
@@ -797,13 +804,17 @@ var OAuthModule = class {
797
804
  return this.client.get("/auth/oauth/jwks.json", void 0, options);
798
805
  }
799
806
  /**
800
- * Fetch the userinfo claim set for the current session.
807
+ * Fetch the userinfo claim set.
801
808
  *
802
- * Returns `sub` plus the identity claims the session's granted scopes allow. Requires an
803
- * authenticated session — the SDK attaches the bearer token automatically.
809
+ * Returns `sub` plus the identity claims the token's granted scopes allow. With a Mitumba session
810
+ * the SDK attaches the session's bearer token automatically. A relying party, whose client holds no
811
+ * Mitumba session (`exchangeCode()` does not set one for it), passes its own access token explicitly:
812
+ * `sdk.oauth.userinfo({ headers: { Authorization: `Bearer ${tokens.access_token}` } })`. A custom
813
+ * `Authorization` header never replaces an active session's token.
804
814
  *
805
815
  * @param options - Optional per-request options (abort signal, extra headers)
806
816
  * @returns The userinfo claims
817
+ * @throws {APIError} On `401` with no token, or `401 invalid_token` for a token that is expired, revoked, or no longer consented
807
818
  */
808
819
  async userinfo(options) {
809
820
  return this.client.get("/auth/oauth/userinfo", void 0, options);