@djangocfg/api 2.1.599 → 2.1.600
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 +2 -1
- package/dist/OAuthProvidersResponse-QZ566OYR.mjs +25 -0
- package/dist/OAuthProvidersResponse-QZ566OYR.mjs.map +1 -0
- package/dist/auth.cjs +526 -288
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +144 -31
- package/dist/auth.d.ts +144 -31
- package/dist/auth.mjs +409 -213
- package/dist/auth.mjs.map +1 -1
- package/dist/cfg_accounts_oauth_connections_response_200_AutoRef-N532BRPN.mjs +28 -0
- package/dist/cfg_accounts_oauth_connections_response_200_AutoRef-N532BRPN.mjs.map +1 -0
- package/dist/chunk-PCOSFQTH.mjs +10 -0
- package/dist/chunk-PCOSFQTH.mjs.map +1 -0
- package/dist/clients.cjs +34 -3
- package/dist/clients.cjs.map +1 -1
- package/dist/clients.d.cts +135 -14
- package/dist/clients.d.ts +135 -14
- package/dist/clients.mjs +34 -3
- package/dist/clients.mjs.map +1 -1
- package/dist/hooks.cjs +1 -0
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.mjs +1 -0
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.cjs +34 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +169 -17
- package/dist/index.d.ts +169 -17
- package/dist/index.mjs +34 -3
- package/dist/index.mjs.map +1 -1
- package/dist/storage.cjs +1 -0
- package/dist/storage.cjs.map +1 -1
- package/dist/storage.d.cts +1 -0
- package/dist/storage.d.ts +1 -0
- package/dist/storage.mjs +1 -0
- package/dist/storage.mjs.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/noStorageLiterals.test.ts +1 -1
- package/src/_api/generated/_cfg_accounts/hooks/index.ts +2 -0
- package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthGoogleAuthorizeCreate.ts +68 -0
- package/src/_api/generated/_cfg_accounts/hooks/useCfgAccountsOauthGoogleCallbackCreate.ts +68 -0
- package/src/_api/generated/_cfg_accounts/openapi.json +263 -19
- package/src/_api/generated/_cfg_accounts/schemas/OAuthCallbackRequestRequest.ts +2 -2
- package/src/_api/generated/_cfg_accounts/schemas/OAuthError.ts +2 -1
- package/src/_api/generated/_cfg_accounts/schemas/OAuthErrorCodeEnum.ts +9 -0
- package/src/_api/generated/_cfg_accounts/schemas/OAuthProviderEnum.ts +1 -1
- package/src/_api/generated/_cfg_accounts/schemas/OAuthProviderInfo.ts +14 -0
- package/src/_api/generated/_cfg_accounts/schemas/OAuthProvidersResponse.ts +2 -1
- package/src/_api/generated/_cfg_accounts/schemas/index.ts +2 -0
- package/src/_api/generated/helpers/keys.ts +1 -0
- package/src/_api/generated/openapi.json +263 -19
- package/src/_api/generated/sdk.gen.ts +36 -4
- package/src/_api/generated/types.gen.ts +136 -11
- package/src/auth/__tests__/oauthErrors.test.ts +23 -0
- package/src/auth/__tests__/passwordLogin.test.tsx +1 -0
- package/src/auth/__tests__/useOAuthLogin.test.tsx +387 -0
- package/src/auth/hooks/index.ts +12 -1
- package/src/auth/hooks/useGithubAuth.ts +15 -225
- package/src/auth/hooks/useOAuthLogin.ts +237 -0
- package/src/auth/hooks/useOAuthProviders.ts +76 -0
- package/src/auth/utils/index.ts +8 -0
- package/src/auth/utils/oauthErrors.ts +45 -0
package/dist/auth.d.cts
CHANGED
|
@@ -40,6 +40,70 @@ type CfgUserUpdateRequest = {
|
|
|
40
40
|
*/
|
|
41
41
|
timezone?: string;
|
|
42
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* * `oauth_disabled` - oauth_disabled
|
|
45
|
+
* * `github_oauth_disabled` - github_oauth_disabled
|
|
46
|
+
* * `origin_not_allowed` - origin_not_allowed
|
|
47
|
+
* * `missing_redirect_uri` - missing_redirect_uri
|
|
48
|
+
* * `invalid_state` - invalid_state
|
|
49
|
+
* * `oauth_exchange_failed` - oauth_exchange_failed
|
|
50
|
+
* * `invalid_id_token` - invalid_id_token
|
|
51
|
+
* * `email_missing` - email_missing
|
|
52
|
+
* * `email_not_verified` - email_not_verified
|
|
53
|
+
* * `hosted_domain_not_allowed` - hosted_domain_not_allowed
|
|
54
|
+
* * `account_inactive` - account_inactive
|
|
55
|
+
* * `link_not_allowed` - link_not_allowed
|
|
56
|
+
* * `rate_limited` - rate_limited
|
|
57
|
+
* * `provider_unavailable` - provider_unavailable
|
|
58
|
+
* * `server_error` - server_error
|
|
59
|
+
* * `not_found` - not_found
|
|
60
|
+
*/
|
|
61
|
+
declare enum OAuthErrorCodeEnum {
|
|
62
|
+
OAUTH_DISABLED = "oauth_disabled",
|
|
63
|
+
GITHUB_OAUTH_DISABLED = "github_oauth_disabled",
|
|
64
|
+
ORIGIN_NOT_ALLOWED = "origin_not_allowed",
|
|
65
|
+
MISSING_REDIRECT_URI = "missing_redirect_uri",
|
|
66
|
+
INVALID_STATE = "invalid_state",
|
|
67
|
+
OAUTH_EXCHANGE_FAILED = "oauth_exchange_failed",
|
|
68
|
+
INVALID_ID_TOKEN = "invalid_id_token",
|
|
69
|
+
EMAIL_MISSING = "email_missing",
|
|
70
|
+
EMAIL_NOT_VERIFIED = "email_not_verified",
|
|
71
|
+
HOSTED_DOMAIN_NOT_ALLOWED = "hosted_domain_not_allowed",
|
|
72
|
+
ACCOUNT_INACTIVE = "account_inactive",
|
|
73
|
+
LINK_NOT_ALLOWED = "link_not_allowed",
|
|
74
|
+
RATE_LIMITED = "rate_limited",
|
|
75
|
+
PROVIDER_UNAVAILABLE = "provider_unavailable",
|
|
76
|
+
SERVER_ERROR = "server_error",
|
|
77
|
+
NOT_FOUND = "not_found"
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* * `github` - GitHub
|
|
81
|
+
* * `google` - Google
|
|
82
|
+
*/
|
|
83
|
+
declare enum OAuthProviderEnum {
|
|
84
|
+
GITHUB = "github",
|
|
85
|
+
GOOGLE = "google"
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* One enabled sign-in provider.
|
|
89
|
+
*/
|
|
90
|
+
type OAuthProviderInfo = {
|
|
91
|
+
/**
|
|
92
|
+
* Provider id
|
|
93
|
+
*
|
|
94
|
+
* * `github` - GitHub
|
|
95
|
+
* * `google` - Google
|
|
96
|
+
*/
|
|
97
|
+
id: OAuthProviderEnum;
|
|
98
|
+
/**
|
|
99
|
+
* Display name
|
|
100
|
+
*/
|
|
101
|
+
name: string;
|
|
102
|
+
/**
|
|
103
|
+
* Icon key
|
|
104
|
+
*/
|
|
105
|
+
icon: string;
|
|
106
|
+
};
|
|
43
107
|
/**
|
|
44
108
|
* Response with JWT tokens after OAuth authentication.
|
|
45
109
|
*
|
|
@@ -834,30 +898,94 @@ declare const useAutoAuth: (options?: UseAutoAuthOptions) => {
|
|
|
834
898
|
isAllowedPath: boolean;
|
|
835
899
|
};
|
|
836
900
|
|
|
901
|
+
/** A provider the server can offer. Derived from the generated enum, so a new backend provider is a type error until it gets an adapter. */
|
|
902
|
+
type OAuthProviderId = `${OAuthProviderEnum}`;
|
|
903
|
+
/** Every `error` value the OAuth endpoints can return (closed set from the OpenAPI schema). */
|
|
904
|
+
type OAuthErrorCode = `${OAuthErrorCodeEnum}`;
|
|
905
|
+
/** Failures the browser detects itself, before or instead of a server answer. */
|
|
906
|
+
type OAuthClientErrorCode = 'cancelled' | 'unknown_provider';
|
|
907
|
+
type OAuthFailureCode = OAuthErrorCode | OAuthClientErrorCode;
|
|
908
|
+
interface OAuthFailure {
|
|
909
|
+
/** Set when the cause is one the UI can explain; absent for transport faults. */
|
|
910
|
+
code?: OAuthFailureCode;
|
|
911
|
+
/** English text for callers without a translator: server prose, else a generic sentence. */
|
|
912
|
+
message: string;
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Read `{error, error_description}` off a thrown API error.
|
|
916
|
+
*
|
|
917
|
+
* The transport keeps the parsed body on `response`; `formatAuthError` alone
|
|
918
|
+
* would surface the machine code (`invalid_state`) as if it were prose.
|
|
919
|
+
*/
|
|
920
|
+
declare const readOAuthFailure: (err: unknown, fallback: string) => OAuthFailure;
|
|
921
|
+
|
|
837
922
|
/**
|
|
838
923
|
* The user payload as the OAuth endpoint declares it.
|
|
839
924
|
*
|
|
840
925
|
* Derived from the generated response rather than restated, so a schema change
|
|
841
|
-
* reaches callers through `make
|
|
842
|
-
* backend types it as a free-form object; when it names a real user model, this
|
|
843
|
-
* narrows on its own.
|
|
926
|
+
* reaches callers through `make generate` instead of drifting silently.
|
|
844
927
|
*/
|
|
845
928
|
type OAuthUser = NonNullable<OAuthTokenResponse['user']>;
|
|
846
|
-
|
|
929
|
+
/** Provider ids this client can run, in the order the adapters are declared. */
|
|
930
|
+
declare const OAUTH_PROVIDER_IDS: OAuthProviderId[];
|
|
931
|
+
declare const isOAuthProviderId: (value: unknown) => value is OAuthProviderId;
|
|
932
|
+
/** Forget the stored state: the attempt is over without an exchange (Cancel, a provider error). */
|
|
933
|
+
declare const clearOAuthAttempt: () => void;
|
|
934
|
+
interface UseOAuthLoginOptions {
|
|
847
935
|
sourceUrl?: string;
|
|
848
|
-
/**
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
onSuccess?: (user: OAuthUser, isNewUser: boolean) => void;
|
|
854
|
-
onError?: (error: string) => void;
|
|
855
|
-
/** Callback when 2FA is required */
|
|
936
|
+
/** The endpoint types `user` as a free-form object; narrow it at the call site. */
|
|
937
|
+
onSuccess?: (user: OAuthUser, isNewUser: boolean, provider: OAuthProviderId) => void;
|
|
938
|
+
/** `message` is server prose or an English fallback; `code` lets the caller choose its own copy. */
|
|
939
|
+
onError?: (message: string, code?: OAuthFailureCode) => void;
|
|
940
|
+
/** Called when 2FA is required instead of a session. */
|
|
856
941
|
onRequires2FA?: (sessionId: string, shouldPrompt2FA: boolean) => void;
|
|
857
942
|
redirectUrl?: string;
|
|
858
|
-
/** Skip automatic redirect after success (caller
|
|
943
|
+
/** Skip the automatic redirect after success (the caller navigates). */
|
|
859
944
|
skipRedirect?: boolean;
|
|
860
945
|
}
|
|
946
|
+
interface UseOAuthLoginReturn {
|
|
947
|
+
/** True from the click until the page leaves (start) or the exchange settles (complete). */
|
|
948
|
+
isLoading: boolean;
|
|
949
|
+
/** The provider whose flow is in flight; disable the other buttons, show progress on this one. */
|
|
950
|
+
loadingProvider: OAuthProviderId | null;
|
|
951
|
+
error: string | null;
|
|
952
|
+
errorCode: OAuthFailureCode | null;
|
|
953
|
+
/** Redirects the tab to the provider. Resolves only if it failed to start. */
|
|
954
|
+
start: (provider: OAuthProviderId) => Promise<void>;
|
|
955
|
+
/** Exchanges the `code` the provider returned. The stored `state` must match; there is no unchecked path. */
|
|
956
|
+
complete: (provider: OAuthProviderId, code: string, state: string) => Promise<void>;
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Sign in with a third-party provider: one hook for every provider.
|
|
960
|
+
*
|
|
961
|
+
* Flow, full page in the same tab so the saved return URL survives:
|
|
962
|
+
* `start(provider)` stores the server's `state`, then navigates to the provider.
|
|
963
|
+
* The provider returns to `/auth?provider=<id>&code&state`; `complete(...)`
|
|
964
|
+
* verifies that `state` against the stored one (login CSRF defence), exchanges
|
|
965
|
+
* the code and writes the session.
|
|
966
|
+
*/
|
|
967
|
+
declare const useOAuthLogin: (options?: UseOAuthLoginOptions) => UseOAuthLoginReturn;
|
|
968
|
+
|
|
969
|
+
interface UseOAuthProvidersReturn {
|
|
970
|
+
/** Providers the server has configured, in the server's display order. Empty until ready and on failure. */
|
|
971
|
+
providers: OAuthProviderInfo[];
|
|
972
|
+
/** False only while the first request is in flight and nothing is cached. */
|
|
973
|
+
isReady: boolean;
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* The sign-in providers the server offers (`GET /cfg/accounts/oauth/providers/`).
|
|
977
|
+
*
|
|
978
|
+
* Fetched once per page session and kept in `sessionStorage`, so a reload or
|
|
979
|
+
* "Try again" after a failed callback shows the buttons at once; the server
|
|
980
|
+
* answer always wins. A failure yields the cached list, else `[]`, with
|
|
981
|
+
* `isReady: true`: the email form never waits on, or breaks because of, this
|
|
982
|
+
* list. Ids this client has no adapter for (a newer backend) are dropped.
|
|
983
|
+
*/
|
|
984
|
+
declare const useOAuthProviders: () => UseOAuthProvidersReturn;
|
|
985
|
+
|
|
986
|
+
/** @deprecated Use `UseOAuthLoginOptions`. */
|
|
987
|
+
type UseGithubAuthOptions = UseOAuthLoginOptions;
|
|
988
|
+
/** @deprecated Use `UseOAuthLoginReturn`. */
|
|
861
989
|
interface UseGithubAuthReturn {
|
|
862
990
|
isLoading: boolean;
|
|
863
991
|
error: string | null;
|
|
@@ -865,23 +993,8 @@ interface UseGithubAuthReturn {
|
|
|
865
993
|
handleGithubCallback: (code: string, state: string) => Promise<void>;
|
|
866
994
|
}
|
|
867
995
|
/**
|
|
868
|
-
*
|
|
869
|
-
*
|
|
870
|
-
* Usage:
|
|
871
|
-
* 1. Call startGithubAuth() to redirect user to GitHub
|
|
872
|
-
* 2. After GitHub redirects back, call handleGithubCallback(code, state)
|
|
873
|
-
*
|
|
874
|
-
* @example
|
|
875
|
-
* ```tsx
|
|
876
|
-
* const { isLoading, error, startGithubAuth } = useGithubAuth({
|
|
877
|
-
* onSuccess: (user) => router.push('/dashboard'),
|
|
878
|
-
* onError: (error) => console.error(error),
|
|
879
|
-
* });
|
|
880
|
-
*
|
|
881
|
-
* <Button onClick={startGithubAuth} disabled={isLoading}>
|
|
882
|
-
* Continue with GitHub
|
|
883
|
-
* </Button>
|
|
884
|
-
* ```
|
|
996
|
+
* @deprecated Use `useOAuthLogin` (`start('github')`, `complete('github', code, state)`).
|
|
997
|
+
* Kept for one minor release; behaviour is `useOAuthLogin` with the provider fixed.
|
|
885
998
|
*/
|
|
886
999
|
declare const useGithubAuth: (options?: UseGithubAuthOptions) => UseGithubAuthReturn;
|
|
887
1000
|
|
|
@@ -1416,4 +1529,4 @@ declare const Analytics: {
|
|
|
1416
1529
|
setUser(userId: string | null): void;
|
|
1417
1530
|
};
|
|
1418
1531
|
|
|
1419
|
-
export { AUTH_CONSTANTS, AUTH_ERROR_KEYS, type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AnalyticsSink, type AuthConfig, AuthContext, type AuthContextType, type AuthErrorCopy, type AuthErrorKey, type AuthFormAutoSubmit, type AuthFormReturn, type AuthFormState, type AuthFormStateHandlers, type AuthFormSubmitHandlers, type AuthFormValidation, AuthProvider, type AuthProviderProps, type AuthStep, type DeleteAccountResult, type GuardInput, type OTPRequestConsent, type OTPRequestResult, type PasswordLoginOptions, type PasswordLoginResult, type PatchedCfgUserUpdateRequest, type ProfileCacheOptions, type SessionSnapshot, type SessionStatus, type TwoFactorChallenge, type TwoFactorDevice, type TwoFactorSetupData, type UseAuthFormOptions, type UseAuthFormStateReturn, type UseAutoAuthOptions, type UseDeleteAccountReturn, type UseGithubAuthOptions, type UseGithubAuthReturn, type UseTimezoneReturn, type UseTwoFactorOptions, type UseTwoFactorReturn, type UseTwoFactorSetupOptions, type UseTwoFactorSetupReturn, type UseTwoFactorStatusReturn, type UseTwoFactorVerifyOptions, type UseTwoFactorVerifyReturn, type UserProfile, type WebmailLink, authLogger, beginTwoFactorChallenge, clearProfileCache, consumeSavedRedirect, decodeBase64, encodeBase64, endTwoFactorChallenge, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, isAllowedAuthPath, isForbidden, logAuthFailure, logger, normalizePath, peekSavedRedirect, resolveAuthError, resolveGuardIsAuthenticated, resolveGuardIsLoading, setAnalyticsSink, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useQueryParams, useSession, useSessionStorage, useTimezone, useTwoFactor, useTwoFactorChallenge, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
|
|
1532
|
+
export { AUTH_CONSTANTS, AUTH_ERROR_KEYS, type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AnalyticsSink, type AuthConfig, AuthContext, type AuthContextType, type AuthErrorCopy, type AuthErrorKey, type AuthFormAutoSubmit, type AuthFormReturn, type AuthFormState, type AuthFormStateHandlers, type AuthFormSubmitHandlers, type AuthFormValidation, AuthProvider, type AuthProviderProps, type AuthStep, type DeleteAccountResult, type GuardInput, OAUTH_PROVIDER_IDS, type OAuthClientErrorCode, type OAuthErrorCode, type OAuthFailure, type OAuthFailureCode, type OAuthProviderId, type OAuthUser, type OTPRequestConsent, type OTPRequestResult, type PasswordLoginOptions, type PasswordLoginResult, type PatchedCfgUserUpdateRequest, type ProfileCacheOptions, type SessionSnapshot, type SessionStatus, type TwoFactorChallenge, type TwoFactorDevice, type TwoFactorSetupData, type UseAuthFormOptions, type UseAuthFormStateReturn, type UseAutoAuthOptions, type UseDeleteAccountReturn, type UseGithubAuthOptions, type UseGithubAuthReturn, type UseOAuthLoginOptions, type UseOAuthLoginReturn, type UseOAuthProvidersReturn, type UseTimezoneReturn, type UseTwoFactorOptions, type UseTwoFactorReturn, type UseTwoFactorSetupOptions, type UseTwoFactorSetupReturn, type UseTwoFactorStatusReturn, type UseTwoFactorVerifyOptions, type UseTwoFactorVerifyReturn, type UserProfile, type WebmailLink, authLogger, beginTwoFactorChallenge, clearOAuthAttempt, clearProfileCache, consumeSavedRedirect, decodeBase64, encodeBase64, endTwoFactorChallenge, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, isAllowedAuthPath, isForbidden, isOAuthProviderId, logAuthFailure, logger, normalizePath, peekSavedRedirect, readOAuthFailure, resolveAuthError, resolveGuardIsAuthenticated, resolveGuardIsLoading, setAnalyticsSink, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useOAuthLogin, useOAuthProviders, useQueryParams, useSession, useSessionStorage, useTimezone, useTwoFactor, useTwoFactorChallenge, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
|
package/dist/auth.d.ts
CHANGED
|
@@ -40,6 +40,70 @@ type CfgUserUpdateRequest = {
|
|
|
40
40
|
*/
|
|
41
41
|
timezone?: string;
|
|
42
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* * `oauth_disabled` - oauth_disabled
|
|
45
|
+
* * `github_oauth_disabled` - github_oauth_disabled
|
|
46
|
+
* * `origin_not_allowed` - origin_not_allowed
|
|
47
|
+
* * `missing_redirect_uri` - missing_redirect_uri
|
|
48
|
+
* * `invalid_state` - invalid_state
|
|
49
|
+
* * `oauth_exchange_failed` - oauth_exchange_failed
|
|
50
|
+
* * `invalid_id_token` - invalid_id_token
|
|
51
|
+
* * `email_missing` - email_missing
|
|
52
|
+
* * `email_not_verified` - email_not_verified
|
|
53
|
+
* * `hosted_domain_not_allowed` - hosted_domain_not_allowed
|
|
54
|
+
* * `account_inactive` - account_inactive
|
|
55
|
+
* * `link_not_allowed` - link_not_allowed
|
|
56
|
+
* * `rate_limited` - rate_limited
|
|
57
|
+
* * `provider_unavailable` - provider_unavailable
|
|
58
|
+
* * `server_error` - server_error
|
|
59
|
+
* * `not_found` - not_found
|
|
60
|
+
*/
|
|
61
|
+
declare enum OAuthErrorCodeEnum {
|
|
62
|
+
OAUTH_DISABLED = "oauth_disabled",
|
|
63
|
+
GITHUB_OAUTH_DISABLED = "github_oauth_disabled",
|
|
64
|
+
ORIGIN_NOT_ALLOWED = "origin_not_allowed",
|
|
65
|
+
MISSING_REDIRECT_URI = "missing_redirect_uri",
|
|
66
|
+
INVALID_STATE = "invalid_state",
|
|
67
|
+
OAUTH_EXCHANGE_FAILED = "oauth_exchange_failed",
|
|
68
|
+
INVALID_ID_TOKEN = "invalid_id_token",
|
|
69
|
+
EMAIL_MISSING = "email_missing",
|
|
70
|
+
EMAIL_NOT_VERIFIED = "email_not_verified",
|
|
71
|
+
HOSTED_DOMAIN_NOT_ALLOWED = "hosted_domain_not_allowed",
|
|
72
|
+
ACCOUNT_INACTIVE = "account_inactive",
|
|
73
|
+
LINK_NOT_ALLOWED = "link_not_allowed",
|
|
74
|
+
RATE_LIMITED = "rate_limited",
|
|
75
|
+
PROVIDER_UNAVAILABLE = "provider_unavailable",
|
|
76
|
+
SERVER_ERROR = "server_error",
|
|
77
|
+
NOT_FOUND = "not_found"
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* * `github` - GitHub
|
|
81
|
+
* * `google` - Google
|
|
82
|
+
*/
|
|
83
|
+
declare enum OAuthProviderEnum {
|
|
84
|
+
GITHUB = "github",
|
|
85
|
+
GOOGLE = "google"
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* One enabled sign-in provider.
|
|
89
|
+
*/
|
|
90
|
+
type OAuthProviderInfo = {
|
|
91
|
+
/**
|
|
92
|
+
* Provider id
|
|
93
|
+
*
|
|
94
|
+
* * `github` - GitHub
|
|
95
|
+
* * `google` - Google
|
|
96
|
+
*/
|
|
97
|
+
id: OAuthProviderEnum;
|
|
98
|
+
/**
|
|
99
|
+
* Display name
|
|
100
|
+
*/
|
|
101
|
+
name: string;
|
|
102
|
+
/**
|
|
103
|
+
* Icon key
|
|
104
|
+
*/
|
|
105
|
+
icon: string;
|
|
106
|
+
};
|
|
43
107
|
/**
|
|
44
108
|
* Response with JWT tokens after OAuth authentication.
|
|
45
109
|
*
|
|
@@ -834,30 +898,94 @@ declare const useAutoAuth: (options?: UseAutoAuthOptions) => {
|
|
|
834
898
|
isAllowedPath: boolean;
|
|
835
899
|
};
|
|
836
900
|
|
|
901
|
+
/** A provider the server can offer. Derived from the generated enum, so a new backend provider is a type error until it gets an adapter. */
|
|
902
|
+
type OAuthProviderId = `${OAuthProviderEnum}`;
|
|
903
|
+
/** Every `error` value the OAuth endpoints can return (closed set from the OpenAPI schema). */
|
|
904
|
+
type OAuthErrorCode = `${OAuthErrorCodeEnum}`;
|
|
905
|
+
/** Failures the browser detects itself, before or instead of a server answer. */
|
|
906
|
+
type OAuthClientErrorCode = 'cancelled' | 'unknown_provider';
|
|
907
|
+
type OAuthFailureCode = OAuthErrorCode | OAuthClientErrorCode;
|
|
908
|
+
interface OAuthFailure {
|
|
909
|
+
/** Set when the cause is one the UI can explain; absent for transport faults. */
|
|
910
|
+
code?: OAuthFailureCode;
|
|
911
|
+
/** English text for callers without a translator: server prose, else a generic sentence. */
|
|
912
|
+
message: string;
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Read `{error, error_description}` off a thrown API error.
|
|
916
|
+
*
|
|
917
|
+
* The transport keeps the parsed body on `response`; `formatAuthError` alone
|
|
918
|
+
* would surface the machine code (`invalid_state`) as if it were prose.
|
|
919
|
+
*/
|
|
920
|
+
declare const readOAuthFailure: (err: unknown, fallback: string) => OAuthFailure;
|
|
921
|
+
|
|
837
922
|
/**
|
|
838
923
|
* The user payload as the OAuth endpoint declares it.
|
|
839
924
|
*
|
|
840
925
|
* Derived from the generated response rather than restated, so a schema change
|
|
841
|
-
* reaches callers through `make
|
|
842
|
-
* backend types it as a free-form object; when it names a real user model, this
|
|
843
|
-
* narrows on its own.
|
|
926
|
+
* reaches callers through `make generate` instead of drifting silently.
|
|
844
927
|
*/
|
|
845
928
|
type OAuthUser = NonNullable<OAuthTokenResponse['user']>;
|
|
846
|
-
|
|
929
|
+
/** Provider ids this client can run, in the order the adapters are declared. */
|
|
930
|
+
declare const OAUTH_PROVIDER_IDS: OAuthProviderId[];
|
|
931
|
+
declare const isOAuthProviderId: (value: unknown) => value is OAuthProviderId;
|
|
932
|
+
/** Forget the stored state: the attempt is over without an exchange (Cancel, a provider error). */
|
|
933
|
+
declare const clearOAuthAttempt: () => void;
|
|
934
|
+
interface UseOAuthLoginOptions {
|
|
847
935
|
sourceUrl?: string;
|
|
848
|
-
/**
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
onSuccess?: (user: OAuthUser, isNewUser: boolean) => void;
|
|
854
|
-
onError?: (error: string) => void;
|
|
855
|
-
/** Callback when 2FA is required */
|
|
936
|
+
/** The endpoint types `user` as a free-form object; narrow it at the call site. */
|
|
937
|
+
onSuccess?: (user: OAuthUser, isNewUser: boolean, provider: OAuthProviderId) => void;
|
|
938
|
+
/** `message` is server prose or an English fallback; `code` lets the caller choose its own copy. */
|
|
939
|
+
onError?: (message: string, code?: OAuthFailureCode) => void;
|
|
940
|
+
/** Called when 2FA is required instead of a session. */
|
|
856
941
|
onRequires2FA?: (sessionId: string, shouldPrompt2FA: boolean) => void;
|
|
857
942
|
redirectUrl?: string;
|
|
858
|
-
/** Skip automatic redirect after success (caller
|
|
943
|
+
/** Skip the automatic redirect after success (the caller navigates). */
|
|
859
944
|
skipRedirect?: boolean;
|
|
860
945
|
}
|
|
946
|
+
interface UseOAuthLoginReturn {
|
|
947
|
+
/** True from the click until the page leaves (start) or the exchange settles (complete). */
|
|
948
|
+
isLoading: boolean;
|
|
949
|
+
/** The provider whose flow is in flight; disable the other buttons, show progress on this one. */
|
|
950
|
+
loadingProvider: OAuthProviderId | null;
|
|
951
|
+
error: string | null;
|
|
952
|
+
errorCode: OAuthFailureCode | null;
|
|
953
|
+
/** Redirects the tab to the provider. Resolves only if it failed to start. */
|
|
954
|
+
start: (provider: OAuthProviderId) => Promise<void>;
|
|
955
|
+
/** Exchanges the `code` the provider returned. The stored `state` must match; there is no unchecked path. */
|
|
956
|
+
complete: (provider: OAuthProviderId, code: string, state: string) => Promise<void>;
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Sign in with a third-party provider: one hook for every provider.
|
|
960
|
+
*
|
|
961
|
+
* Flow, full page in the same tab so the saved return URL survives:
|
|
962
|
+
* `start(provider)` stores the server's `state`, then navigates to the provider.
|
|
963
|
+
* The provider returns to `/auth?provider=<id>&code&state`; `complete(...)`
|
|
964
|
+
* verifies that `state` against the stored one (login CSRF defence), exchanges
|
|
965
|
+
* the code and writes the session.
|
|
966
|
+
*/
|
|
967
|
+
declare const useOAuthLogin: (options?: UseOAuthLoginOptions) => UseOAuthLoginReturn;
|
|
968
|
+
|
|
969
|
+
interface UseOAuthProvidersReturn {
|
|
970
|
+
/** Providers the server has configured, in the server's display order. Empty until ready and on failure. */
|
|
971
|
+
providers: OAuthProviderInfo[];
|
|
972
|
+
/** False only while the first request is in flight and nothing is cached. */
|
|
973
|
+
isReady: boolean;
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* The sign-in providers the server offers (`GET /cfg/accounts/oauth/providers/`).
|
|
977
|
+
*
|
|
978
|
+
* Fetched once per page session and kept in `sessionStorage`, so a reload or
|
|
979
|
+
* "Try again" after a failed callback shows the buttons at once; the server
|
|
980
|
+
* answer always wins. A failure yields the cached list, else `[]`, with
|
|
981
|
+
* `isReady: true`: the email form never waits on, or breaks because of, this
|
|
982
|
+
* list. Ids this client has no adapter for (a newer backend) are dropped.
|
|
983
|
+
*/
|
|
984
|
+
declare const useOAuthProviders: () => UseOAuthProvidersReturn;
|
|
985
|
+
|
|
986
|
+
/** @deprecated Use `UseOAuthLoginOptions`. */
|
|
987
|
+
type UseGithubAuthOptions = UseOAuthLoginOptions;
|
|
988
|
+
/** @deprecated Use `UseOAuthLoginReturn`. */
|
|
861
989
|
interface UseGithubAuthReturn {
|
|
862
990
|
isLoading: boolean;
|
|
863
991
|
error: string | null;
|
|
@@ -865,23 +993,8 @@ interface UseGithubAuthReturn {
|
|
|
865
993
|
handleGithubCallback: (code: string, state: string) => Promise<void>;
|
|
866
994
|
}
|
|
867
995
|
/**
|
|
868
|
-
*
|
|
869
|
-
*
|
|
870
|
-
* Usage:
|
|
871
|
-
* 1. Call startGithubAuth() to redirect user to GitHub
|
|
872
|
-
* 2. After GitHub redirects back, call handleGithubCallback(code, state)
|
|
873
|
-
*
|
|
874
|
-
* @example
|
|
875
|
-
* ```tsx
|
|
876
|
-
* const { isLoading, error, startGithubAuth } = useGithubAuth({
|
|
877
|
-
* onSuccess: (user) => router.push('/dashboard'),
|
|
878
|
-
* onError: (error) => console.error(error),
|
|
879
|
-
* });
|
|
880
|
-
*
|
|
881
|
-
* <Button onClick={startGithubAuth} disabled={isLoading}>
|
|
882
|
-
* Continue with GitHub
|
|
883
|
-
* </Button>
|
|
884
|
-
* ```
|
|
996
|
+
* @deprecated Use `useOAuthLogin` (`start('github')`, `complete('github', code, state)`).
|
|
997
|
+
* Kept for one minor release; behaviour is `useOAuthLogin` with the provider fixed.
|
|
885
998
|
*/
|
|
886
999
|
declare const useGithubAuth: (options?: UseGithubAuthOptions) => UseGithubAuthReturn;
|
|
887
1000
|
|
|
@@ -1416,4 +1529,4 @@ declare const Analytics: {
|
|
|
1416
1529
|
setUser(userId: string | null): void;
|
|
1417
1530
|
};
|
|
1418
1531
|
|
|
1419
|
-
export { AUTH_CONSTANTS, AUTH_ERROR_KEYS, type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AnalyticsSink, type AuthConfig, AuthContext, type AuthContextType, type AuthErrorCopy, type AuthErrorKey, type AuthFormAutoSubmit, type AuthFormReturn, type AuthFormState, type AuthFormStateHandlers, type AuthFormSubmitHandlers, type AuthFormValidation, AuthProvider, type AuthProviderProps, type AuthStep, type DeleteAccountResult, type GuardInput, type OTPRequestConsent, type OTPRequestResult, type PasswordLoginOptions, type PasswordLoginResult, type PatchedCfgUserUpdateRequest, type ProfileCacheOptions, type SessionSnapshot, type SessionStatus, type TwoFactorChallenge, type TwoFactorDevice, type TwoFactorSetupData, type UseAuthFormOptions, type UseAuthFormStateReturn, type UseAutoAuthOptions, type UseDeleteAccountReturn, type UseGithubAuthOptions, type UseGithubAuthReturn, type UseTimezoneReturn, type UseTwoFactorOptions, type UseTwoFactorReturn, type UseTwoFactorSetupOptions, type UseTwoFactorSetupReturn, type UseTwoFactorStatusReturn, type UseTwoFactorVerifyOptions, type UseTwoFactorVerifyReturn, type UserProfile, type WebmailLink, authLogger, beginTwoFactorChallenge, clearProfileCache, consumeSavedRedirect, decodeBase64, encodeBase64, endTwoFactorChallenge, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, isAllowedAuthPath, isForbidden, logAuthFailure, logger, normalizePath, peekSavedRedirect, resolveAuthError, resolveGuardIsAuthenticated, resolveGuardIsLoading, setAnalyticsSink, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useQueryParams, useSession, useSessionStorage, useTimezone, useTwoFactor, useTwoFactorChallenge, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
|
|
1532
|
+
export { AUTH_CONSTANTS, AUTH_ERROR_KEYS, type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AnalyticsSink, type AuthConfig, AuthContext, type AuthContextType, type AuthErrorCopy, type AuthErrorKey, type AuthFormAutoSubmit, type AuthFormReturn, type AuthFormState, type AuthFormStateHandlers, type AuthFormSubmitHandlers, type AuthFormValidation, AuthProvider, type AuthProviderProps, type AuthStep, type DeleteAccountResult, type GuardInput, OAUTH_PROVIDER_IDS, type OAuthClientErrorCode, type OAuthErrorCode, type OAuthFailure, type OAuthFailureCode, type OAuthProviderId, type OAuthUser, type OTPRequestConsent, type OTPRequestResult, type PasswordLoginOptions, type PasswordLoginResult, type PatchedCfgUserUpdateRequest, type ProfileCacheOptions, type SessionSnapshot, type SessionStatus, type TwoFactorChallenge, type TwoFactorDevice, type TwoFactorSetupData, type UseAuthFormOptions, type UseAuthFormStateReturn, type UseAutoAuthOptions, type UseDeleteAccountReturn, type UseGithubAuthOptions, type UseGithubAuthReturn, type UseOAuthLoginOptions, type UseOAuthLoginReturn, type UseOAuthProvidersReturn, type UseTimezoneReturn, type UseTwoFactorOptions, type UseTwoFactorReturn, type UseTwoFactorSetupOptions, type UseTwoFactorSetupReturn, type UseTwoFactorStatusReturn, type UseTwoFactorVerifyOptions, type UseTwoFactorVerifyReturn, type UserProfile, type WebmailLink, authLogger, beginTwoFactorChallenge, clearOAuthAttempt, clearProfileCache, consumeSavedRedirect, decodeBase64, encodeBase64, endTwoFactorChallenge, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, isAllowedAuthPath, isForbidden, isOAuthProviderId, logAuthFailure, logger, normalizePath, peekSavedRedirect, readOAuthFailure, resolveAuthError, resolveGuardIsAuthenticated, resolveGuardIsLoading, setAnalyticsSink, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useOAuthLogin, useOAuthProviders, useQueryParams, useSession, useSessionStorage, useTimezone, useTwoFactor, useTwoFactorChallenge, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
|