capacitor-auth-manager 2.1.0 → 2.3.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/CapacitorAuthManager.podspec +1 -1
- package/Readme.md +223 -103
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthStorage.java +28 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/CapacitorAuthManager.java +109 -15
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/FacebookAuthProvider.java +389 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/GoogleAuthProvider.java +353 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/MicrosoftAuthProvider.java +455 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/ProviderFactory.java +180 -0
- package/dist/angular.cjs.js +7036 -0
- package/dist/angular.cjs.js.map +1 -0
- package/dist/core.cjs.js +2216 -486
- package/dist/core.cjs.js.map +1 -1
- package/dist/esm/angular/auth.guard.d.ts +18 -0
- package/dist/esm/angular/auth.guard.js +82 -0
- package/dist/esm/angular/auth.guard.js.map +1 -0
- package/dist/esm/angular/auth.module.d.ts +18 -0
- package/dist/esm/angular/auth.module.js +56 -0
- package/dist/esm/angular/auth.module.js.map +1 -0
- package/dist/esm/angular/auth.service.d.ts +108 -0
- package/dist/esm/angular/auth.service.js +224 -0
- package/dist/esm/angular/auth.service.js.map +1 -0
- package/dist/esm/angular/index.d.ts +3 -0
- package/dist/esm/angular/index.js +4 -0
- package/dist/esm/angular/index.js.map +1 -0
- package/dist/esm/core/auth-manager.d.ts +61 -1
- package/dist/esm/core/auth-manager.js +285 -24
- package/dist/esm/core/auth-manager.js.map +1 -1
- package/dist/esm/core/platform.d.ts +7 -0
- package/dist/esm/core/platform.js +30 -10
- package/dist/esm/core/platform.js.map +1 -1
- package/dist/esm/core/provider-manifests.d.ts +9 -0
- package/dist/esm/core/provider-manifests.js +471 -0
- package/dist/esm/core/provider-manifests.js.map +1 -0
- package/dist/esm/core/provider-registry.d.ts +19 -1
- package/dist/esm/core/provider-registry.js +72 -480
- package/dist/esm/core/provider-registry.js.map +1 -1
- package/dist/esm/core/types.d.ts +18 -7
- package/dist/esm/definitions.d.ts +42 -1
- package/dist/esm/definitions.js +28 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/providers/base-provider.d.ts +14 -3
- package/dist/esm/providers/base-provider.js +53 -1
- package/dist/esm/providers/base-provider.js.map +1 -1
- package/dist/esm/providers/oauth-provider.d.ts +23 -2
- package/dist/esm/providers/oauth-provider.js +134 -17
- package/dist/esm/providers/oauth-provider.js.map +1 -1
- package/dist/esm/providers/provider-factory.d.ts +3 -1
- package/dist/esm/providers/provider-factory.js +29 -41
- package/dist/esm/providers/provider-factory.js.map +1 -1
- package/dist/esm/providers/web/apple-provider.d.ts +2 -1
- package/dist/esm/providers/web/apple-provider.js +25 -9
- package/dist/esm/providers/web/apple-provider.js.map +1 -1
- package/dist/esm/providers/web/biometric-provider.d.ts +20 -7
- package/dist/esm/providers/web/biometric-provider.js +124 -23
- package/dist/esm/providers/web/biometric-provider.js.map +1 -1
- package/dist/esm/providers/web/email-code-provider.d.ts +46 -0
- package/dist/esm/providers/web/email-code-provider.js +294 -0
- package/dist/esm/providers/web/email-code-provider.js.map +1 -0
- package/dist/esm/providers/web/email-password-provider.d.ts +4 -7
- package/dist/esm/providers/web/email-password-provider.js +38 -38
- package/dist/esm/providers/web/email-password-provider.js.map +1 -1
- package/dist/esm/providers/web/facebook-provider.d.ts +52 -1
- package/dist/esm/providers/web/facebook-provider.js +2 -2
- package/dist/esm/providers/web/facebook-provider.js.map +1 -1
- package/dist/esm/providers/web/firebase-provider.d.ts +5 -3
- package/dist/esm/providers/web/firebase-provider.js +74 -42
- package/dist/esm/providers/web/firebase-provider.js.map +1 -1
- package/dist/esm/providers/web/github-provider.d.ts +9 -0
- package/dist/esm/providers/web/github-provider.js +91 -14
- package/dist/esm/providers/web/github-provider.js.map +1 -1
- package/dist/esm/providers/web/index.d.ts +2 -0
- package/dist/esm/providers/web/index.js +2 -0
- package/dist/esm/providers/web/index.js.map +1 -1
- package/dist/esm/providers/web/linkedin-provider.d.ts +2 -3
- package/dist/esm/providers/web/linkedin-provider.js +40 -14
- package/dist/esm/providers/web/linkedin-provider.js.map +1 -1
- package/dist/esm/providers/web/magic-link-provider.d.ts +4 -6
- package/dist/esm/providers/web/magic-link-provider.js +49 -36
- package/dist/esm/providers/web/magic-link-provider.js.map +1 -1
- package/dist/esm/providers/web/microsoft-provider.d.ts +2 -0
- package/dist/esm/providers/web/microsoft-provider.js +45 -20
- package/dist/esm/providers/web/microsoft-provider.js.map +1 -1
- package/dist/esm/providers/web/phone-password-provider.d.ts +63 -0
- package/dist/esm/providers/web/phone-password-provider.js +440 -0
- package/dist/esm/providers/web/phone-password-provider.js.map +1 -0
- package/dist/esm/providers/web/slack-provider.d.ts +2 -3
- package/dist/esm/providers/web/slack-provider.js +38 -14
- package/dist/esm/providers/web/slack-provider.js.map +1 -1
- package/dist/esm/providers/web/sms-provider.d.ts +4 -6
- package/dist/esm/providers/web/sms-provider.js +33 -28
- package/dist/esm/providers/web/sms-provider.js.map +1 -1
- package/dist/esm/providers/web/username-password-provider.d.ts +4 -7
- package/dist/esm/providers/web/username-password-provider.js +32 -30
- package/dist/esm/providers/web/username-password-provider.js.map +1 -1
- package/dist/esm/react/hooks.d.ts +110 -0
- package/dist/esm/react/hooks.js +307 -0
- package/dist/esm/react/hooks.js.map +1 -0
- package/dist/esm/react/index.d.ts +2 -0
- package/dist/esm/react/index.js +3 -0
- package/dist/esm/react/index.js.map +1 -0
- package/dist/esm/react/types.d.ts +30 -0
- package/dist/esm/react/types.js +2 -0
- package/dist/esm/react/types.js.map +1 -0
- package/dist/esm/utils/auth-error.d.ts +7 -0
- package/dist/esm/utils/auth-error.js +31 -5
- package/dist/esm/utils/auth-error.js.map +1 -1
- package/dist/esm/utils/event-emitter.d.ts +7 -0
- package/dist/esm/utils/event-emitter.js +8 -2
- package/dist/esm/utils/event-emitter.js.map +1 -1
- package/dist/esm/utils/logger.d.ts +28 -1
- package/dist/esm/utils/logger.js +115 -1
- package/dist/esm/utils/logger.js.map +1 -1
- package/dist/esm/utils/pending-verification-store.d.ts +59 -0
- package/dist/esm/utils/pending-verification-store.js +103 -0
- package/dist/esm/utils/pending-verification-store.js.map +1 -0
- package/dist/esm/utils/storage.d.ts +29 -1
- package/dist/esm/utils/storage.js +64 -5
- package/dist/esm/utils/storage.js.map +1 -1
- package/dist/esm/vue/composables.d.ts +124 -0
- package/dist/esm/vue/composables.js +290 -0
- package/dist/esm/vue/composables.js.map +1 -0
- package/dist/esm/vue/index.d.ts +1 -0
- package/dist/esm/vue/index.js +2 -0
- package/dist/esm/vue/index.js.map +1 -0
- package/dist/esm/web.d.ts +32 -7
- package/dist/esm/web.js +247 -52
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +2674 -719
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +2674 -719
- package/dist/plugin.js.map +1 -1
- package/dist/react.cjs.js +6991 -0
- package/dist/react.cjs.js.map +1 -0
- package/dist/vue.cjs.js +6974 -0
- package/dist/vue.cjs.js.map +1 -0
- package/ios/Plugin/AppleAuthProvider.swift +288 -0
- package/ios/Plugin/AuthStorage.swift +49 -1
- package/ios/Plugin/CapacitorAuthManager.swift +45 -23
- package/ios/Plugin/FacebookAuthProvider.swift +297 -0
- package/ios/Plugin/GitHubAuthProvider.swift +54 -0
- package/ios/Plugin/GoogleAuthProvider.swift +265 -0
- package/ios/Plugin/LinkedInAuthProvider.swift +63 -0
- package/ios/Plugin/MicrosoftAuthProvider.swift +315 -0
- package/ios/Plugin/Models.swift +4 -1
- package/ios/Plugin/OAuthWebProvider.swift +415 -0
- package/ios/Plugin/SlackAuthProvider.swift +108 -0
- package/package.json +61 -40
package/dist/esm/core/types.d.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import type { AuthUser, AuthResult } from '../definitions';
|
|
1
|
+
import type { AuthUser, AuthResult, SignInOptions, SignOutOptions, RefreshTokenOptions, LinkAccountOptions, UnlinkAccountOptions, ProviderOptions } from '../definitions';
|
|
2
|
+
import type { StorageInterface } from '../utils/storage';
|
|
2
3
|
export interface AuthManagerConfig {
|
|
3
|
-
providers?: Record<string,
|
|
4
|
+
providers?: Record<string, ProviderOptions>;
|
|
4
5
|
persistence?: 'local' | 'session' | 'memory';
|
|
5
6
|
autoRefreshToken?: boolean;
|
|
6
7
|
tokenRefreshBuffer?: number;
|
|
7
8
|
enableLogging?: boolean;
|
|
8
9
|
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
10
|
+
/**
|
|
11
|
+
* Custom storage backend. Web tokens otherwise live in localStorage (readable by any XSS /
|
|
12
|
+
* third-party script on the origin). On native, inject a secure implementation —
|
|
13
|
+
* `CapacitorPreferencesStorage` (from this package) or a Keychain/Keystore-backed adapter —
|
|
14
|
+
* to keep tokens out of the webview's localStorage.
|
|
15
|
+
*/
|
|
16
|
+
storage?: StorageInterface;
|
|
9
17
|
}
|
|
10
18
|
export interface AuthState {
|
|
11
19
|
user: AuthUser | null;
|
|
@@ -16,13 +24,16 @@ export interface AuthState {
|
|
|
16
24
|
export type AuthStateListener = (state: AuthState) => void;
|
|
17
25
|
export interface AuthProviderInterface {
|
|
18
26
|
name: string;
|
|
19
|
-
signIn(options?:
|
|
20
|
-
signOut(options?:
|
|
27
|
+
signIn(options?: SignInOptions): Promise<AuthResult>;
|
|
28
|
+
signOut(options?: SignOutOptions): Promise<void>;
|
|
21
29
|
getCurrentUser(): Promise<AuthUser | null>;
|
|
22
|
-
refreshToken?(options?:
|
|
30
|
+
refreshToken?(options?: RefreshTokenOptions): Promise<AuthResult>;
|
|
23
31
|
isSupported(): Promise<boolean>;
|
|
24
|
-
initialize?(config
|
|
32
|
+
initialize?(config?: ProviderOptions): Promise<void>;
|
|
25
33
|
dispose?(): void;
|
|
34
|
+
linkAccount?(options?: LinkAccountOptions): Promise<AuthResult>;
|
|
35
|
+
unlinkAccount?(options?: UnlinkAccountOptions): Promise<void>;
|
|
36
|
+
revokeAccess?(token?: string): Promise<void>;
|
|
26
37
|
}
|
|
27
38
|
export interface ProviderManifest {
|
|
28
39
|
name: string;
|
|
@@ -30,6 +41,6 @@ export interface ProviderManifest {
|
|
|
30
41
|
packageName?: string;
|
|
31
42
|
importPath?: string;
|
|
32
43
|
setupInstructions?: string;
|
|
33
|
-
configSchema?: Record<string,
|
|
44
|
+
configSchema?: Record<string, unknown>;
|
|
34
45
|
platforms?: ('web' | 'ios' | 'android' | 'electron')[];
|
|
35
46
|
}
|
|
@@ -142,6 +142,17 @@ export interface GitHubAuthOptions {
|
|
|
142
142
|
allowSignup?: boolean;
|
|
143
143
|
login?: string;
|
|
144
144
|
state?: string;
|
|
145
|
+
/**
|
|
146
|
+
* URL of a backend endpoint that exchanges the GitHub authorization `code` for an access
|
|
147
|
+
* token. GitHub does NOT allow browser-side code→token exchange (it requires the client
|
|
148
|
+
* secret and blocks CORS), so a server-side proxy is required to complete sign-in. The
|
|
149
|
+
* proxy receives `{ code, redirectUri, state }` (POST, JSON) and must return GitHub's
|
|
150
|
+
* token JSON (`{ access_token, token_type, scope, ... }`). Alias: `tokenEndpoint`.
|
|
151
|
+
* @see https://docs.github.com/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps
|
|
152
|
+
*/
|
|
153
|
+
tokenExchangeProxy?: string;
|
|
154
|
+
/** Alias for {@link tokenExchangeProxy}. */
|
|
155
|
+
tokenEndpoint?: string;
|
|
145
156
|
}
|
|
146
157
|
export interface SlackAuthOptions {
|
|
147
158
|
clientId: string;
|
|
@@ -170,6 +181,11 @@ export interface FirebaseAuthOptions {
|
|
|
170
181
|
tenantId?: string;
|
|
171
182
|
persistence?: 'local' | 'session' | 'none';
|
|
172
183
|
enableMultiTabSupport?: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Default Firebase sign-in sub-method used when `signIn` is called without an explicit
|
|
186
|
+
* method and no email/password credentials are supplied. Defaults to `'google'`.
|
|
187
|
+
*/
|
|
188
|
+
defaultMethod?: 'google' | 'facebook' | 'github' | 'microsoft' | 'apple' | 'email' | 'anonymous';
|
|
173
189
|
}
|
|
174
190
|
export interface EmailMagicLinkOptions {
|
|
175
191
|
endpoint?: string;
|
|
@@ -552,5 +568,30 @@ export declare enum AuthErrorCode {
|
|
|
552
568
|
INVALID_SCOPE = "auth/invalid-scope",
|
|
553
569
|
CLIENT_NOT_FOUND = "auth/client-not-found",
|
|
554
570
|
MISSING_CONFIG = "auth/missing-config",
|
|
555
|
-
PROVIDER_NOT_INITIALIZED = "auth/provider-not-initialized"
|
|
571
|
+
PROVIDER_NOT_INITIALIZED = "auth/provider-not-initialized",
|
|
572
|
+
CREDENTIALS_REQUIRED = "auth/credentials-required",
|
|
573
|
+
EMAIL_REQUIRED = "auth/email-required",
|
|
574
|
+
PHONE_REQUIRED = "auth/phone-required",
|
|
575
|
+
USERNAME_REQUIRED = "auth/username-required",
|
|
576
|
+
INVALID_USERNAME = "auth/invalid-username",
|
|
577
|
+
USERNAME_ALREADY_EXISTS = "auth/username-already-exists",
|
|
578
|
+
INVALID_CODE = "auth/invalid-code",
|
|
579
|
+
CODE_EXPIRED = "auth/code-expired",
|
|
580
|
+
INVALID_TOKEN = "auth/invalid-token",
|
|
581
|
+
NO_PENDING_VERIFICATION = "auth/no-pending-verification",
|
|
582
|
+
TOO_MANY_ATTEMPTS = "auth/too-many-attempts",
|
|
583
|
+
RESEND_DELAY = "auth/resend-delay",
|
|
584
|
+
SEND_CODE_FAILED = "auth/send-code-failed",
|
|
585
|
+
SEND_LINK_FAILED = "auth/send-link-failed",
|
|
586
|
+
VERIFICATION_FAILED = "auth/verification-failed",
|
|
587
|
+
SIGN_UP_FAILED = "auth/sign-up-failed",
|
|
588
|
+
SIGN_UP_DISABLED = "auth/sign-up-disabled",
|
|
589
|
+
NO_REFRESH_TOKEN = "auth/no-refresh-token",
|
|
590
|
+
NOT_AUTHENTICATED = "auth/not-authenticated",
|
|
591
|
+
PHONE_NOT_VERIFIED = "auth/phone-not-verified",
|
|
592
|
+
EMAIL_ALREADY_VERIFIED = "auth/email-already-verified",
|
|
593
|
+
NO_STORED_CREDENTIALS = "auth/no-stored-credentials",
|
|
594
|
+
STORAGE_ERROR = "auth/storage-error",
|
|
595
|
+
BIOMETRIC_LOCKOUT = "auth/biometric-lockout",
|
|
596
|
+
PROVIDER_UNSUPPORTED_OPERATION = "auth/provider-unsupported-operation"
|
|
556
597
|
}
|
package/dist/esm/definitions.js
CHANGED
|
@@ -110,5 +110,33 @@ export var AuthErrorCode;
|
|
|
110
110
|
AuthErrorCode["CLIENT_NOT_FOUND"] = "auth/client-not-found";
|
|
111
111
|
AuthErrorCode["MISSING_CONFIG"] = "auth/missing-config";
|
|
112
112
|
AuthErrorCode["PROVIDER_NOT_INITIALIZED"] = "auth/provider-not-initialized";
|
|
113
|
+
// --- Added in 2.2.0 (additive, non-breaking) so standalone providers (sms / email-code /
|
|
114
|
+
// magic-link / biometric / email-password / username-password / phone-password) throw enum
|
|
115
|
+
// codes instead of bare string literals. Consumers can now switch on `error.code` reliably.
|
|
116
|
+
AuthErrorCode["CREDENTIALS_REQUIRED"] = "auth/credentials-required";
|
|
117
|
+
AuthErrorCode["EMAIL_REQUIRED"] = "auth/email-required";
|
|
118
|
+
AuthErrorCode["PHONE_REQUIRED"] = "auth/phone-required";
|
|
119
|
+
AuthErrorCode["USERNAME_REQUIRED"] = "auth/username-required";
|
|
120
|
+
AuthErrorCode["INVALID_USERNAME"] = "auth/invalid-username";
|
|
121
|
+
AuthErrorCode["USERNAME_ALREADY_EXISTS"] = "auth/username-already-exists";
|
|
122
|
+
AuthErrorCode["INVALID_CODE"] = "auth/invalid-code";
|
|
123
|
+
AuthErrorCode["CODE_EXPIRED"] = "auth/code-expired";
|
|
124
|
+
AuthErrorCode["INVALID_TOKEN"] = "auth/invalid-token";
|
|
125
|
+
AuthErrorCode["NO_PENDING_VERIFICATION"] = "auth/no-pending-verification";
|
|
126
|
+
AuthErrorCode["TOO_MANY_ATTEMPTS"] = "auth/too-many-attempts";
|
|
127
|
+
AuthErrorCode["RESEND_DELAY"] = "auth/resend-delay";
|
|
128
|
+
AuthErrorCode["SEND_CODE_FAILED"] = "auth/send-code-failed";
|
|
129
|
+
AuthErrorCode["SEND_LINK_FAILED"] = "auth/send-link-failed";
|
|
130
|
+
AuthErrorCode["VERIFICATION_FAILED"] = "auth/verification-failed";
|
|
131
|
+
AuthErrorCode["SIGN_UP_FAILED"] = "auth/sign-up-failed";
|
|
132
|
+
AuthErrorCode["SIGN_UP_DISABLED"] = "auth/sign-up-disabled";
|
|
133
|
+
AuthErrorCode["NO_REFRESH_TOKEN"] = "auth/no-refresh-token";
|
|
134
|
+
AuthErrorCode["NOT_AUTHENTICATED"] = "auth/not-authenticated";
|
|
135
|
+
AuthErrorCode["PHONE_NOT_VERIFIED"] = "auth/phone-not-verified";
|
|
136
|
+
AuthErrorCode["EMAIL_ALREADY_VERIFIED"] = "auth/email-already-verified";
|
|
137
|
+
AuthErrorCode["NO_STORED_CREDENTIALS"] = "auth/no-stored-credentials";
|
|
138
|
+
AuthErrorCode["STORAGE_ERROR"] = "auth/storage-error";
|
|
139
|
+
AuthErrorCode["BIOMETRIC_LOCKOUT"] = "auth/biometric-lockout";
|
|
140
|
+
AuthErrorCode["PROVIDER_UNSUPPORTED_OPERATION"] = "auth/provider-unsupported-operation";
|
|
113
141
|
})(AuthErrorCode || (AuthErrorCode = {}));
|
|
114
142
|
//# sourceMappingURL=definitions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AA2CA,MAAM,CAAN,IAAY,YAiBX;AAjBD,WAAY,YAAY;IACtB,iCAAiB,CAAA;IACjB,+BAAe,CAAA;IACf,uCAAuB,CAAA;IACvB,qCAAqB,CAAA;IACrB,iCAAiB,CAAA;IACjB,+BAAe,CAAA;IACf,qCAAqB,CAAA;IACrB,qCAAqB,CAAA;IACrB,qDAAqC,CAAA;IACrC,yCAAyB,CAAA;IACzB,2BAAW,CAAA;IACX,iDAAiC,CAAA;IACjC,iDAAiC,CAAA;IACjC,uDAAuC,CAAA;IACvC,yCAAyB,CAAA;IACzB,uCAAuB,CAAA;AACzB,CAAC,EAjBW,YAAY,KAAZ,YAAY,QAiBvB;AAED,wDAAwD;AACxD,MAAM,CAAC,MAAM,cAAc,GAAG,gCACzB,YAAY,KACf,YAAY,EAAE,YAAY,CAAC,UAAU,EACrC,gBAAgB,EAAE,YAAY,CAAC,cAAc,EAC7C,GAAG,EAAE,YAAY,CAAC,GAAG,EACrB,SAAS,EAAE,YAAY,CAAC,SAAS,GACzB,CAAC;AA6CX,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,iCAAe,CAAA;IACf,+BAAa,CAAA;AACf,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AA2CA,MAAM,CAAN,IAAY,YAiBX;AAjBD,WAAY,YAAY;IACtB,iCAAiB,CAAA;IACjB,+BAAe,CAAA;IACf,uCAAuB,CAAA;IACvB,qCAAqB,CAAA;IACrB,iCAAiB,CAAA;IACjB,+BAAe,CAAA;IACf,qCAAqB,CAAA;IACrB,qCAAqB,CAAA;IACrB,qDAAqC,CAAA;IACrC,yCAAyB,CAAA;IACzB,2BAAW,CAAA;IACX,iDAAiC,CAAA;IACjC,iDAAiC,CAAA;IACjC,uDAAuC,CAAA;IACvC,yCAAyB,CAAA;IACzB,uCAAuB,CAAA;AACzB,CAAC,EAjBW,YAAY,KAAZ,YAAY,QAiBvB;AAED,wDAAwD;AACxD,MAAM,CAAC,MAAM,cAAc,GA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C,2DAA0C,CAAA;IAC1C,iEAAgD,CAAA;IAChD,uDAAsC,CAAA;IACtC,2DAA0C,CAAA;IAC1C,2DAA0C,CAAA;IAC1C,6DAA4C,CAAA;IAC5C,+DAA8C,CAAA;IAC9C,uEAAsD,CAAA;IACtD,qEAAoD,CAAA;IACpD,qDAAoC,CAAA;IACpC,6DAA4C,CAAA;IAC5C,uFAAsE,CAAA;AACxE,CAAC,EAnGW,aAAa,KAAb,aAAa,QAmGxB"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -3,6 +3,10 @@ export type { AuthManagerConfig, AuthState, AuthStateListener, AuthProviderInter
|
|
|
3
3
|
export { AuthUser, UserInfo, UserMetadata, AuthResult, AuthCredential, AdditionalUserInfo, SignInOptions, SignOutOptions, AuthProvider, AuthErrorCode, AuthPersistence, ProviderOptions, RefreshTokenOptions, LinkAccountOptions, UnlinkAccountOptions, AuthStateChangeCallback, GetIdTokenOptions, UpdateProfileOptions, BiometricAuthOptions, BiometricType, AppleAuthScope, PasswordStrengthRequirements, UsernameRequirements, AuthCredentials, } from './definitions';
|
|
4
4
|
export { PlatformDetector } from './core/platform';
|
|
5
5
|
export type { Platform, PlatformInfo } from './core/platform';
|
|
6
|
+
export { WebStorage, CapacitorPreferencesStorage } from './utils/storage';
|
|
7
|
+
export type { StorageInterface } from './utils/storage';
|
|
6
8
|
export { AuthError, isAuthError } from './utils/auth-error';
|
|
9
|
+
export { Logger, defaultLogger } from './utils/logger';
|
|
10
|
+
export type { LogLevel, LoggerConfig } from './utils/logger';
|
|
7
11
|
export { CapacitorAuthManager } from './capacitor-plugin';
|
|
8
12
|
export type { CapacitorAuthManagerPlugin } from './definitions';
|
package/dist/esm/index.js
CHANGED
|
@@ -3,8 +3,14 @@ export { auth } from './core/auth-manager';
|
|
|
3
3
|
// Re-export shared types from definitions (these are used by both old and new API)
|
|
4
4
|
export { AuthProvider, AuthErrorCode, AuthPersistence, BiometricType, AppleAuthScope, } from './definitions';
|
|
5
5
|
export { PlatformDetector } from './core/platform';
|
|
6
|
+
// Storage backends. Inject a secure implementation on native via
|
|
7
|
+
// auth.configure({ storage: new CapacitorPreferencesStorage() }) or your own StorageInterface.
|
|
8
|
+
export { WebStorage, CapacitorPreferencesStorage } from './utils/storage';
|
|
6
9
|
// Error handling
|
|
7
10
|
export { AuthError, isAuthError } from './utils/auth-error';
|
|
11
|
+
// Logger — the shared default instance internals use, plus the class. Adjust verbosity with
|
|
12
|
+
// `defaultLogger.setLevel('debug')` or build-time `VITE_LOG_LEVEL` / `LOG_LEVEL`.
|
|
13
|
+
export { Logger, defaultLogger } from './utils/logger';
|
|
8
14
|
// For backward compatibility with Capacitor plugin interface
|
|
9
15
|
export { CapacitorAuthManager } from './capacitor-plugin';
|
|
10
16
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAW3C,mFAAmF;AACnF,OAAO,EASL,YAAY,EACZ,aAAa,EACb,eAAe,EASf,aAAa,EACb,cAAc,GAIf,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGnD,iBAAiB;AACjB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE5D,6DAA6D;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAW3C,mFAAmF;AACnF,OAAO,EASL,YAAY,EACZ,aAAa,EACb,eAAe,EASf,aAAa,EACb,cAAc,GAIf,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGnD,iEAAiE;AACjE,+FAA+F;AAC/F,OAAO,EAAE,UAAU,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAG1E,iBAAiB;AACjB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE5D,4FAA4F;AAC5F,kFAAkF;AAClF,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGvD,6DAA6D;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -10,6 +10,17 @@ export interface BaseProviderConfig {
|
|
|
10
10
|
logger: Logger;
|
|
11
11
|
persistence?: AuthPersistence;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Normalize a provider constructor argument into a full {@link BaseProviderConfig}.
|
|
15
|
+
*
|
|
16
|
+
* The standalone providers are public (exported from `capacitor-auth-manager/providers/web`) and
|
|
17
|
+
* get constructed two ways: the factory/registry pass a full {@link BaseProviderConfig}, while
|
|
18
|
+
* tests and direct consumers pass the provider's own bare options object. This helper accepts
|
|
19
|
+
* either — a bare object is wrapped with an in-memory storage (`AuthPersistence.NONE`, so it never
|
|
20
|
+
* touches `window` and stays safe under SSR / Node test environments) plus the shared
|
|
21
|
+
* {@link defaultLogger}. Callers that pass a full config keep their injected storage/logger.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveProviderConfig(provider: AuthProvider, input?: unknown): BaseProviderConfig;
|
|
13
24
|
export declare abstract class BaseAuthProvider implements AuthProviderInterface {
|
|
14
25
|
protected provider: AuthProvider;
|
|
15
26
|
protected options: ProviderOptions;
|
|
@@ -26,9 +37,9 @@ export declare abstract class BaseAuthProvider implements AuthProviderInterface
|
|
|
26
37
|
abstract signOut(options?: SignOutOptions): Promise<void>;
|
|
27
38
|
abstract refreshToken(options?: RefreshTokenOptions): Promise<AuthResult>;
|
|
28
39
|
abstract isSupported(): Promise<boolean>;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
linkAccount(_options: LinkAccountOptions): Promise<AuthResult>;
|
|
41
|
+
unlinkAccount(_options: UnlinkAccountOptions): Promise<void>;
|
|
42
|
+
revokeAccess(_token?: string): Promise<void>;
|
|
32
43
|
getCurrentUser(): Promise<AuthUser | null>;
|
|
33
44
|
addAuthStateListener(callback: AuthStateChangeCallback): UnsubscribeFn;
|
|
34
45
|
protected setCurrentUser(user: AuthUser | null): Promise<void>;
|
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
import { AuthErrorCode, AuthPersistence, } from '../definitions';
|
|
2
2
|
import { AuthError } from '../utils/auth-error';
|
|
3
3
|
import { EventEmitter } from '../utils/event-emitter';
|
|
4
|
+
import { WebStorage } from '../utils/storage';
|
|
5
|
+
import { defaultLogger } from '../utils/logger';
|
|
6
|
+
/**
|
|
7
|
+
* Normalize a provider constructor argument into a full {@link BaseProviderConfig}.
|
|
8
|
+
*
|
|
9
|
+
* The standalone providers are public (exported from `capacitor-auth-manager/providers/web`) and
|
|
10
|
+
* get constructed two ways: the factory/registry pass a full {@link BaseProviderConfig}, while
|
|
11
|
+
* tests and direct consumers pass the provider's own bare options object. This helper accepts
|
|
12
|
+
* either — a bare object is wrapped with an in-memory storage (`AuthPersistence.NONE`, so it never
|
|
13
|
+
* touches `window` and stays safe under SSR / Node test environments) plus the shared
|
|
14
|
+
* {@link defaultLogger}. Callers that pass a full config keep their injected storage/logger.
|
|
15
|
+
*/
|
|
16
|
+
export function resolveProviderConfig(provider, input) {
|
|
17
|
+
if (typeof input === 'object' &&
|
|
18
|
+
input !== null &&
|
|
19
|
+
'storage' in input &&
|
|
20
|
+
'logger' in input &&
|
|
21
|
+
'options' in input) {
|
|
22
|
+
return input;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
provider,
|
|
26
|
+
options: (input !== null && input !== void 0 ? input : {}),
|
|
27
|
+
storage: new WebStorage(AuthPersistence.NONE),
|
|
28
|
+
logger: defaultLogger,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
4
31
|
export class BaseAuthProvider {
|
|
5
32
|
get name() {
|
|
6
33
|
return this.provider;
|
|
@@ -15,6 +42,19 @@ export class BaseAuthProvider {
|
|
|
15
42
|
this.persistence = config.persistence || AuthPersistence.LOCAL;
|
|
16
43
|
this.authStateEmitter = new EventEmitter();
|
|
17
44
|
}
|
|
45
|
+
// Capability methods with concrete defaults: providers that support these operations override
|
|
46
|
+
// them; the rest inherit a uniform "not allowed" signal so capability detection is consistent
|
|
47
|
+
// across every provider (see AuthProviderInterface, where they are optional). Marking them
|
|
48
|
+
// abstract previously forced every subclass to re-implement them just to throw.
|
|
49
|
+
async linkAccount(_options) {
|
|
50
|
+
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Account linking is not supported by provider ${this.provider}`, this.provider);
|
|
51
|
+
}
|
|
52
|
+
async unlinkAccount(_options) {
|
|
53
|
+
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Account unlinking is not supported by provider ${this.provider}`, this.provider);
|
|
54
|
+
}
|
|
55
|
+
async revokeAccess(_token) {
|
|
56
|
+
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Access revocation is not supported by provider ${this.provider}`, this.provider);
|
|
57
|
+
}
|
|
18
58
|
async getCurrentUser() {
|
|
19
59
|
if (!this.isInitialized) {
|
|
20
60
|
await this.initialize();
|
|
@@ -92,7 +132,19 @@ export class BaseAuthProvider {
|
|
|
92
132
|
};
|
|
93
133
|
}
|
|
94
134
|
generateUniqueId() {
|
|
95
|
-
|
|
135
|
+
// Cryptographically-strong identifier (uid fallback when a provider returns no stable sub).
|
|
136
|
+
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
|
137
|
+
return crypto.randomUUID();
|
|
138
|
+
}
|
|
139
|
+
const bytes = new Uint8Array(16);
|
|
140
|
+
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
|
141
|
+
crypto.getRandomValues(bytes);
|
|
142
|
+
}
|
|
143
|
+
let hex = '';
|
|
144
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
145
|
+
hex += bytes[i].toString(16).padStart(2, '0');
|
|
146
|
+
}
|
|
147
|
+
return `${Date.now()}-${hex}`;
|
|
96
148
|
}
|
|
97
149
|
isTokenExpired(expiresAt) {
|
|
98
150
|
if (!expiresAt)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-provider.js","sourceRoot":"","sources":["../../../src/providers/base-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,aAAa,EAIb,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAiB,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"base-provider.js","sourceRoot":"","sources":["../../../src/providers/base-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,aAAa,EAIb,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAiB,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAoB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAU,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAWxD;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAAsB,EACtB,KAAe;IAEf,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QAClB,QAAQ,IAAI,KAAK;QACjB,SAAS,IAAI,KAAK,EAClB,CAAC;QACD,OAAO,KAA2B,CAAC;IACrC,CAAC;IACD,OAAO;QACL,QAAQ;QACR,OAAO,EAAE,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,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,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAC9B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -24,6 +24,11 @@ export interface OAuthUserInfo {
|
|
|
24
24
|
}
|
|
25
25
|
export interface OAuthConfig {
|
|
26
26
|
clientId: string;
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Do NOT set a client secret in browser-facing config — it ships in the JS
|
|
29
|
+
* bundle and is fully recoverable by end users. Use a backend token-exchange proxy
|
|
30
|
+
* (point `tokenEndpoint` at your server). Retained only for native/server-side use.
|
|
31
|
+
*/
|
|
27
32
|
clientSecret?: string;
|
|
28
33
|
redirectUri: string;
|
|
29
34
|
authorizationEndpoint: string;
|
|
@@ -34,12 +39,14 @@ export interface OAuthConfig {
|
|
|
34
39
|
responseType?: string;
|
|
35
40
|
grantType?: string;
|
|
36
41
|
additionalParams?: Record<string, string>;
|
|
42
|
+
/** Enable PKCE (RFC 7636) for the authorization-code flow. Defaults to true. */
|
|
43
|
+
pkceEnabled?: boolean;
|
|
37
44
|
}
|
|
38
45
|
export declare abstract class OAuthProvider extends BaseAuthProvider {
|
|
39
46
|
protected abstract getOAuthConfig(): OAuthConfig;
|
|
40
47
|
protected abstract parseUserFromTokenResponse(response: OAuthTokenResponse): Promise<OAuthUserInfo>;
|
|
41
48
|
protected performOAuthFlow(options?: SignInOptions): Promise<AuthResult>;
|
|
42
|
-
protected buildAuthorizationUrl(config: OAuthConfig, state: string, nonce: string, options?: SignInOptions): string;
|
|
49
|
+
protected buildAuthorizationUrl(config: OAuthConfig, state: string, nonce: string, options?: SignInOptions, codeChallenge?: string): string;
|
|
43
50
|
protected abstract openAuthorizationUrl(url: string): Promise<{
|
|
44
51
|
code?: string;
|
|
45
52
|
state?: string;
|
|
@@ -51,11 +58,25 @@ export declare abstract class OAuthProvider extends BaseAuthProvider {
|
|
|
51
58
|
error?: string;
|
|
52
59
|
error_description?: string;
|
|
53
60
|
}, expectedState: string, _expectedNonce: string): Promise<void>;
|
|
54
|
-
protected exchangeCodeForTokens(code: string, config: OAuthConfig): Promise<OAuthTokenResponse>;
|
|
61
|
+
protected exchangeCodeForTokens(code: string, config: OAuthConfig, codeVerifier?: string): Promise<OAuthTokenResponse>;
|
|
55
62
|
refreshToken(_options?: RefreshTokenOptions): Promise<AuthResult>;
|
|
56
63
|
revokeAccess(token?: string): Promise<void>;
|
|
57
64
|
protected createOAuthCredential(tokenResponse: OAuthTokenResponse): AuthCredential;
|
|
58
65
|
protected createAuthUser(userInfo: OAuthUserInfo, tokenResponse: OAuthTokenResponse): AuthUser;
|
|
59
66
|
protected mapOAuthError(error: string): AuthErrorCode;
|
|
60
67
|
protected generateSecureRandomString(length?: number): string;
|
|
68
|
+
/** RFC 7636 PKCE code verifier: 64 chars from the unreserved set [A-Za-z0-9]. */
|
|
69
|
+
protected generateCodeVerifier(): string;
|
|
70
|
+
/** Derives the S256 PKCE code challenge: base64url(SHA-256(verifier)). */
|
|
71
|
+
protected generateCodeChallenge(verifier: string): Promise<string>;
|
|
72
|
+
protected base64UrlEncode(bytes: Uint8Array): string;
|
|
73
|
+
/** Decodes a JWT payload without verifying the signature. Returns null if malformed. */
|
|
74
|
+
protected decodeJwtPayload(token: string): Record<string, unknown> | null;
|
|
75
|
+
/**
|
|
76
|
+
* Validates the ID token's nonce (replay protection) and expiry. The signature is NOT
|
|
77
|
+
* verified client-side — always re-validate ID tokens on your backend before trusting them.
|
|
78
|
+
*/
|
|
79
|
+
protected validateIdToken(idToken: string | undefined, expectedNonce: string): void;
|
|
80
|
+
protected warnClientSecretInBrowser(): void;
|
|
81
|
+
protected assertSecureEndpoint(url: string): void;
|
|
61
82
|
}
|
|
@@ -8,11 +8,26 @@ export class OAuthProvider extends BaseAuthProvider {
|
|
|
8
8
|
// Generate state and nonce for security
|
|
9
9
|
const state = this.generateSecureRandomString();
|
|
10
10
|
const nonce = this.generateSecureRandomString();
|
|
11
|
-
//
|
|
11
|
+
// PKCE (RFC 7636) — default on; requires Web Crypto 'subtle' (HTTPS / localhost).
|
|
12
|
+
let codeVerifier;
|
|
13
|
+
let codeChallenge;
|
|
14
|
+
if (config.pkceEnabled !== false) {
|
|
15
|
+
if (typeof crypto !== 'undefined' && crypto.subtle) {
|
|
16
|
+
codeVerifier = this.generateCodeVerifier();
|
|
17
|
+
codeChallenge = await this.generateCodeChallenge(codeVerifier);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
this.logger.warn(`PKCE skipped for ${this.provider}: Web Crypto 'subtle' is unavailable (insecure context). Serve over HTTPS to enable PKCE.`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Store state, nonce, and PKCE verifier for validation
|
|
12
24
|
await this.storage.set(`${this.provider}_oauth_state`, state);
|
|
13
25
|
await this.storage.set(`${this.provider}_oauth_nonce`, nonce);
|
|
26
|
+
if (codeVerifier) {
|
|
27
|
+
await this.storage.set(`${this.provider}_oauth_verifier`, codeVerifier);
|
|
28
|
+
}
|
|
14
29
|
// Build authorization URL
|
|
15
|
-
const authUrl = this.buildAuthorizationUrl(config, state, nonce, options);
|
|
30
|
+
const authUrl = this.buildAuthorizationUrl(config, state, nonce, options, codeChallenge);
|
|
16
31
|
// Perform the OAuth flow (platform-specific implementation)
|
|
17
32
|
const authResponse = await this.openAuthorizationUrl(authUrl);
|
|
18
33
|
// Validate response
|
|
@@ -21,7 +36,10 @@ export class OAuthProvider extends BaseAuthProvider {
|
|
|
21
36
|
if (!authResponse.code) {
|
|
22
37
|
throw new AuthError(AuthErrorCode.INVALID_GRANT, 'No authorization code received', this.provider);
|
|
23
38
|
}
|
|
24
|
-
const tokenResponse = await this.exchangeCodeForTokens(authResponse.code, config);
|
|
39
|
+
const tokenResponse = await this.exchangeCodeForTokens(authResponse.code, config, codeVerifier);
|
|
40
|
+
// Validate the ID token's nonce + expiry (replay protection). NOTE: the signature is
|
|
41
|
+
// NOT verified client-side — always re-validate ID tokens on your backend.
|
|
42
|
+
this.validateIdToken(tokenResponse.id_token, nonce);
|
|
25
43
|
// Parse user information
|
|
26
44
|
const userInfo = await this.parseUserFromTokenResponse(tokenResponse);
|
|
27
45
|
// Create AuthUser and AuthCredential
|
|
@@ -40,31 +58,47 @@ export class OAuthProvider extends BaseAuthProvider {
|
|
|
40
58
|
// Clean up temporary storage
|
|
41
59
|
await this.storage.remove(`${this.provider}_oauth_state`);
|
|
42
60
|
await this.storage.remove(`${this.provider}_oauth_nonce`);
|
|
61
|
+
await this.storage.remove(`${this.provider}_oauth_verifier`);
|
|
43
62
|
}
|
|
44
63
|
}
|
|
45
|
-
buildAuthorizationUrl(config, state, nonce, options) {
|
|
64
|
+
buildAuthorizationUrl(config, state, nonce, options, codeChallenge) {
|
|
46
65
|
var _a, _b, _c, _d;
|
|
47
|
-
const params = new URLSearchParams(
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
const params = new URLSearchParams();
|
|
67
|
+
// Developer-supplied params FIRST, so the security-critical params set below cannot be
|
|
68
|
+
// overridden by additionalParams / customParameters.
|
|
69
|
+
if (config.additionalParams) {
|
|
70
|
+
for (const [key, value] of Object.entries(config.additionalParams)) {
|
|
71
|
+
params.set(key, value);
|
|
72
|
+
}
|
|
53
73
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
Object.entries(options.options.customParameters).forEach(([key, value]) => {
|
|
74
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.options) === null || _a === void 0 ? void 0 : _a.customParameters) {
|
|
75
|
+
for (const [key, value] of Object.entries(options.options.customParameters)) {
|
|
57
76
|
params.set(key, value);
|
|
58
|
-
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Scopes
|
|
80
|
+
const scopes = ((_b = options === null || options === void 0 ? void 0 : options.options) === null || _b === void 0 ? void 0 : _b.scopes) || config.scopes || [];
|
|
81
|
+
if (scopes.length > 0) {
|
|
82
|
+
params.set('scope', scopes.join(' '));
|
|
59
83
|
}
|
|
60
|
-
//
|
|
84
|
+
// Login hint / prompt
|
|
61
85
|
if ((_c = options === null || options === void 0 ? void 0 : options.options) === null || _c === void 0 ? void 0 : _c.loginHint) {
|
|
62
86
|
params.set('login_hint', options.options.loginHint);
|
|
63
87
|
}
|
|
64
|
-
// Add prompt if provided
|
|
65
88
|
if ((_d = options === null || options === void 0 ? void 0 : options.options) === null || _d === void 0 ? void 0 : _d.prompt) {
|
|
66
89
|
params.set('prompt', options.options.prompt);
|
|
67
90
|
}
|
|
91
|
+
// Security-critical parameters — set LAST so custom params cannot override them.
|
|
92
|
+
params.set('client_id', config.clientId);
|
|
93
|
+
params.set('redirect_uri', config.redirectUri);
|
|
94
|
+
params.set('response_type', config.responseType || 'code');
|
|
95
|
+
params.set('state', state);
|
|
96
|
+
params.set('nonce', nonce);
|
|
97
|
+
if (codeChallenge) {
|
|
98
|
+
params.set('code_challenge', codeChallenge);
|
|
99
|
+
params.set('code_challenge_method', 'S256');
|
|
100
|
+
}
|
|
101
|
+
this.assertSecureEndpoint(config.authorizationEndpoint);
|
|
68
102
|
return `${config.authorizationEndpoint}?${params.toString()}`;
|
|
69
103
|
}
|
|
70
104
|
async validateOAuthResponse(response, expectedState, _expectedNonce) {
|
|
@@ -76,16 +110,21 @@ export class OAuthProvider extends BaseAuthProvider {
|
|
|
76
110
|
}
|
|
77
111
|
// Nonce validation is done after ID token is received
|
|
78
112
|
}
|
|
79
|
-
async exchangeCodeForTokens(code, config) {
|
|
113
|
+
async exchangeCodeForTokens(code, config, codeVerifier) {
|
|
80
114
|
const params = new URLSearchParams({
|
|
81
115
|
grant_type: config.grantType || 'authorization_code',
|
|
82
116
|
code,
|
|
83
117
|
redirect_uri: config.redirectUri,
|
|
84
118
|
client_id: config.clientId,
|
|
85
119
|
});
|
|
120
|
+
if (codeVerifier) {
|
|
121
|
+
params.set('code_verifier', codeVerifier);
|
|
122
|
+
}
|
|
86
123
|
if (config.clientSecret) {
|
|
124
|
+
this.warnClientSecretInBrowser();
|
|
87
125
|
params.set('client_secret', config.clientSecret);
|
|
88
126
|
}
|
|
127
|
+
this.assertSecureEndpoint(config.tokenEndpoint);
|
|
89
128
|
try {
|
|
90
129
|
const response = await fetch(config.tokenEndpoint, {
|
|
91
130
|
method: 'POST',
|
|
@@ -122,8 +161,10 @@ export class OAuthProvider extends BaseAuthProvider {
|
|
|
122
161
|
client_id: config.clientId,
|
|
123
162
|
});
|
|
124
163
|
if (config.clientSecret) {
|
|
164
|
+
this.warnClientSecretInBrowser();
|
|
125
165
|
params.set('client_secret', config.clientSecret);
|
|
126
166
|
}
|
|
167
|
+
this.assertSecureEndpoint(config.tokenEndpoint);
|
|
127
168
|
const response = await fetch(config.tokenEndpoint, {
|
|
128
169
|
method: 'POST',
|
|
129
170
|
headers: {
|
|
@@ -170,8 +211,10 @@ export class OAuthProvider extends BaseAuthProvider {
|
|
|
170
211
|
client_id: config.clientId,
|
|
171
212
|
});
|
|
172
213
|
if (config.clientSecret) {
|
|
214
|
+
this.warnClientSecretInBrowser();
|
|
173
215
|
params.set('client_secret', config.clientSecret);
|
|
174
216
|
}
|
|
217
|
+
this.assertSecureEndpoint(config.revokeEndpoint);
|
|
175
218
|
await fetch(config.revokeEndpoint, {
|
|
176
219
|
method: 'POST',
|
|
177
220
|
headers: {
|
|
@@ -258,5 +301,79 @@ export class OAuthProvider extends BaseAuthProvider {
|
|
|
258
301
|
}
|
|
259
302
|
return result;
|
|
260
303
|
}
|
|
304
|
+
/** RFC 7636 PKCE code verifier: 64 chars from the unreserved set [A-Za-z0-9]. */
|
|
305
|
+
generateCodeVerifier() {
|
|
306
|
+
return this.generateSecureRandomString(64);
|
|
307
|
+
}
|
|
308
|
+
/** Derives the S256 PKCE code challenge: base64url(SHA-256(verifier)). */
|
|
309
|
+
async generateCodeChallenge(verifier) {
|
|
310
|
+
const data = new TextEncoder().encode(verifier);
|
|
311
|
+
const digest = await crypto.subtle.digest('SHA-256', data);
|
|
312
|
+
return this.base64UrlEncode(new Uint8Array(digest));
|
|
313
|
+
}
|
|
314
|
+
base64UrlEncode(bytes) {
|
|
315
|
+
let binary = '';
|
|
316
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
317
|
+
binary += String.fromCharCode(bytes[i]);
|
|
318
|
+
}
|
|
319
|
+
return btoa(binary)
|
|
320
|
+
.replace(/\+/g, '-')
|
|
321
|
+
.replace(/\//g, '_')
|
|
322
|
+
.replace(/=+$/, '');
|
|
323
|
+
}
|
|
324
|
+
/** Decodes a JWT payload without verifying the signature. Returns null if malformed. */
|
|
325
|
+
decodeJwtPayload(token) {
|
|
326
|
+
try {
|
|
327
|
+
const parts = token.split('.');
|
|
328
|
+
if (parts.length < 2) {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
let payload = parts[1].replace(/-/g, '+').replace(/_/g, '/');
|
|
332
|
+
const pad = payload.length % 4;
|
|
333
|
+
if (pad) {
|
|
334
|
+
payload += '='.repeat(4 - pad);
|
|
335
|
+
}
|
|
336
|
+
return JSON.parse(atob(payload));
|
|
337
|
+
}
|
|
338
|
+
catch (_a) {
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Validates the ID token's nonce (replay protection) and expiry. The signature is NOT
|
|
344
|
+
* verified client-side — always re-validate ID tokens on your backend before trusting them.
|
|
345
|
+
*/
|
|
346
|
+
validateIdToken(idToken, expectedNonce) {
|
|
347
|
+
if (!idToken) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const payload = this.decodeJwtPayload(idToken);
|
|
351
|
+
if (!payload) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (payload.nonce !== undefined && payload.nonce !== expectedNonce) {
|
|
355
|
+
throw new AuthError(AuthErrorCode.INVALID_NONCE, 'OIDC nonce mismatch in ID token', this.provider);
|
|
356
|
+
}
|
|
357
|
+
if (typeof payload.exp === 'number' && payload.exp * 1000 < Date.now()) {
|
|
358
|
+
throw new AuthError(AuthErrorCode.TOKEN_EXPIRED, 'ID token is expired', this.provider);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
warnClientSecretInBrowser() {
|
|
362
|
+
this.logger.warn(`${this.provider}: a client secret was supplied to a browser-facing provider. Secrets ` +
|
|
363
|
+
`placed in client config ship in the JS bundle and are recoverable by end users. Use a ` +
|
|
364
|
+
`backend token-exchange proxy (set tokenEndpoint to your server) instead.`);
|
|
365
|
+
}
|
|
366
|
+
assertSecureEndpoint(url) {
|
|
367
|
+
try {
|
|
368
|
+
const parsed = new URL(url);
|
|
369
|
+
const isLocalhost = parsed.hostname === 'localhost' || parsed.hostname === '127.0.0.1';
|
|
370
|
+
if (parsed.protocol !== 'https:' && !isLocalhost) {
|
|
371
|
+
this.logger.warn(`${this.provider}: endpoint ${url} is not HTTPS — credentials/tokens may be sent in cleartext.`);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
catch (_a) {
|
|
375
|
+
// Malformed URL: let the subsequent fetch surface the error.
|
|
376
|
+
}
|
|
377
|
+
}
|
|
261
378
|
}
|
|
262
379
|
//# sourceMappingURL=oauth-provider.js.map
|