capacitor-auth-manager 1.0.0 → 1.1.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 +209 -0
- package/dist/esm/definitions.d.ts +5 -5
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/providers/oauth-provider.d.ts +38 -7
- package/dist/esm/providers/oauth-provider.js +17 -12
- package/dist/esm/providers/oauth-provider.js.map +1 -1
- package/dist/esm/providers/web/apple-provider.d.ts +32 -5
- package/dist/esm/providers/web/apple-provider.js +15 -16
- package/dist/esm/providers/web/apple-provider.js.map +1 -1
- package/dist/esm/providers/web/google-provider.d.ts +98 -7
- package/dist/esm/providers/web/google-provider.js +19 -9
- package/dist/esm/providers/web/google-provider.js.map +1 -1
- package/dist/esm/utils/auth-error.d.ts +5 -5
- package/dist/esm/utils/auth-error.js +10 -3
- package/dist/esm/utils/auth-error.js.map +1 -1
- package/dist/esm/utils/event-emitter.d.ts +2 -2
- package/dist/esm/utils/logger.d.ts +4 -4
- package/dist/esm/utils/logger.js.map +1 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +69 -43
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +69 -43
- package/dist/plugin.js.map +1 -1
- package/package.json +9 -9
package/Readme.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
A comprehensive authentication plugin for Capacitor that provides secure, type-safe, and framework-independent authentication implementations across Android, iOS, and Web platforms.
|
|
4
4
|
|
|
5
|
+
## 📚 Documentation
|
|
6
|
+
|
|
7
|
+
- [**Installation Guide**](./docs/installation.md) - Get started with Capacitor Auth Manager
|
|
8
|
+
- [**Configuration Options**](./docs/configuration.md) - Complete list of all configuration options
|
|
9
|
+
- [**Provider Guides**](./docs/providers/) - Detailed setup guides for each authentication provider
|
|
10
|
+
- [Google Auth](./docs/providers/google.md)
|
|
11
|
+
- [Apple Auth](./docs/providers/apple.md)
|
|
12
|
+
- [Microsoft Auth](./docs/providers/microsoft.md)
|
|
13
|
+
- [Facebook Auth](./docs/providers/facebook.md)
|
|
14
|
+
- [GitHub Auth](./docs/providers/github.md)
|
|
15
|
+
- [And more...](./docs/providers/)
|
|
16
|
+
- [**API Reference**](./docs/api/) - Complete API documentation
|
|
17
|
+
- [**Examples**](./docs/examples/) - Sample implementations and use cases
|
|
18
|
+
- [**Migration Guide**](./docs/migration.md) - Upgrading from previous versions
|
|
19
|
+
- [**Troubleshooting**](./docs/troubleshooting.md) - Common issues and solutions
|
|
20
|
+
|
|
5
21
|
## Features
|
|
6
22
|
|
|
7
23
|
- 🔐 **13+ Authentication Providers**: Google, Apple, Microsoft, Facebook, GitHub, Slack, LinkedIn, Firebase, Email Magic Link, SMS, Email/Phone/Username + Password, Email Code, and Biometric Auth
|
|
@@ -455,6 +471,169 @@ const token = await CapacitorAuthManager.getIdToken({
|
|
|
455
471
|
});
|
|
456
472
|
```
|
|
457
473
|
|
|
474
|
+
## Configuration Options
|
|
475
|
+
|
|
476
|
+
### Global Configuration
|
|
477
|
+
|
|
478
|
+
All configuration options available when initializing the auth manager:
|
|
479
|
+
|
|
480
|
+
```typescript
|
|
481
|
+
interface AuthManagerInitOptions {
|
|
482
|
+
providers: AuthProviderConfig[]; // Required: Array of provider configurations
|
|
483
|
+
persistence?: AuthPersistence; // 'local' | 'session' | 'none' (default: 'local')
|
|
484
|
+
autoRefreshToken?: boolean; // Auto-refresh tokens before expiry (default: true)
|
|
485
|
+
tokenRefreshBuffer?: number; // Ms before expiry to refresh (default: 300000 - 5 min)
|
|
486
|
+
enableLogging?: boolean; // Enable debug logging (default: false)
|
|
487
|
+
logLevel?: LogLevel; // 'debug' | 'info' | 'warn' | 'error' (default: 'info')
|
|
488
|
+
}
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
### Provider-Specific Options
|
|
492
|
+
|
|
493
|
+
Each provider supports all options provided by their official SDKs:
|
|
494
|
+
|
|
495
|
+
#### Google Auth Options
|
|
496
|
+
```typescript
|
|
497
|
+
interface GoogleAuthOptions {
|
|
498
|
+
clientId: string; // Required: Your Google Client ID
|
|
499
|
+
serverClientId?: string; // Android: Server client ID for offline access
|
|
500
|
+
scopes?: string[]; // OAuth scopes (default: ['openid', 'email', 'profile'])
|
|
501
|
+
offlineAccess?: boolean; // Request refresh token (default: false)
|
|
502
|
+
hostedDomain?: string; // Restrict to G Suite domain
|
|
503
|
+
forceCodeForRefreshToken?: boolean; // Force auth code flow (default: false)
|
|
504
|
+
}
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
#### Apple Auth Options
|
|
508
|
+
```typescript
|
|
509
|
+
interface AppleAuthOptions {
|
|
510
|
+
clientId: string; // Required: Your Service ID
|
|
511
|
+
redirectUri: string; // Required: Your redirect URI
|
|
512
|
+
scopes?: AppleAuthScope[]; // [EMAIL, NAME] (default: [])
|
|
513
|
+
usePopup?: boolean; // Use popup instead of redirect (default: true)
|
|
514
|
+
state?: string; // OAuth state parameter
|
|
515
|
+
nonce?: string; // OAuth nonce for security
|
|
516
|
+
}
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
#### Microsoft Auth Options
|
|
520
|
+
```typescript
|
|
521
|
+
interface MicrosoftAuthOptions {
|
|
522
|
+
clientId: string; // Required: Your Azure AD Client ID
|
|
523
|
+
redirectUri?: string; // Redirect URI (default: current URL)
|
|
524
|
+
scopes?: string[]; // OAuth scopes
|
|
525
|
+
tenantId?: string; // Azure AD tenant ID
|
|
526
|
+
prompt?: string; // 'login' | 'consent' | 'select_account'
|
|
527
|
+
loginHint?: string; // Pre-fill email
|
|
528
|
+
domainHint?: string; // 'consumers' | 'organizations'
|
|
529
|
+
responseType?: string; // OAuth response type
|
|
530
|
+
responseMode?: string; // 'query' | 'fragment'
|
|
531
|
+
codeChallenge?: string; // PKCE code challenge
|
|
532
|
+
codeChallengeMethod?: string; // PKCE method
|
|
533
|
+
state?: string; // OAuth state
|
|
534
|
+
nonce?: string; // OAuth nonce
|
|
535
|
+
}
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
#### Facebook Auth Options
|
|
539
|
+
```typescript
|
|
540
|
+
interface FacebookAuthOptions {
|
|
541
|
+
appId: string; // Required: Your Facebook App ID
|
|
542
|
+
permissions?: string[]; // Facebook permissions
|
|
543
|
+
version?: string; // API version (default: 'v12.0')
|
|
544
|
+
loginBehavior?: string; // iOS: 'browser' | 'native' | 'system'
|
|
545
|
+
limitedLogin?: boolean; // iOS 14.5+: Use limited login
|
|
546
|
+
nonce?: string; // Security nonce
|
|
547
|
+
}
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
#### Sign In Options
|
|
551
|
+
|
|
552
|
+
Additional options available when calling `signIn()`:
|
|
553
|
+
|
|
554
|
+
```typescript
|
|
555
|
+
interface SignInProviderOptions {
|
|
556
|
+
scopes?: string[]; // Override default scopes
|
|
557
|
+
customParameters?: Record<string, string>; // Provider-specific parameters
|
|
558
|
+
loginHint?: string; // Pre-fill username/email
|
|
559
|
+
prompt?: string; // UI behavior
|
|
560
|
+
display?: string; // UI display mode
|
|
561
|
+
accessType?: string; // 'online' | 'offline'
|
|
562
|
+
includeGrantedScopes?: boolean; // Include previously granted scopes
|
|
563
|
+
state?: string; // OAuth state
|
|
564
|
+
nonce?: string; // OAuth nonce
|
|
565
|
+
pkceEnabled?: boolean; // Enable PKCE (default: true where supported)
|
|
566
|
+
}
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
### Complete Example with All Options
|
|
570
|
+
|
|
571
|
+
```typescript
|
|
572
|
+
await CapacitorAuthManager.initialize({
|
|
573
|
+
// Global options
|
|
574
|
+
persistence: 'local',
|
|
575
|
+
autoRefreshToken: true,
|
|
576
|
+
tokenRefreshBuffer: 300000,
|
|
577
|
+
enableLogging: true,
|
|
578
|
+
logLevel: 'debug',
|
|
579
|
+
|
|
580
|
+
// Provider configurations
|
|
581
|
+
providers: [
|
|
582
|
+
{
|
|
583
|
+
provider: AuthProvider.GOOGLE,
|
|
584
|
+
options: {
|
|
585
|
+
clientId: 'YOUR_GOOGLE_CLIENT_ID',
|
|
586
|
+
serverClientId: 'YOUR_SERVER_CLIENT_ID',
|
|
587
|
+
scopes: ['email', 'profile', 'https://www.googleapis.com/auth/calendar'],
|
|
588
|
+
offlineAccess: true,
|
|
589
|
+
hostedDomain: 'company.com',
|
|
590
|
+
forceCodeForRefreshToken: true
|
|
591
|
+
}
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
provider: AuthProvider.APPLE,
|
|
595
|
+
options: {
|
|
596
|
+
clientId: 'com.company.service',
|
|
597
|
+
redirectUri: 'https://company.com/auth/callback',
|
|
598
|
+
scopes: [AppleAuthScope.EMAIL, AppleAuthScope.NAME],
|
|
599
|
+
usePopup: true,
|
|
600
|
+
state: crypto.randomUUID(),
|
|
601
|
+
nonce: crypto.randomUUID()
|
|
602
|
+
}
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
provider: AuthProvider.MICROSOFT,
|
|
606
|
+
options: {
|
|
607
|
+
clientId: 'YOUR_AZURE_CLIENT_ID',
|
|
608
|
+
redirectUri: 'https://company.com/auth/callback',
|
|
609
|
+
scopes: ['openid', 'profile', 'email', 'User.Read'],
|
|
610
|
+
tenantId: 'YOUR_TENANT_ID',
|
|
611
|
+
prompt: 'select_account',
|
|
612
|
+
responseType: 'code',
|
|
613
|
+
responseMode: 'query',
|
|
614
|
+
codeChallenge: 'YOUR_CODE_CHALLENGE',
|
|
615
|
+
codeChallengeMethod: 'S256'
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
]
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
// Sign in with custom options
|
|
622
|
+
const result = await CapacitorAuthManager.signIn({
|
|
623
|
+
provider: AuthProvider.GOOGLE,
|
|
624
|
+
options: {
|
|
625
|
+
scopes: ['email', 'profile', 'https://www.googleapis.com/auth/drive'],
|
|
626
|
+
loginHint: 'user@company.com',
|
|
627
|
+
prompt: 'consent',
|
|
628
|
+
accessType: 'offline',
|
|
629
|
+
includeGrantedScopes: true,
|
|
630
|
+
customParameters: {
|
|
631
|
+
'approval_prompt': 'force'
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
```
|
|
636
|
+
|
|
458
637
|
## Error Handling
|
|
459
638
|
|
|
460
639
|
The plugin provides detailed error codes for different scenarios:
|
|
@@ -569,6 +748,36 @@ For comprehensive documentation, examples, and guides, visit our [Documentation]
|
|
|
569
748
|
- [Token Management](./docs/guides/token-management.md) - Handling tokens
|
|
570
749
|
- [Multi-Factor Auth](./docs/guides/mfa.md) - Implementing MFA
|
|
571
750
|
|
|
751
|
+
## Platform Compatibility
|
|
752
|
+
|
|
753
|
+
### Supported Platforms
|
|
754
|
+
|
|
755
|
+
| Provider | iOS | Android | Web |
|
|
756
|
+
|----------|-----|---------|-----|
|
|
757
|
+
| Google | ✅ | ✅ | ✅ |
|
|
758
|
+
| Apple | ✅ | ✅ | ✅ |
|
|
759
|
+
| Microsoft | ✅ | ✅ | ✅ |
|
|
760
|
+
| Facebook | ✅ | ✅ | ✅ |
|
|
761
|
+
| GitHub | ✅ | ✅ | ✅ |
|
|
762
|
+
| Slack | ✅ | ✅ | ✅ |
|
|
763
|
+
| LinkedIn | ✅ | ✅ | ✅ |
|
|
764
|
+
| Firebase | ✅ | ✅ | ✅ |
|
|
765
|
+
| Email Magic Link | ✅ | ✅ | ✅ |
|
|
766
|
+
| SMS | ✅ | ✅ | ✅ |
|
|
767
|
+
| Email/Phone/Username + Password | ✅ | ✅ | ✅ |
|
|
768
|
+
| Email Code | ✅ | ✅ | ✅ |
|
|
769
|
+
| Biometric | ✅ | ✅ | ❌ |
|
|
770
|
+
|
|
771
|
+
### Platform Requirements
|
|
772
|
+
|
|
773
|
+
- **iOS**: iOS 13.0+
|
|
774
|
+
- **Android**: Android 5.0 (API 21)+
|
|
775
|
+
- **Web**: Modern browsers with ES2017 support
|
|
776
|
+
|
|
777
|
+
### Capacitor Version
|
|
778
|
+
|
|
779
|
+
- Capacitor 7.0.0+
|
|
780
|
+
|
|
572
781
|
## Contributing
|
|
573
782
|
|
|
574
783
|
Contributions are welcome! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
@@ -290,7 +290,7 @@ export interface OAuthCredentials {
|
|
|
290
290
|
nonce?: string;
|
|
291
291
|
}
|
|
292
292
|
export interface CustomCredentials {
|
|
293
|
-
[key: string]:
|
|
293
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
294
294
|
}
|
|
295
295
|
export type SignInProviderOptions = {
|
|
296
296
|
scopes?: string[];
|
|
@@ -328,7 +328,7 @@ export interface AuthUser {
|
|
|
328
328
|
providerData: UserInfo[];
|
|
329
329
|
metadata: UserMetadata;
|
|
330
330
|
refreshToken?: string;
|
|
331
|
-
customClaims?: Record<string,
|
|
331
|
+
customClaims?: Record<string, string | number | boolean | null>;
|
|
332
332
|
}
|
|
333
333
|
export interface UserInfo {
|
|
334
334
|
providerId: string;
|
|
@@ -357,7 +357,7 @@ export interface AuthCredential {
|
|
|
357
357
|
export interface AdditionalUserInfo {
|
|
358
358
|
isNewUser: boolean;
|
|
359
359
|
providerId: string;
|
|
360
|
-
profile?: Record<string,
|
|
360
|
+
profile?: Record<string, string | number | boolean | null | undefined>;
|
|
361
361
|
username?: string;
|
|
362
362
|
}
|
|
363
363
|
export interface RefreshTokenOptions {
|
|
@@ -425,7 +425,7 @@ export interface UpdateProfileOptions {
|
|
|
425
425
|
displayName?: string | null;
|
|
426
426
|
photoURL?: string | null;
|
|
427
427
|
phoneNumber?: string | null;
|
|
428
|
-
customClaims?: Record<string,
|
|
428
|
+
customClaims?: Record<string, string | number | boolean | null>;
|
|
429
429
|
}
|
|
430
430
|
export interface DeleteAccountOptions {
|
|
431
431
|
requireReauthentication?: boolean;
|
|
@@ -451,7 +451,7 @@ export declare enum AuthPersistence {
|
|
|
451
451
|
}
|
|
452
452
|
export interface AuthError extends Error {
|
|
453
453
|
code: string;
|
|
454
|
-
details?:
|
|
454
|
+
details?: Record<string, unknown>;
|
|
455
455
|
provider?: AuthProvider;
|
|
456
456
|
}
|
|
457
457
|
export declare enum AuthErrorCode {
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ import type { CapacitorAuthManagerPlugin } from './definitions';
|
|
|
2
2
|
declare const CapacitorAuthManager: CapacitorAuthManagerPlugin;
|
|
3
3
|
export * from './definitions';
|
|
4
4
|
export { CapacitorAuthManager };
|
|
5
|
+
export { AuthError, isAuthError } from './utils/auth-error';
|
|
6
|
+
export type { LogLevel } from './utils/logger';
|
package/dist/esm/index.js
CHANGED
|
@@ -4,4 +4,6 @@ const CapacitorAuthManager = registerPlugin('CapacitorAuthManager', {
|
|
|
4
4
|
});
|
|
5
5
|
export * from './definitions';
|
|
6
6
|
export { CapacitorAuthManager };
|
|
7
|
+
// Export useful utilities for end users
|
|
8
|
+
export { AuthError, isAuthError } from './utils/auth-error';
|
|
7
9
|
//# 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,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,oBAAoB,GAAG,cAAc,CACzC,sBAAsB,EACtB;IACE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,uBAAuB,EAAE,CAAC;CACtE,CACF,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,oBAAoB,GAAG,cAAc,CACzC,sBAAsB,EACtB;IACE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,uBAAuB,EAAE,CAAC;CACtE,CACF,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC,wCAAwC;AACxC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -1,5 +1,27 @@
|
|
|
1
|
-
import { AuthResult, SignInOptions, AuthErrorCode, AuthCredential, RefreshTokenOptions } from '../definitions';
|
|
1
|
+
import { AuthResult, SignInOptions, AuthErrorCode, AuthCredential, RefreshTokenOptions, AuthUser } from '../definitions';
|
|
2
2
|
import { BaseAuthProvider } from './base-provider';
|
|
3
|
+
export interface OAuthTokenResponse {
|
|
4
|
+
access_token: string;
|
|
5
|
+
token_type: string;
|
|
6
|
+
expires_in?: number;
|
|
7
|
+
refresh_token?: string;
|
|
8
|
+
id_token?: string;
|
|
9
|
+
scope?: string;
|
|
10
|
+
[key: string]: string | number | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface OAuthUserInfo {
|
|
13
|
+
id?: string;
|
|
14
|
+
sub?: string;
|
|
15
|
+
email?: string;
|
|
16
|
+
email_verified?: boolean;
|
|
17
|
+
name?: string;
|
|
18
|
+
displayName?: string;
|
|
19
|
+
picture?: string;
|
|
20
|
+
photoURL?: string;
|
|
21
|
+
phone_number?: string;
|
|
22
|
+
isNewUser?: boolean;
|
|
23
|
+
[key: string]: string | boolean | undefined;
|
|
24
|
+
}
|
|
3
25
|
export interface OAuthConfig {
|
|
4
26
|
clientId: string;
|
|
5
27
|
clientSecret?: string;
|
|
@@ -15,16 +37,25 @@ export interface OAuthConfig {
|
|
|
15
37
|
}
|
|
16
38
|
export declare abstract class OAuthProvider extends BaseAuthProvider {
|
|
17
39
|
protected abstract getOAuthConfig(): OAuthConfig;
|
|
18
|
-
protected abstract parseUserFromTokenResponse(response:
|
|
40
|
+
protected abstract parseUserFromTokenResponse(response: OAuthTokenResponse): Promise<OAuthUserInfo>;
|
|
19
41
|
protected performOAuthFlow(options?: SignInOptions): Promise<AuthResult>;
|
|
20
42
|
protected buildAuthorizationUrl(config: OAuthConfig, state: string, nonce: string, options?: SignInOptions): string;
|
|
21
|
-
protected abstract openAuthorizationUrl(url: string): Promise<
|
|
22
|
-
|
|
23
|
-
|
|
43
|
+
protected abstract openAuthorizationUrl(url: string): Promise<{
|
|
44
|
+
code?: string;
|
|
45
|
+
state?: string;
|
|
46
|
+
error?: string;
|
|
47
|
+
}>;
|
|
48
|
+
protected validateOAuthResponse(response: {
|
|
49
|
+
code?: string;
|
|
50
|
+
state?: string;
|
|
51
|
+
error?: string;
|
|
52
|
+
error_description?: string;
|
|
53
|
+
}, expectedState: string, _expectedNonce: string): Promise<void>;
|
|
54
|
+
protected exchangeCodeForTokens(code: string, config: OAuthConfig): Promise<OAuthTokenResponse>;
|
|
24
55
|
refreshToken(_options?: RefreshTokenOptions): Promise<AuthResult>;
|
|
25
56
|
revokeAccess(token?: string): Promise<void>;
|
|
26
|
-
protected createOAuthCredential(tokenResponse:
|
|
27
|
-
protected createAuthUser(userInfo:
|
|
57
|
+
protected createOAuthCredential(tokenResponse: OAuthTokenResponse): AuthCredential;
|
|
58
|
+
protected createAuthUser(userInfo: OAuthUserInfo, tokenResponse: OAuthTokenResponse): AuthUser;
|
|
28
59
|
protected mapOAuthError(error: string): AuthErrorCode;
|
|
29
60
|
protected generateSecureRandomString(length?: number): string;
|
|
30
61
|
}
|
|
@@ -18,6 +18,9 @@ export class OAuthProvider extends BaseAuthProvider {
|
|
|
18
18
|
// Validate response
|
|
19
19
|
await this.validateOAuthResponse(authResponse, state, nonce);
|
|
20
20
|
// Exchange authorization code for tokens
|
|
21
|
+
if (!authResponse.code) {
|
|
22
|
+
throw new AuthError(AuthErrorCode.INVALID_GRANT, 'No authorization code received', this.provider);
|
|
23
|
+
}
|
|
21
24
|
const tokenResponse = await this.exchangeCodeForTokens(authResponse.code, config);
|
|
22
25
|
// Parse user information
|
|
23
26
|
const userInfo = await this.parseUserFromTokenResponse(tokenResponse);
|
|
@@ -27,7 +30,7 @@ export class OAuthProvider extends BaseAuthProvider {
|
|
|
27
30
|
// Save user and credential
|
|
28
31
|
await this.setCurrentUser(user);
|
|
29
32
|
await this.saveCredential(credential);
|
|
30
|
-
return this.createAuthResult(user, credential, userInfo.isNewUser);
|
|
33
|
+
return this.createAuthResult(user, credential, userInfo.isNewUser || false);
|
|
31
34
|
}
|
|
32
35
|
catch (error) {
|
|
33
36
|
this.logger.error(`OAuth flow failed for ${this.provider}`, error);
|
|
@@ -93,7 +96,8 @@ export class OAuthProvider extends BaseAuthProvider {
|
|
|
93
96
|
});
|
|
94
97
|
const data = await response.json();
|
|
95
98
|
if (!response.ok) {
|
|
96
|
-
|
|
99
|
+
const errorData = data;
|
|
100
|
+
throw new AuthError(this.mapOAuthError(errorData.error), errorData.error_description || 'Token exchange failed', this.provider, errorData);
|
|
97
101
|
}
|
|
98
102
|
return data;
|
|
99
103
|
}
|
|
@@ -129,7 +133,8 @@ export class OAuthProvider extends BaseAuthProvider {
|
|
|
129
133
|
});
|
|
130
134
|
const data = await response.json();
|
|
131
135
|
if (!response.ok) {
|
|
132
|
-
|
|
136
|
+
const errorData = data;
|
|
137
|
+
throw new AuthError(this.mapOAuthError(errorData.error), errorData.error_description || 'Token refresh failed', this.provider, errorData);
|
|
133
138
|
}
|
|
134
139
|
// Update credential with new tokens
|
|
135
140
|
const newCredential = this.createOAuthCredential(data);
|
|
@@ -202,20 +207,20 @@ export class OAuthProvider extends BaseAuthProvider {
|
|
|
202
207
|
createAuthUser(userInfo, tokenResponse) {
|
|
203
208
|
return {
|
|
204
209
|
uid: userInfo.id || userInfo.sub || this.generateUniqueId(),
|
|
205
|
-
email: userInfo.email,
|
|
210
|
+
email: userInfo.email || null,
|
|
206
211
|
emailVerified: userInfo.email_verified || false,
|
|
207
|
-
displayName: userInfo.name || userInfo.displayName,
|
|
208
|
-
photoURL: userInfo.picture || userInfo.photoURL,
|
|
209
|
-
phoneNumber: userInfo.phone_number,
|
|
212
|
+
displayName: userInfo.name || userInfo.displayName || null,
|
|
213
|
+
photoURL: userInfo.picture || userInfo.photoURL || null,
|
|
214
|
+
phoneNumber: userInfo.phone_number || null,
|
|
210
215
|
isAnonymous: false,
|
|
211
216
|
tenantId: null,
|
|
212
217
|
providerData: [{
|
|
213
218
|
providerId: this.provider,
|
|
214
|
-
uid: userInfo.id || userInfo.sub,
|
|
215
|
-
displayName: userInfo.name,
|
|
216
|
-
email: userInfo.email,
|
|
217
|
-
phoneNumber: userInfo.phone_number,
|
|
218
|
-
photoURL: userInfo.picture,
|
|
219
|
+
uid: userInfo.id || userInfo.sub || '',
|
|
220
|
+
displayName: userInfo.name || null,
|
|
221
|
+
email: userInfo.email || null,
|
|
222
|
+
phoneNumber: userInfo.phone_number || null,
|
|
223
|
+
photoURL: userInfo.picture || null,
|
|
219
224
|
}],
|
|
220
225
|
metadata: {
|
|
221
226
|
creationTime: new Date().toISOString(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-provider.js","sourceRoot":"","sources":["../../../src/providers/oauth-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,
|
|
1
|
+
{"version":3,"file":"oauth-provider.js","sourceRoot":"","sources":["../../../src/providers/oauth-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,GAId,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAwChD,MAAM,OAAgB,aAAc,SAAQ,gBAAgB;IAIhD,KAAK,CAAC,gBAAgB,CAAC,OAAuB;QACtD,MAAM,MAAM,GAAG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B,EAAE,aAAa,CAAC,eAAe;YAChD,qBAAqB,EAAE,aAAa,CAAC,kBAAkB;YACvD,eAAe,EAAE,aAAa,CAAC,aAAa;YAC5C,2BAA2B,EAAE,aAAa,CAAC,sBAAsB;YACjE,eAAe,EAAE,aAAa,CAAC,aAAa;YAC5C,cAAc,EAAE,aAAa,CAAC,YAAY;YAC1C,yBAAyB,EAAE,aAAa,CAAC,uBAAuB;YAChE,eAAe,EAAE,aAAa,CAAC,aAAa;YAC5C,gBAAgB,EAAE,aAAa,CAAC,gBAAgB;YAChD,sBAAsB,EAAE,aAAa,CAAC,oBAAoB;YAC1D,gBAAgB,EAAE,aAAa,CAAC,cAAc;YAC9C,kBAAkB,EAAE,aAAa,CAAC,gBAAgB;SACnD,CAAC;QAEF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,cAAc,CAAC;IACzD,CAAC;IAES,0BAA0B,CAAC,MAAM,GAAG,EAAE;QAC9C,MAAM,KAAK,GAAG,gEAAgE,CAAC;QAC/E,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,MAAM,YAAY,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;QAC5C,MAAM,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;QAErC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
import { SignInOptions, SignOutOptions, LinkAccountOptions, UnlinkAccountOptions, AuthResult } from '../../definitions';
|
|
2
|
-
import { OAuthProvider, OAuthConfig } from '../oauth-provider';
|
|
2
|
+
import { OAuthProvider, OAuthConfig, OAuthTokenResponse, OAuthUserInfo } from '../oauth-provider';
|
|
3
3
|
import { BaseProviderConfig } from '../base-provider';
|
|
4
|
+
interface AppleSignInResponse {
|
|
5
|
+
authorization: {
|
|
6
|
+
code: string;
|
|
7
|
+
id_token: string;
|
|
8
|
+
state: string;
|
|
9
|
+
};
|
|
10
|
+
user?: {
|
|
11
|
+
email?: string;
|
|
12
|
+
name?: {
|
|
13
|
+
firstName?: string;
|
|
14
|
+
lastName?: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface AppleSignInConfig {
|
|
19
|
+
clientId: string;
|
|
20
|
+
scope: string;
|
|
21
|
+
redirectURI: string;
|
|
22
|
+
state: string;
|
|
23
|
+
nonce?: string;
|
|
24
|
+
usePopup?: boolean;
|
|
25
|
+
}
|
|
4
26
|
declare global {
|
|
5
27
|
interface Window {
|
|
6
28
|
AppleID?: {
|
|
7
29
|
auth: {
|
|
8
|
-
init: (config:
|
|
9
|
-
signIn: (config?:
|
|
30
|
+
init: (config: AppleSignInConfig) => void;
|
|
31
|
+
signIn: (config?: AppleSignInConfig) => Promise<AppleSignInResponse>;
|
|
10
32
|
};
|
|
11
33
|
};
|
|
12
34
|
}
|
|
@@ -22,8 +44,12 @@ export declare class AppleAuthProviderWeb extends OAuthProvider {
|
|
|
22
44
|
isSupported(): Promise<boolean>;
|
|
23
45
|
linkAccount(options: LinkAccountOptions): Promise<AuthResult>;
|
|
24
46
|
unlinkAccount(_options: UnlinkAccountOptions): Promise<void>;
|
|
25
|
-
protected openAuthorizationUrl(_url: string): Promise<
|
|
26
|
-
|
|
47
|
+
protected openAuthorizationUrl(_url: string): Promise<{
|
|
48
|
+
code?: string;
|
|
49
|
+
state?: string;
|
|
50
|
+
error?: string;
|
|
51
|
+
}>;
|
|
52
|
+
protected parseUserFromTokenResponse(_response: OAuthTokenResponse): Promise<OAuthUserInfo>;
|
|
27
53
|
private loadAppleSDK;
|
|
28
54
|
private mapAppleScopes;
|
|
29
55
|
private validateAppleResponse;
|
|
@@ -31,3 +57,4 @@ export declare class AppleAuthProviderWeb extends OAuthProvider {
|
|
|
31
57
|
private createAppleCredential;
|
|
32
58
|
private mapAppleError;
|
|
33
59
|
}
|
|
60
|
+
export {};
|
|
@@ -45,7 +45,7 @@ export class AppleAuthProviderWeb extends OAuthProvider {
|
|
|
45
45
|
clientId: options.clientId,
|
|
46
46
|
scope: this.mapAppleScopes(options.scopes).join(' '),
|
|
47
47
|
redirectURI: options.redirectUri,
|
|
48
|
-
state: options.state,
|
|
48
|
+
state: options.state || this.generateSecureRandomString(),
|
|
49
49
|
nonce: options.nonce,
|
|
50
50
|
usePopup: options.usePopup !== false, // Default to true
|
|
51
51
|
});
|
|
@@ -141,9 +141,10 @@ export class AppleAuthProviderWeb extends OAuthProvider {
|
|
|
141
141
|
// This method is not used in Apple JS SDK flow
|
|
142
142
|
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Direct OAuth flow not supported for Apple. Use signIn method instead.', this.provider);
|
|
143
143
|
}
|
|
144
|
-
async parseUserFromTokenResponse(
|
|
144
|
+
async parseUserFromTokenResponse(_response) {
|
|
145
145
|
// Apple provides user info directly in the authorization response
|
|
146
|
-
|
|
146
|
+
// Note: This is a simplified implementation since Apple doesn't provide user info in the token response
|
|
147
|
+
return {};
|
|
147
148
|
}
|
|
148
149
|
async loadAppleSDK() {
|
|
149
150
|
var _a;
|
|
@@ -189,14 +190,14 @@ export class AppleAuthProviderWeb extends OAuthProvider {
|
|
|
189
190
|
if (response.error) {
|
|
190
191
|
throw new AuthError(this.mapAppleError(response.error), response.error, this.provider);
|
|
191
192
|
}
|
|
192
|
-
if (response.state !== expectedState) {
|
|
193
|
+
if (response.authorization.state !== expectedState) {
|
|
193
194
|
throw new AuthError(AuthErrorCode.INVALID_STATE, 'OAuth state mismatch', this.provider);
|
|
194
195
|
}
|
|
195
196
|
// ID token validation with nonce would be done here
|
|
196
197
|
// For production, you should validate the ID token on your backend
|
|
197
198
|
}
|
|
198
199
|
createAppleAuthUser(response) {
|
|
199
|
-
var _a, _b, _c
|
|
200
|
+
var _a, _b, _c;
|
|
200
201
|
const user = response.user || {};
|
|
201
202
|
const idToken = (_a = response.authorization) === null || _a === void 0 ? void 0 : _a.id_token;
|
|
202
203
|
// Parse ID token claims (in production, do this on backend)
|
|
@@ -221,7 +222,7 @@ export class AppleAuthProviderWeb extends OAuthProvider {
|
|
|
221
222
|
tenantId: null,
|
|
222
223
|
providerData: [{
|
|
223
224
|
providerId: AuthProvider.APPLE,
|
|
224
|
-
uid: claims.sub || ((_c = response.authorization) === null || _c === void 0 ? void 0 : _c.code),
|
|
225
|
+
uid: claims.sub || ((_c = response.authorization) === null || _c === void 0 ? void 0 : _c.code) || '',
|
|
225
226
|
displayName: user.name ? `${user.name.firstName || ''} ${user.name.lastName || ''}`.trim() : null,
|
|
226
227
|
email: user.email || claims.email || null,
|
|
227
228
|
phoneNumber: null,
|
|
@@ -231,23 +232,21 @@ export class AppleAuthProviderWeb extends OAuthProvider {
|
|
|
231
232
|
creationTime: new Date().toISOString(),
|
|
232
233
|
lastSignInTime: new Date().toISOString(),
|
|
233
234
|
},
|
|
234
|
-
refreshToken:
|
|
235
|
+
refreshToken: undefined, // Apple doesn't provide refresh tokens through JS SDK
|
|
235
236
|
};
|
|
236
237
|
}
|
|
237
238
|
createAppleCredential(response) {
|
|
238
|
-
var _a, _b
|
|
239
|
+
var _a, _b;
|
|
239
240
|
return {
|
|
240
241
|
providerId: AuthProvider.APPLE,
|
|
241
242
|
signInMethod: 'oauth',
|
|
242
|
-
accessToken:
|
|
243
|
-
idToken: (
|
|
244
|
-
refreshToken:
|
|
245
|
-
expiresAt:
|
|
246
|
-
? this.calculateTokenExpiry(response.authorization.expires_in)
|
|
247
|
-
: undefined,
|
|
243
|
+
accessToken: undefined, // Apple doesn't provide access tokens through JS SDK
|
|
244
|
+
idToken: (_a = response.authorization) === null || _a === void 0 ? void 0 : _a.id_token,
|
|
245
|
+
refreshToken: undefined, // Apple doesn't provide refresh tokens through JS SDK
|
|
246
|
+
expiresAt: undefined,
|
|
248
247
|
tokenType: 'Bearer',
|
|
249
|
-
scope:
|
|
250
|
-
rawNonce: response.
|
|
248
|
+
scope: undefined, // Apple doesn't provide scope info in JS SDK response
|
|
249
|
+
rawNonce: (_b = response.authorization) === null || _b === void 0 ? void 0 : _b.state,
|
|
251
250
|
};
|
|
252
251
|
}
|
|
253
252
|
mapAppleError(error) {
|