@corvushold/guard-sdk 0.14.0 → 0.16.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/README.md +30 -0
- package/dist/index.cjs +46 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -2
- package/dist/index.d.ts +50 -2
- package/dist/index.js +46 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -153,16 +153,27 @@ interface components {
|
|
|
153
153
|
"controller.LoginOptionsResponse": {
|
|
154
154
|
/** @description If email domain matches an SSO provider's configured domains */
|
|
155
155
|
domain_matched_sso?: components["schemas"]["controller.SSOProviderOption"];
|
|
156
|
+
/** @description Last successful login method for this email in this tenant (if known).
|
|
157
|
+
* Values: "sso", "password", "magic_link" */
|
|
158
|
+
last_successful_method?: string;
|
|
156
159
|
magic_link_enabled?: boolean;
|
|
157
160
|
/** @description Authentication methods available */
|
|
158
161
|
password_enabled?: boolean;
|
|
159
162
|
/** @description Recommended/preferred login method based on context
|
|
160
|
-
* Values: "sso", "password", "magic_link"
|
|
163
|
+
* Values: "sso", "password", "magic_link" */
|
|
161
164
|
preferred_method?: string;
|
|
165
|
+
/** @description Reason for the top recommendation.
|
|
166
|
+
* Values: "sso_required", "last_successful_method", "domain_matched_sso", "preferred_method", "default_order" */
|
|
167
|
+
recommended_method_reason?: string;
|
|
168
|
+
/** @description Ordered recommendation list for clients that support adaptive UI.
|
|
169
|
+
* Values: "sso", "password", "magic_link" */
|
|
170
|
+
recommended_methods?: string[];
|
|
162
171
|
/** @description Whether new user signup is enabled for this tenant */
|
|
163
172
|
signup_enabled?: boolean;
|
|
164
173
|
/** @description Social login providers (tenant-wide or global) */
|
|
165
174
|
social_providers?: components["schemas"]["controller.SocialProviderOption"][];
|
|
175
|
+
/** @description Explicit policy flag for SSO-only login UX. */
|
|
176
|
+
sso_only?: boolean;
|
|
166
177
|
/** @description SSO providers configured for this tenant */
|
|
167
178
|
sso_providers?: components["schemas"]["controller.SSOProviderOption"][];
|
|
168
179
|
/** @description If true, SSO is required for this domain/tenant (password disabled) */
|
|
@@ -1034,6 +1045,19 @@ interface GuardClientOptions {
|
|
|
1034
1045
|
defaultHeaders?: Record<string, string>;
|
|
1035
1046
|
authMode?: 'bearer' | 'cookie';
|
|
1036
1047
|
}
|
|
1048
|
+
interface OAuth2AuthorizeParams {
|
|
1049
|
+
client_id: string;
|
|
1050
|
+
redirect_uri: string;
|
|
1051
|
+
response_type?: 'code';
|
|
1052
|
+
scope?: string | string[];
|
|
1053
|
+
state?: string;
|
|
1054
|
+
nonce?: string;
|
|
1055
|
+
code_challenge?: string;
|
|
1056
|
+
code_challenge_method?: 'S256' | 'plain';
|
|
1057
|
+
prompt?: string;
|
|
1058
|
+
login_hint?: string;
|
|
1059
|
+
max_age?: number;
|
|
1060
|
+
}
|
|
1037
1061
|
type TokensResp = {
|
|
1038
1062
|
access_token?: string | null;
|
|
1039
1063
|
refresh_token?: string | null;
|
|
@@ -1349,7 +1373,11 @@ interface LoginOptionsResp {
|
|
|
1349
1373
|
signup_enabled: boolean;
|
|
1350
1374
|
sso_providers: SsoProviderOption[];
|
|
1351
1375
|
preferred_method: AuthMethod;
|
|
1376
|
+
recommended_methods?: AuthMethod[];
|
|
1377
|
+
recommended_method_reason?: 'sso_required' | 'last_successful_method' | 'domain_matched_sso' | 'preferred_method' | 'default_order';
|
|
1378
|
+
last_successful_method?: AuthMethod;
|
|
1352
1379
|
sso_required: boolean;
|
|
1380
|
+
sso_only?: boolean;
|
|
1353
1381
|
user_exists: boolean;
|
|
1354
1382
|
tenant_id?: string;
|
|
1355
1383
|
tenant_name?: string;
|
|
@@ -1777,6 +1805,26 @@ declare class GuardClient {
|
|
|
1777
1805
|
getOAuthClient(id: string): Promise<ResponseWrapper<OAuthClientItem>>;
|
|
1778
1806
|
updateOAuthClient(id: string, body: UpdateOAuthClientReq): Promise<ResponseWrapper<unknown>>;
|
|
1779
1807
|
deleteOAuthClient(id: string): Promise<ResponseWrapper<unknown>>;
|
|
1808
|
+
/**
|
|
1809
|
+
* Build an OAuth2 Authorization Code URL using this Guard client's baseUrl.
|
|
1810
|
+
*
|
|
1811
|
+
* This prevents accidental redirects to the current app origin when initiating
|
|
1812
|
+
* OAuth2 flows from SPAs.
|
|
1813
|
+
*
|
|
1814
|
+
* @example
|
|
1815
|
+
* ```ts
|
|
1816
|
+
* const url = client.buildOAuth2AuthorizeUrl({
|
|
1817
|
+
* client_id: 'gc_123',
|
|
1818
|
+
* redirect_uri: 'https://app.example.com/callback',
|
|
1819
|
+
* code_challenge: 'abc...',
|
|
1820
|
+
* code_challenge_method: 'S256',
|
|
1821
|
+
* scope: ['openid', 'profile', 'email'],
|
|
1822
|
+
* state: 'csrf-state',
|
|
1823
|
+
* });
|
|
1824
|
+
* window.location.href = url;
|
|
1825
|
+
* ```
|
|
1826
|
+
*/
|
|
1827
|
+
buildOAuth2AuthorizeUrl(params: OAuth2AuthorizeParams): string;
|
|
1780
1828
|
/**
|
|
1781
1829
|
* Fetch OAuth 2.0 Authorization Server Metadata (RFC 8414)
|
|
1782
1830
|
* Returns server capabilities including supported auth modes, endpoints, and grant types.
|
|
@@ -1805,4 +1853,4 @@ declare class GuardClient {
|
|
|
1805
1853
|
|
|
1806
1854
|
declare function generateTOTPCode(base32Secret: string): string;
|
|
1807
1855
|
|
|
1808
|
-
export { type AcceptInvitationReq, type AdminCreateUserReq, type AdminCreateUserResp, type AdminUser, type AdminUsersResp, ApiError, type AsyncStorageLike, type AuthMethod, type CreateOAuthClientReq, type CreateOAuthClientResp, type CreateSsoProviderReq, type DiscoverTenantsResp, type FetchLike, type FgaAclTuple, type FgaGroup, type FgaGroupsResp, GuardClient, type GuardClientOptions, type HeadersMap, HttpClient, InMemoryStorage, type Interceptors, type Invitation, type InvitationStatus, type InvitationsListResp, type InviteUserReq, type InviteUserResp, type LoginOptionsResp, type Meta, type OAuthClientItem, RateLimitError, type RequestInterceptor, type ResponseInterceptor, type ResponseWrapper, type SessionItem, type SessionsListResp, type SsoLinkingPolicy, type SsoPortalContext, type SsoPortalSessionResp, type SsoProvider, type SsoProviderItem, type SsoProviderOption, type SsoProviderSlug, type SsoProviderType, type SsoProvidersListResp, type SsoSPInfoResp, type SsoTestProviderResp, type TenantId, type TenantOption, type TenantSelectionRequiredResp, type TenantSettingsPutRequest, type TenantSettingsResponse, type TenantSummary, type TokenProvider, type TokenStorage, type TransportOptions, type UpdateOAuthClientReq, type UpdateSsoProviderReq, WebLocalStorage, applyRequestInterceptors, applyResponseInterceptors, buildRateLimitError, generateTOTPCode, isApiError, isMfaChallengeResp, isRateLimitError, isTenantSelectionRequired, isTokensResp, noopStorage, parseRetryAfter, reactNativeStorageAdapter, toHeadersMap };
|
|
1856
|
+
export { type AcceptInvitationReq, type AdminCreateUserReq, type AdminCreateUserResp, type AdminUser, type AdminUsersResp, ApiError, type AsyncStorageLike, type AuthMethod, type CreateOAuthClientReq, type CreateOAuthClientResp, type CreateSsoProviderReq, type DiscoverTenantsResp, type FetchLike, type FgaAclTuple, type FgaGroup, type FgaGroupsResp, GuardClient, type GuardClientOptions, type HeadersMap, HttpClient, InMemoryStorage, type Interceptors, type Invitation, type InvitationStatus, type InvitationsListResp, type InviteUserReq, type InviteUserResp, type LoginOptionsResp, type Meta, type OAuth2AuthorizeParams, type OAuthClientItem, RateLimitError, type RequestInterceptor, type ResponseInterceptor, type ResponseWrapper, type SessionItem, type SessionsListResp, type SsoLinkingPolicy, type SsoPortalContext, type SsoPortalSessionResp, type SsoProvider, type SsoProviderItem, type SsoProviderOption, type SsoProviderSlug, type SsoProviderType, type SsoProvidersListResp, type SsoSPInfoResp, type SsoTestProviderResp, type TenantId, type TenantOption, type TenantSelectionRequiredResp, type TenantSettingsPutRequest, type TenantSettingsResponse, type TenantSummary, type TokenProvider, type TokenStorage, type TransportOptions, type UpdateOAuthClientReq, type UpdateSsoProviderReq, WebLocalStorage, applyRequestInterceptors, applyResponseInterceptors, buildRateLimitError, generateTOTPCode, isApiError, isMfaChallengeResp, isRateLimitError, isTenantSelectionRequired, isTokensResp, noopStorage, parseRetryAfter, reactNativeStorageAdapter, toHeadersMap };
|
package/dist/index.d.ts
CHANGED
|
@@ -153,16 +153,27 @@ interface components {
|
|
|
153
153
|
"controller.LoginOptionsResponse": {
|
|
154
154
|
/** @description If email domain matches an SSO provider's configured domains */
|
|
155
155
|
domain_matched_sso?: components["schemas"]["controller.SSOProviderOption"];
|
|
156
|
+
/** @description Last successful login method for this email in this tenant (if known).
|
|
157
|
+
* Values: "sso", "password", "magic_link" */
|
|
158
|
+
last_successful_method?: string;
|
|
156
159
|
magic_link_enabled?: boolean;
|
|
157
160
|
/** @description Authentication methods available */
|
|
158
161
|
password_enabled?: boolean;
|
|
159
162
|
/** @description Recommended/preferred login method based on context
|
|
160
|
-
* Values: "sso", "password", "magic_link"
|
|
163
|
+
* Values: "sso", "password", "magic_link" */
|
|
161
164
|
preferred_method?: string;
|
|
165
|
+
/** @description Reason for the top recommendation.
|
|
166
|
+
* Values: "sso_required", "last_successful_method", "domain_matched_sso", "preferred_method", "default_order" */
|
|
167
|
+
recommended_method_reason?: string;
|
|
168
|
+
/** @description Ordered recommendation list for clients that support adaptive UI.
|
|
169
|
+
* Values: "sso", "password", "magic_link" */
|
|
170
|
+
recommended_methods?: string[];
|
|
162
171
|
/** @description Whether new user signup is enabled for this tenant */
|
|
163
172
|
signup_enabled?: boolean;
|
|
164
173
|
/** @description Social login providers (tenant-wide or global) */
|
|
165
174
|
social_providers?: components["schemas"]["controller.SocialProviderOption"][];
|
|
175
|
+
/** @description Explicit policy flag for SSO-only login UX. */
|
|
176
|
+
sso_only?: boolean;
|
|
166
177
|
/** @description SSO providers configured for this tenant */
|
|
167
178
|
sso_providers?: components["schemas"]["controller.SSOProviderOption"][];
|
|
168
179
|
/** @description If true, SSO is required for this domain/tenant (password disabled) */
|
|
@@ -1034,6 +1045,19 @@ interface GuardClientOptions {
|
|
|
1034
1045
|
defaultHeaders?: Record<string, string>;
|
|
1035
1046
|
authMode?: 'bearer' | 'cookie';
|
|
1036
1047
|
}
|
|
1048
|
+
interface OAuth2AuthorizeParams {
|
|
1049
|
+
client_id: string;
|
|
1050
|
+
redirect_uri: string;
|
|
1051
|
+
response_type?: 'code';
|
|
1052
|
+
scope?: string | string[];
|
|
1053
|
+
state?: string;
|
|
1054
|
+
nonce?: string;
|
|
1055
|
+
code_challenge?: string;
|
|
1056
|
+
code_challenge_method?: 'S256' | 'plain';
|
|
1057
|
+
prompt?: string;
|
|
1058
|
+
login_hint?: string;
|
|
1059
|
+
max_age?: number;
|
|
1060
|
+
}
|
|
1037
1061
|
type TokensResp = {
|
|
1038
1062
|
access_token?: string | null;
|
|
1039
1063
|
refresh_token?: string | null;
|
|
@@ -1349,7 +1373,11 @@ interface LoginOptionsResp {
|
|
|
1349
1373
|
signup_enabled: boolean;
|
|
1350
1374
|
sso_providers: SsoProviderOption[];
|
|
1351
1375
|
preferred_method: AuthMethod;
|
|
1376
|
+
recommended_methods?: AuthMethod[];
|
|
1377
|
+
recommended_method_reason?: 'sso_required' | 'last_successful_method' | 'domain_matched_sso' | 'preferred_method' | 'default_order';
|
|
1378
|
+
last_successful_method?: AuthMethod;
|
|
1352
1379
|
sso_required: boolean;
|
|
1380
|
+
sso_only?: boolean;
|
|
1353
1381
|
user_exists: boolean;
|
|
1354
1382
|
tenant_id?: string;
|
|
1355
1383
|
tenant_name?: string;
|
|
@@ -1777,6 +1805,26 @@ declare class GuardClient {
|
|
|
1777
1805
|
getOAuthClient(id: string): Promise<ResponseWrapper<OAuthClientItem>>;
|
|
1778
1806
|
updateOAuthClient(id: string, body: UpdateOAuthClientReq): Promise<ResponseWrapper<unknown>>;
|
|
1779
1807
|
deleteOAuthClient(id: string): Promise<ResponseWrapper<unknown>>;
|
|
1808
|
+
/**
|
|
1809
|
+
* Build an OAuth2 Authorization Code URL using this Guard client's baseUrl.
|
|
1810
|
+
*
|
|
1811
|
+
* This prevents accidental redirects to the current app origin when initiating
|
|
1812
|
+
* OAuth2 flows from SPAs.
|
|
1813
|
+
*
|
|
1814
|
+
* @example
|
|
1815
|
+
* ```ts
|
|
1816
|
+
* const url = client.buildOAuth2AuthorizeUrl({
|
|
1817
|
+
* client_id: 'gc_123',
|
|
1818
|
+
* redirect_uri: 'https://app.example.com/callback',
|
|
1819
|
+
* code_challenge: 'abc...',
|
|
1820
|
+
* code_challenge_method: 'S256',
|
|
1821
|
+
* scope: ['openid', 'profile', 'email'],
|
|
1822
|
+
* state: 'csrf-state',
|
|
1823
|
+
* });
|
|
1824
|
+
* window.location.href = url;
|
|
1825
|
+
* ```
|
|
1826
|
+
*/
|
|
1827
|
+
buildOAuth2AuthorizeUrl(params: OAuth2AuthorizeParams): string;
|
|
1780
1828
|
/**
|
|
1781
1829
|
* Fetch OAuth 2.0 Authorization Server Metadata (RFC 8414)
|
|
1782
1830
|
* Returns server capabilities including supported auth modes, endpoints, and grant types.
|
|
@@ -1805,4 +1853,4 @@ declare class GuardClient {
|
|
|
1805
1853
|
|
|
1806
1854
|
declare function generateTOTPCode(base32Secret: string): string;
|
|
1807
1855
|
|
|
1808
|
-
export { type AcceptInvitationReq, type AdminCreateUserReq, type AdminCreateUserResp, type AdminUser, type AdminUsersResp, ApiError, type AsyncStorageLike, type AuthMethod, type CreateOAuthClientReq, type CreateOAuthClientResp, type CreateSsoProviderReq, type DiscoverTenantsResp, type FetchLike, type FgaAclTuple, type FgaGroup, type FgaGroupsResp, GuardClient, type GuardClientOptions, type HeadersMap, HttpClient, InMemoryStorage, type Interceptors, type Invitation, type InvitationStatus, type InvitationsListResp, type InviteUserReq, type InviteUserResp, type LoginOptionsResp, type Meta, type OAuthClientItem, RateLimitError, type RequestInterceptor, type ResponseInterceptor, type ResponseWrapper, type SessionItem, type SessionsListResp, type SsoLinkingPolicy, type SsoPortalContext, type SsoPortalSessionResp, type SsoProvider, type SsoProviderItem, type SsoProviderOption, type SsoProviderSlug, type SsoProviderType, type SsoProvidersListResp, type SsoSPInfoResp, type SsoTestProviderResp, type TenantId, type TenantOption, type TenantSelectionRequiredResp, type TenantSettingsPutRequest, type TenantSettingsResponse, type TenantSummary, type TokenProvider, type TokenStorage, type TransportOptions, type UpdateOAuthClientReq, type UpdateSsoProviderReq, WebLocalStorage, applyRequestInterceptors, applyResponseInterceptors, buildRateLimitError, generateTOTPCode, isApiError, isMfaChallengeResp, isRateLimitError, isTenantSelectionRequired, isTokensResp, noopStorage, parseRetryAfter, reactNativeStorageAdapter, toHeadersMap };
|
|
1856
|
+
export { type AcceptInvitationReq, type AdminCreateUserReq, type AdminCreateUserResp, type AdminUser, type AdminUsersResp, ApiError, type AsyncStorageLike, type AuthMethod, type CreateOAuthClientReq, type CreateOAuthClientResp, type CreateSsoProviderReq, type DiscoverTenantsResp, type FetchLike, type FgaAclTuple, type FgaGroup, type FgaGroupsResp, GuardClient, type GuardClientOptions, type HeadersMap, HttpClient, InMemoryStorage, type Interceptors, type Invitation, type InvitationStatus, type InvitationsListResp, type InviteUserReq, type InviteUserResp, type LoginOptionsResp, type Meta, type OAuth2AuthorizeParams, type OAuthClientItem, RateLimitError, type RequestInterceptor, type ResponseInterceptor, type ResponseWrapper, type SessionItem, type SessionsListResp, type SsoLinkingPolicy, type SsoPortalContext, type SsoPortalSessionResp, type SsoProvider, type SsoProviderItem, type SsoProviderOption, type SsoProviderSlug, type SsoProviderType, type SsoProvidersListResp, type SsoSPInfoResp, type SsoTestProviderResp, type TenantId, type TenantOption, type TenantSelectionRequiredResp, type TenantSettingsPutRequest, type TenantSettingsResponse, type TenantSummary, type TokenProvider, type TokenStorage, type TransportOptions, type UpdateOAuthClientReq, type UpdateSsoProviderReq, WebLocalStorage, applyRequestInterceptors, applyResponseInterceptors, buildRateLimitError, generateTOTPCode, isApiError, isMfaChallengeResp, isRateLimitError, isTenantSelectionRequired, isTokensResp, noopStorage, parseRetryAfter, reactNativeStorageAdapter, toHeadersMap };
|
package/dist/index.js
CHANGED
|
@@ -277,7 +277,7 @@ var HttpClient = class {
|
|
|
277
277
|
|
|
278
278
|
// package.json
|
|
279
279
|
var package_default = {
|
|
280
|
-
version: "0.
|
|
280
|
+
version: "0.16.0"};
|
|
281
281
|
|
|
282
282
|
// src/client.ts
|
|
283
283
|
function isTenantSelectionRequired(data) {
|
|
@@ -1048,6 +1048,51 @@ var GuardClient = class {
|
|
|
1048
1048
|
// ==============================
|
|
1049
1049
|
// OAuth2 Discovery (RFC 8414)
|
|
1050
1050
|
// ==============================
|
|
1051
|
+
/**
|
|
1052
|
+
* Build an OAuth2 Authorization Code URL using this Guard client's baseUrl.
|
|
1053
|
+
*
|
|
1054
|
+
* This prevents accidental redirects to the current app origin when initiating
|
|
1055
|
+
* OAuth2 flows from SPAs.
|
|
1056
|
+
*
|
|
1057
|
+
* @example
|
|
1058
|
+
* ```ts
|
|
1059
|
+
* const url = client.buildOAuth2AuthorizeUrl({
|
|
1060
|
+
* client_id: 'gc_123',
|
|
1061
|
+
* redirect_uri: 'https://app.example.com/callback',
|
|
1062
|
+
* code_challenge: 'abc...',
|
|
1063
|
+
* code_challenge_method: 'S256',
|
|
1064
|
+
* scope: ['openid', 'profile', 'email'],
|
|
1065
|
+
* state: 'csrf-state',
|
|
1066
|
+
* });
|
|
1067
|
+
* window.location.href = url;
|
|
1068
|
+
* ```
|
|
1069
|
+
*/
|
|
1070
|
+
buildOAuth2AuthorizeUrl(params) {
|
|
1071
|
+
const clientID = params.client_id?.trim();
|
|
1072
|
+
if (!clientID) throw new Error("client_id is required");
|
|
1073
|
+
const redirectURI = params.redirect_uri?.trim();
|
|
1074
|
+
if (!redirectURI) throw new Error("redirect_uri is required");
|
|
1075
|
+
const responseType = params.response_type ?? "code";
|
|
1076
|
+
if (responseType !== "code") {
|
|
1077
|
+
throw new Error('response_type must be "code"');
|
|
1078
|
+
}
|
|
1079
|
+
const scope = Array.isArray(params.scope) ? params.scope.filter(Boolean).join(" ").trim() : params.scope?.trim();
|
|
1080
|
+
const u = new URL("/oauth/authorize", this.baseUrl);
|
|
1081
|
+
u.searchParams.set("response_type", responseType);
|
|
1082
|
+
u.searchParams.set("client_id", clientID);
|
|
1083
|
+
u.searchParams.set("redirect_uri", redirectURI);
|
|
1084
|
+
if (scope) u.searchParams.set("scope", scope);
|
|
1085
|
+
if (params.state) u.searchParams.set("state", params.state);
|
|
1086
|
+
if (params.nonce) u.searchParams.set("nonce", params.nonce);
|
|
1087
|
+
if (params.code_challenge) u.searchParams.set("code_challenge", params.code_challenge);
|
|
1088
|
+
if (params.code_challenge) {
|
|
1089
|
+
u.searchParams.set("code_challenge_method", params.code_challenge_method ?? "S256");
|
|
1090
|
+
}
|
|
1091
|
+
if (params.prompt) u.searchParams.set("prompt", params.prompt);
|
|
1092
|
+
if (params.login_hint) u.searchParams.set("login_hint", params.login_hint);
|
|
1093
|
+
if (params.max_age !== void 0) u.searchParams.set("max_age", String(params.max_age));
|
|
1094
|
+
return u.toString();
|
|
1095
|
+
}
|
|
1051
1096
|
/**
|
|
1052
1097
|
* Fetch OAuth 2.0 Authorization Server Metadata (RFC 8414)
|
|
1053
1098
|
* Returns server capabilities including supported auth modes, endpoints, and grant types.
|