capacitor-auth-manager 1.1.0 → 2.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 +385 -640
- package/dist/core.cjs.js +4952 -0
- package/dist/core.cjs.js.map +1 -0
- package/dist/esm/capacitor-plugin.d.ts +3 -0
- package/dist/esm/capacitor-plugin.js +7 -0
- package/dist/esm/capacitor-plugin.js.map +1 -0
- package/dist/esm/core/auth-manager.d.ts +33 -0
- package/dist/esm/core/auth-manager.js +296 -0
- package/dist/esm/core/auth-manager.js.map +1 -0
- package/dist/esm/core/index.d.ts +4 -0
- package/dist/esm/core/index.js +5 -0
- package/dist/esm/core/index.js.map +1 -0
- package/dist/esm/core/platform.d.ts +17 -0
- package/dist/esm/core/platform.js +80 -0
- package/dist/esm/core/platform.js.map +1 -0
- package/dist/esm/core/provider-registry.d.ts +21 -0
- package/dist/esm/core/provider-registry.js +605 -0
- package/dist/esm/core/provider-registry.js.map +1 -0
- package/dist/esm/core/types.d.ts +35 -0
- package/dist/esm/core/types.js +2 -0
- package/dist/esm/core/types.js.map +1 -0
- package/dist/esm/definitions.d.ts +40 -5
- package/dist/esm/definitions.js +14 -4
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +7 -5
- package/dist/esm/index.js +8 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/providers/base-provider.d.ts +3 -1
- package/dist/esm/providers/base-provider.js +8 -5
- package/dist/esm/providers/base-provider.js.map +1 -1
- package/dist/esm/providers/oauth-provider.js +18 -16
- package/dist/esm/providers/oauth-provider.js.map +1 -1
- package/dist/esm/providers/provider-factory.js +1 -1
- package/dist/esm/providers/provider-factory.js.map +1 -1
- package/dist/esm/providers/web/apple-provider.js +27 -19
- package/dist/esm/providers/web/apple-provider.js.map +1 -1
- package/dist/esm/providers/web/biometric-provider.d.ts +47 -0
- package/dist/esm/providers/web/biometric-provider.js +267 -0
- package/dist/esm/providers/web/biometric-provider.js.map +1 -0
- package/dist/esm/providers/web/email-password-provider.d.ts +55 -0
- package/dist/esm/providers/web/email-password-provider.js +429 -0
- package/dist/esm/providers/web/email-password-provider.js.map +1 -0
- package/dist/esm/providers/web/facebook-provider.d.ts +29 -0
- package/dist/esm/providers/web/facebook-provider.js +249 -0
- package/dist/esm/providers/web/facebook-provider.js.map +1 -0
- package/dist/esm/providers/web/firebase-provider.d.ts +20 -0
- package/dist/esm/providers/web/firebase-provider.js +306 -0
- package/dist/esm/providers/web/firebase-provider.js.map +1 -0
- package/dist/esm/providers/web/github-provider.d.ts +25 -0
- package/dist/esm/providers/web/github-provider.js +248 -0
- package/dist/esm/providers/web/github-provider.js.map +1 -0
- package/dist/esm/providers/web/google-provider.js +18 -14
- package/dist/esm/providers/web/google-provider.js.map +1 -1
- package/dist/esm/providers/web/index.d.ts +13 -0
- package/dist/esm/providers/web/index.js +15 -0
- package/dist/esm/providers/web/index.js.map +1 -0
- package/dist/esm/providers/web/linkedin-provider.d.ts +38 -0
- package/dist/esm/providers/web/linkedin-provider.js +152 -0
- package/dist/esm/providers/web/linkedin-provider.js.map +1 -0
- package/dist/esm/providers/web/magic-link-provider.d.ts +46 -0
- package/dist/esm/providers/web/magic-link-provider.js +298 -0
- package/dist/esm/providers/web/magic-link-provider.js.map +1 -0
- package/dist/esm/providers/web/microsoft-provider.d.ts +21 -0
- package/dist/esm/providers/web/microsoft-provider.js +211 -0
- package/dist/esm/providers/web/microsoft-provider.js.map +1 -0
- package/dist/esm/providers/web/slack-provider.d.ts +40 -0
- package/dist/esm/providers/web/slack-provider.js +151 -0
- package/dist/esm/providers/web/slack-provider.js.map +1 -0
- package/dist/esm/providers/web/sms-provider.d.ts +48 -0
- package/dist/esm/providers/web/sms-provider.js +301 -0
- package/dist/esm/providers/web/sms-provider.js.map +1 -0
- package/dist/esm/providers/web/username-password-provider.d.ts +62 -0
- package/dist/esm/providers/web/username-password-provider.js +432 -0
- package/dist/esm/providers/web/username-password-provider.js.map +1 -0
- package/dist/esm/utils/auth-error.js +7 -5
- package/dist/esm/utils/auth-error.js.map +1 -1
- package/dist/esm/utils/event-emitter.js +1 -1
- package/dist/esm/utils/event-emitter.js.map +1 -1
- package/dist/esm/utils/storage.d.ts +4 -4
- package/dist/esm/utils/storage.js +13 -3
- package/dist/esm/utils/storage.js.map +1 -1
- package/dist/esm/web.js +7 -3
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +4093 -354
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +4093 -354
- package/dist/plugin.js.map +1 -1
- package/package.json +75 -14
- package/scripts/configure.js +105 -61
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { AuthProvider, } from '../../definitions';
|
|
2
|
+
import { OAuthProvider, } from '../oauth-provider';
|
|
3
|
+
import { AuthError } from '../../utils/auth-error';
|
|
4
|
+
export class SlackProvider extends OAuthProvider {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
super(config);
|
|
7
|
+
this.provider = AuthProvider.SLACK;
|
|
8
|
+
this.clientId = '';
|
|
9
|
+
this.redirectUri = '';
|
|
10
|
+
this.scopes = [];
|
|
11
|
+
this.authWindow = null;
|
|
12
|
+
const options = config.options;
|
|
13
|
+
this.clientId = options.clientId || '';
|
|
14
|
+
this.redirectUri = options.redirectUri || '';
|
|
15
|
+
this.scopes = options.scopes || ['openid', 'profile', 'email'];
|
|
16
|
+
this.teamId = options.teamId;
|
|
17
|
+
}
|
|
18
|
+
async initialize() {
|
|
19
|
+
this.isInitialized = true;
|
|
20
|
+
}
|
|
21
|
+
async signIn(options) {
|
|
22
|
+
return this.performOAuthFlow(options);
|
|
23
|
+
}
|
|
24
|
+
async refreshToken(_options) {
|
|
25
|
+
throw new AuthError('NOT_IMPLEMENTED', 'Token refresh not implemented for Slack provider');
|
|
26
|
+
}
|
|
27
|
+
getOAuthConfig() {
|
|
28
|
+
return {
|
|
29
|
+
clientId: this.clientId,
|
|
30
|
+
redirectUri: this.redirectUri,
|
|
31
|
+
authorizationEndpoint: 'https://slack.com/oauth/v2/authorize',
|
|
32
|
+
tokenEndpoint: 'https://slack.com/api/oauth.v2.access',
|
|
33
|
+
scopes: this.scopes,
|
|
34
|
+
additionalParams: this.teamId ? { team: this.teamId } : {},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async parseUserFromTokenResponse(_response) {
|
|
38
|
+
// In a real implementation, you would parse the user info from the token response
|
|
39
|
+
// or make an additional API call to get user details
|
|
40
|
+
return {
|
|
41
|
+
id: 'U1234567890',
|
|
42
|
+
email: 'user@workspace.slack.com',
|
|
43
|
+
name: 'Slack User',
|
|
44
|
+
picture: 'https://ui-avatars.com/api/?name=Slack+User',
|
|
45
|
+
email_verified: true,
|
|
46
|
+
isNewUser: false,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async openAuthorizationUrl(url) {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
// Open OAuth window
|
|
52
|
+
this.authWindow = window.open(url, 'SlackAuth', 'width=500,height=600');
|
|
53
|
+
if (!this.authWindow) {
|
|
54
|
+
reject(new Error('Failed to open authentication window'));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
// Listen for OAuth callback
|
|
58
|
+
const checkInterval = setInterval(() => {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
try {
|
|
61
|
+
if ((_a = this.authWindow) === null || _a === void 0 ? void 0 : _a.closed) {
|
|
62
|
+
clearInterval(checkInterval);
|
|
63
|
+
reject(new Error('Authentication cancelled'));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if ((_b = this.authWindow) === null || _b === void 0 ? void 0 : _b.location.href.startsWith(this.redirectUri)) {
|
|
67
|
+
clearInterval(checkInterval);
|
|
68
|
+
const url = new URL(this.authWindow.location.href);
|
|
69
|
+
const code = url.searchParams.get('code');
|
|
70
|
+
const state = url.searchParams.get('state');
|
|
71
|
+
const error = url.searchParams.get('error');
|
|
72
|
+
this.authWindow.close();
|
|
73
|
+
this.authWindow = null;
|
|
74
|
+
resolve({
|
|
75
|
+
code: code || undefined,
|
|
76
|
+
state: state || undefined,
|
|
77
|
+
error: error || undefined,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (_c) {
|
|
82
|
+
// Cross-origin error, ignore
|
|
83
|
+
}
|
|
84
|
+
}, 1000);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async isSupported() {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
async linkAccount(_options) {
|
|
91
|
+
throw new AuthError('NOT_SUPPORTED', 'Account linking is not supported for Slack provider');
|
|
92
|
+
}
|
|
93
|
+
async unlinkAccount(_options) {
|
|
94
|
+
throw new AuthError('NOT_SUPPORTED', 'Account unlinking is not supported for Slack provider');
|
|
95
|
+
}
|
|
96
|
+
async revokeAccess(token) {
|
|
97
|
+
await super.revokeAccess(token);
|
|
98
|
+
}
|
|
99
|
+
async signOut(_options) {
|
|
100
|
+
await this.clearStoredData();
|
|
101
|
+
await this.setCurrentUser(null);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Provider manifest for dynamic loading
|
|
105
|
+
export const SlackProviderManifest = {
|
|
106
|
+
name: 'slack',
|
|
107
|
+
displayName: 'Slack',
|
|
108
|
+
iconUrl: 'https://cdn.jsdelivr.net/npm/simple-icons@v9/icons/slack.svg',
|
|
109
|
+
description: 'Sign in with Slack workspace',
|
|
110
|
+
setupInstructions: `
|
|
111
|
+
To use Slack authentication:
|
|
112
|
+
|
|
113
|
+
1. Create a Slack App:
|
|
114
|
+
- Go to https://api.slack.com/apps
|
|
115
|
+
- Click "Create New App" > "From scratch"
|
|
116
|
+
- Name your app and select workspace
|
|
117
|
+
|
|
118
|
+
2. Configure OAuth & Permissions:
|
|
119
|
+
- Add redirect URL: https://your-app.com/auth/slack/callback
|
|
120
|
+
- Add required scopes:
|
|
121
|
+
- openid
|
|
122
|
+
- profile
|
|
123
|
+
- email
|
|
124
|
+
|
|
125
|
+
3. Get your credentials:
|
|
126
|
+
- Go to "Basic Information"
|
|
127
|
+
- Copy Client ID and Client Secret
|
|
128
|
+
|
|
129
|
+
4. Configure the provider:
|
|
130
|
+
\`\`\`javascript
|
|
131
|
+
auth.configure({
|
|
132
|
+
providers: {
|
|
133
|
+
slack: {
|
|
134
|
+
clientId: 'YOUR_CLIENT_ID',
|
|
135
|
+
redirectUri: 'https://your-app.com/auth/slack/callback',
|
|
136
|
+
scopes: ['openid', 'profile', 'email'],
|
|
137
|
+
teamId: 'OPTIONAL_TEAM_ID' // Restrict to specific workspace
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
\`\`\`
|
|
142
|
+
|
|
143
|
+
5. Use the provider:
|
|
144
|
+
\`\`\`javascript
|
|
145
|
+
await auth.signIn('slack');
|
|
146
|
+
\`\`\`
|
|
147
|
+
|
|
148
|
+
Note: Slack OAuth requires a backend service to exchange the authorization code for access tokens.
|
|
149
|
+
`,
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=slack-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slack-provider.js","sourceRoot":"","sources":["../../../../src/providers/web/slack-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAOb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,aAAa,GAId,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AASnD,MAAM,OAAO,aAAc,SAAQ,aAAa;IAQ9C,YAAY,MAA0B;QACpC,KAAK,CAAC,MAAM,CAAC,CAAC;QARhB,aAAQ,GAAG,YAAY,CAAC,KAAK,CAAC;QACtB,aAAQ,GAAG,EAAE,CAAC;QACd,gBAAW,GAAG,EAAE,CAAC;QACjB,WAAM,GAAa,EAAE,CAAC;QAEtB,eAAU,GAAkB,IAAI,CAAC;QAIvC,MAAM,OAAO,GAAG,MAAM,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AAE,IAAI,IAAI,SAAS;4BACvB,KAAK,EAAE,KAAK,IAAI,SAAS;4BACzB,KAAK,EAAE,KAAK,IAAI,SAAS;yBAC1B,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;gBAAC,WAAM,CAAC;oBACP,6BAA6B;gBAC/B,CAAC;YACH,CAAC,EAAE,IAAI,CAAC,CAAC;QACX,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,WAAW;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,QAA4B;QAC5C,MAAM,IAAI,SAAS,CACjB,eAAe,EACf,qDAAqD,CACtD,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,QAA8B;QAChD,MAAM,IAAI,SAAS,CACjB,eAAe,EACf,uDAAuD,CACxD,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,KAAc;QAC/B,MAAM,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,QAAyB;QACrC,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC7B,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACF;AAED,wCAAwC;AACxC,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,OAAO;IACb,WAAW,EAAE,OAAO;IACpB,OAAO,EAAE,8DAA8D;IACvE,WAAW,EAAE,8BAA8B;IAC3C,iBAAiB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCpB;CACA,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AuthResult, AuthUser, SignInOptions, RefreshTokenOptions } from '../../definitions';
|
|
2
|
+
import { AuthProviderInterface } from '../../core/types';
|
|
3
|
+
export interface SMSConfig {
|
|
4
|
+
sendCodeUrl: string;
|
|
5
|
+
verifyCodeUrl: string;
|
|
6
|
+
clientId?: string;
|
|
7
|
+
countryCode?: string;
|
|
8
|
+
codeLength?: number;
|
|
9
|
+
resendDelay?: number;
|
|
10
|
+
}
|
|
11
|
+
interface SMSOptions extends SignInOptions {
|
|
12
|
+
phoneNumber: string;
|
|
13
|
+
code?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class SMSProvider implements AuthProviderInterface {
|
|
16
|
+
name: string;
|
|
17
|
+
private config;
|
|
18
|
+
private pendingVerifications;
|
|
19
|
+
private readonly MAX_ATTEMPTS;
|
|
20
|
+
constructor(config: SMSConfig);
|
|
21
|
+
signIn(options?: SMSOptions): Promise<AuthResult>;
|
|
22
|
+
private sendCode;
|
|
23
|
+
private verifyCode;
|
|
24
|
+
signOut(): Promise<void>;
|
|
25
|
+
getCurrentUser(): Promise<AuthUser | null>;
|
|
26
|
+
refreshToken(_options?: RefreshTokenOptions): Promise<AuthResult>;
|
|
27
|
+
private formatPhoneNumber;
|
|
28
|
+
private maskPhoneNumber;
|
|
29
|
+
private generateUid;
|
|
30
|
+
resendCode(phoneNumber: string): Promise<AuthResult>;
|
|
31
|
+
canResendCode(phoneNumber: string): {
|
|
32
|
+
canResend: boolean;
|
|
33
|
+
waitTime?: number;
|
|
34
|
+
};
|
|
35
|
+
initialize(): Promise<void>;
|
|
36
|
+
isSupported(): Promise<boolean>;
|
|
37
|
+
linkAccount(_options: any): Promise<AuthResult>;
|
|
38
|
+
unlinkAccount(_options: any): Promise<void>;
|
|
39
|
+
revokeAccess(_token?: string): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export declare const SMSProviderManifest: {
|
|
42
|
+
name: string;
|
|
43
|
+
displayName: string;
|
|
44
|
+
iconUrl: string;
|
|
45
|
+
description: string;
|
|
46
|
+
setupInstructions: string;
|
|
47
|
+
};
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { AuthError } from '../../utils/auth-error';
|
|
2
|
+
export class SMSProvider {
|
|
3
|
+
constructor(config) {
|
|
4
|
+
this.name = 'sms';
|
|
5
|
+
this.pendingVerifications = new Map();
|
|
6
|
+
this.MAX_ATTEMPTS = 3;
|
|
7
|
+
// Initialize with config
|
|
8
|
+
this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, config);
|
|
9
|
+
}
|
|
10
|
+
async signIn(options) {
|
|
11
|
+
if (!(options === null || options === void 0 ? void 0 : options.phoneNumber)) {
|
|
12
|
+
throw new AuthError('PHONE_REQUIRED', 'Phone number is required for SMS authentication');
|
|
13
|
+
}
|
|
14
|
+
// If code is provided, verify it
|
|
15
|
+
if (options.code) {
|
|
16
|
+
return this.verifyCode(options.phoneNumber, options.code);
|
|
17
|
+
}
|
|
18
|
+
// Otherwise, send code
|
|
19
|
+
return this.sendCode(options.phoneNumber);
|
|
20
|
+
}
|
|
21
|
+
async sendCode(phoneNumber) {
|
|
22
|
+
try {
|
|
23
|
+
// Format phone number
|
|
24
|
+
const formattedPhone = this.formatPhoneNumber(phoneNumber);
|
|
25
|
+
// Check if we can resend
|
|
26
|
+
const existing = this.pendingVerifications.get(formattedPhone);
|
|
27
|
+
if (existing && existing.lastResent) {
|
|
28
|
+
const timeSinceLastResend = Date.now() - existing.lastResent;
|
|
29
|
+
if (timeSinceLastResend < this.config.resendDelay) {
|
|
30
|
+
const waitTime = Math.ceil((this.config.resendDelay - timeSinceLastResend) / 1000);
|
|
31
|
+
throw new AuthError('RESEND_DELAY', `Please wait ${waitTime} seconds before requesting a new code`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Send SMS code via backend
|
|
35
|
+
const response = await fetch(this.config.sendCodeUrl, {
|
|
36
|
+
method: 'POST',
|
|
37
|
+
headers: {
|
|
38
|
+
'Content-Type': 'application/json',
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify({
|
|
41
|
+
phoneNumber: formattedPhone,
|
|
42
|
+
clientId: this.config.clientId,
|
|
43
|
+
codeLength: this.config.codeLength,
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
const error = await response.json().catch(() => ({}));
|
|
48
|
+
throw new AuthError('SEND_CODE_FAILED', error.message || 'Failed to send SMS code');
|
|
49
|
+
}
|
|
50
|
+
const data = await response.json();
|
|
51
|
+
// Store pending verification
|
|
52
|
+
this.pendingVerifications.set(formattedPhone, {
|
|
53
|
+
phoneNumber: formattedPhone,
|
|
54
|
+
sessionId: data.sessionId,
|
|
55
|
+
expires: Date.now() + 10 * 60 * 1000, // 10 minutes
|
|
56
|
+
attempts: 0,
|
|
57
|
+
lastResent: Date.now(),
|
|
58
|
+
});
|
|
59
|
+
// Return partial auth result for pending state
|
|
60
|
+
// SMS requires two-step process, so we return a temporary user
|
|
61
|
+
const tempUser = {
|
|
62
|
+
uid: `sms-pending:${data.sessionId}`,
|
|
63
|
+
email: null,
|
|
64
|
+
displayName: this.maskPhoneNumber(formattedPhone),
|
|
65
|
+
photoURL: null,
|
|
66
|
+
phoneNumber: formattedPhone,
|
|
67
|
+
emailVerified: false,
|
|
68
|
+
providerData: [],
|
|
69
|
+
metadata: {
|
|
70
|
+
creationTime: new Date().toISOString(),
|
|
71
|
+
lastSignInTime: new Date().toISOString(),
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
user: tempUser,
|
|
76
|
+
credential: {
|
|
77
|
+
providerId: this.name,
|
|
78
|
+
signInMethod: 'sms',
|
|
79
|
+
accessToken: data.sessionId,
|
|
80
|
+
},
|
|
81
|
+
additionalUserInfo: {
|
|
82
|
+
isNewUser: false,
|
|
83
|
+
providerId: this.name,
|
|
84
|
+
profile: {
|
|
85
|
+
phoneNumber: formattedPhone,
|
|
86
|
+
sessionId: data.sessionId,
|
|
87
|
+
message: `SMS code sent to ${this.maskPhoneNumber(formattedPhone)}`,
|
|
88
|
+
pending: true,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
if (error instanceof AuthError)
|
|
95
|
+
throw error;
|
|
96
|
+
throw new AuthError('SMS_ERROR', error.message || 'Failed to send SMS code');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async verifyCode(phoneNumber, code) {
|
|
100
|
+
const formattedPhone = this.formatPhoneNumber(phoneNumber);
|
|
101
|
+
const pending = this.pendingVerifications.get(formattedPhone);
|
|
102
|
+
if (!pending) {
|
|
103
|
+
throw new AuthError('NO_PENDING_VERIFICATION', 'No pending SMS verification found');
|
|
104
|
+
}
|
|
105
|
+
if (Date.now() > pending.expires) {
|
|
106
|
+
this.pendingVerifications.delete(formattedPhone);
|
|
107
|
+
throw new AuthError('CODE_EXPIRED', 'SMS code has expired');
|
|
108
|
+
}
|
|
109
|
+
if (pending.attempts >= this.MAX_ATTEMPTS) {
|
|
110
|
+
this.pendingVerifications.delete(formattedPhone);
|
|
111
|
+
throw new AuthError('TOO_MANY_ATTEMPTS', 'Too many failed attempts');
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
// Increment attempts
|
|
115
|
+
pending.attempts++;
|
|
116
|
+
// Verify code with backend
|
|
117
|
+
const response = await fetch(this.config.verifyCodeUrl, {
|
|
118
|
+
method: 'POST',
|
|
119
|
+
headers: {
|
|
120
|
+
'Content-Type': 'application/json',
|
|
121
|
+
},
|
|
122
|
+
body: JSON.stringify({
|
|
123
|
+
phoneNumber: formattedPhone,
|
|
124
|
+
code,
|
|
125
|
+
sessionId: pending.sessionId,
|
|
126
|
+
clientId: this.config.clientId,
|
|
127
|
+
}),
|
|
128
|
+
});
|
|
129
|
+
if (!response.ok) {
|
|
130
|
+
const error = await response.json().catch(() => ({}));
|
|
131
|
+
if (response.status === 401) {
|
|
132
|
+
throw new AuthError('INVALID_CODE', 'Invalid SMS code');
|
|
133
|
+
}
|
|
134
|
+
throw new AuthError('VERIFICATION_FAILED', error.message || 'Failed to verify SMS code');
|
|
135
|
+
}
|
|
136
|
+
const data = await response.json();
|
|
137
|
+
// Create user from verified data
|
|
138
|
+
const user = {
|
|
139
|
+
uid: data.uid || this.generateUid(formattedPhone),
|
|
140
|
+
email: data.email || null,
|
|
141
|
+
displayName: data.displayName || formattedPhone,
|
|
142
|
+
photoURL: data.photoURL || null,
|
|
143
|
+
phoneNumber: formattedPhone,
|
|
144
|
+
emailVerified: false,
|
|
145
|
+
providerData: [
|
|
146
|
+
{
|
|
147
|
+
providerId: this.name,
|
|
148
|
+
uid: data.uid || phoneNumber,
|
|
149
|
+
displayName: phoneNumber,
|
|
150
|
+
email: null,
|
|
151
|
+
phoneNumber: phoneNumber,
|
|
152
|
+
photoURL: null,
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
metadata: {
|
|
156
|
+
creationTime: data.createdAt || new Date().toISOString(),
|
|
157
|
+
lastSignInTime: new Date().toISOString(),
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
// Clean up pending verification
|
|
161
|
+
this.pendingVerifications.delete(formattedPhone);
|
|
162
|
+
return {
|
|
163
|
+
user,
|
|
164
|
+
credential: {
|
|
165
|
+
providerId: this.name,
|
|
166
|
+
signInMethod: 'sms',
|
|
167
|
+
accessToken: data.accessToken,
|
|
168
|
+
refreshToken: data.refreshToken,
|
|
169
|
+
expiresAt: data.expiresAt,
|
|
170
|
+
},
|
|
171
|
+
additionalUserInfo: {
|
|
172
|
+
isNewUser: data.isNewUser || false,
|
|
173
|
+
providerId: this.name,
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
if (error instanceof AuthError)
|
|
179
|
+
throw error;
|
|
180
|
+
throw new AuthError('VERIFICATION_ERROR', error.message || 'Failed to verify SMS code');
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async signOut() {
|
|
184
|
+
// Clear any pending verifications
|
|
185
|
+
this.pendingVerifications.clear();
|
|
186
|
+
}
|
|
187
|
+
async getCurrentUser() {
|
|
188
|
+
// SMS auth doesn't persist sessions by default
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
async refreshToken(_options) {
|
|
192
|
+
// Token refresh would be implemented based on backend requirements
|
|
193
|
+
throw new AuthError('NOT_IMPLEMENTED', 'Token refresh is not yet implemented for SMS authentication');
|
|
194
|
+
}
|
|
195
|
+
formatPhoneNumber(phoneNumber) {
|
|
196
|
+
// Remove all non-numeric characters
|
|
197
|
+
let cleaned = phoneNumber.replace(/\D/g, '');
|
|
198
|
+
// Add country code if not present
|
|
199
|
+
if (!phoneNumber.startsWith('+')) {
|
|
200
|
+
if (cleaned.length === 10) {
|
|
201
|
+
// Assume US number without country code
|
|
202
|
+
cleaned = '1' + cleaned;
|
|
203
|
+
}
|
|
204
|
+
cleaned = this.config.countryCode.replace('+', '') + cleaned;
|
|
205
|
+
}
|
|
206
|
+
return '+' + cleaned;
|
|
207
|
+
}
|
|
208
|
+
maskPhoneNumber(phoneNumber) {
|
|
209
|
+
// Show only last 4 digits
|
|
210
|
+
const digits = phoneNumber.replace(/\D/g, '');
|
|
211
|
+
const lastFour = digits.slice(-4);
|
|
212
|
+
return `***-***-${lastFour}`;
|
|
213
|
+
}
|
|
214
|
+
generateUid(phoneNumber) {
|
|
215
|
+
return `sms:${phoneNumber.replace(/\D/g, '')}`;
|
|
216
|
+
}
|
|
217
|
+
// Public method to resend code
|
|
218
|
+
async resendCode(phoneNumber) {
|
|
219
|
+
return this.sendCode(phoneNumber);
|
|
220
|
+
}
|
|
221
|
+
// Public method to check if can resend
|
|
222
|
+
canResendCode(phoneNumber) {
|
|
223
|
+
const formattedPhone = this.formatPhoneNumber(phoneNumber);
|
|
224
|
+
const pending = this.pendingVerifications.get(formattedPhone);
|
|
225
|
+
if (!pending || !pending.lastResent) {
|
|
226
|
+
return { canResend: true };
|
|
227
|
+
}
|
|
228
|
+
const timeSinceLastResend = Date.now() - pending.lastResent;
|
|
229
|
+
if (timeSinceLastResend < this.config.resendDelay) {
|
|
230
|
+
return {
|
|
231
|
+
canResend: false,
|
|
232
|
+
waitTime: Math.ceil((this.config.resendDelay - timeSinceLastResend) / 1000),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
return { canResend: true };
|
|
236
|
+
}
|
|
237
|
+
async initialize() {
|
|
238
|
+
// SMS provider doesn't require initialization
|
|
239
|
+
}
|
|
240
|
+
async isSupported() {
|
|
241
|
+
// SMS auth is supported if we have the required config
|
|
242
|
+
return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
|
|
243
|
+
}
|
|
244
|
+
async linkAccount(_options) {
|
|
245
|
+
throw new AuthError('NOT_SUPPORTED', 'Account linking is not supported for SMS authentication');
|
|
246
|
+
}
|
|
247
|
+
async unlinkAccount(_options) {
|
|
248
|
+
throw new AuthError('NOT_SUPPORTED', 'Account unlinking is not supported for SMS authentication');
|
|
249
|
+
}
|
|
250
|
+
async revokeAccess(_token) {
|
|
251
|
+
// SMS auth doesn't have persistent access to revoke
|
|
252
|
+
this.pendingVerifications.clear();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
// Provider manifest for dynamic loading
|
|
256
|
+
export const SMSProviderManifest = {
|
|
257
|
+
name: 'sms',
|
|
258
|
+
displayName: 'SMS Authentication',
|
|
259
|
+
iconUrl: 'https://cdn.jsdelivr.net/npm/simple-icons@v9/icons/sms.svg',
|
|
260
|
+
description: 'Phone number authentication via SMS',
|
|
261
|
+
setupInstructions: `
|
|
262
|
+
To use SMS authentication:
|
|
263
|
+
|
|
264
|
+
1. Set up backend endpoints:
|
|
265
|
+
- Send code endpoint: POST request to send SMS
|
|
266
|
+
- Verify code endpoint: POST request to verify SMS code
|
|
267
|
+
|
|
268
|
+
2. Configure the provider:
|
|
269
|
+
\`\`\`javascript
|
|
270
|
+
auth.configure({
|
|
271
|
+
providers: {
|
|
272
|
+
sms: {
|
|
273
|
+
sendCodeUrl: 'https://your-api.com/sms/send',
|
|
274
|
+
verifyCodeUrl: 'https://your-api.com/sms/verify',
|
|
275
|
+
countryCode: '+1', // Default country code
|
|
276
|
+
codeLength: 6, // SMS code length
|
|
277
|
+
resendDelay: 60000 // Minimum time between resends (ms)
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
\`\`\`
|
|
282
|
+
|
|
283
|
+
3. Send SMS code:
|
|
284
|
+
\`\`\`javascript
|
|
285
|
+
const result = await auth.signIn('sms', { phoneNumber: '+1234567890' });
|
|
286
|
+
// Returns pending state with sessionId
|
|
287
|
+
\`\`\`
|
|
288
|
+
|
|
289
|
+
4. Verify SMS code:
|
|
290
|
+
\`\`\`javascript
|
|
291
|
+
const result = await auth.signIn('sms', {
|
|
292
|
+
phoneNumber: '+1234567890',
|
|
293
|
+
code: '123456'
|
|
294
|
+
});
|
|
295
|
+
\`\`\`
|
|
296
|
+
|
|
297
|
+
Note: This provider requires a backend service to send SMS messages.
|
|
298
|
+
You'll need to integrate with an SMS service like Twilio, AWS SNS, etc.
|
|
299
|
+
`,
|
|
300
|
+
};
|
|
301
|
+
//# sourceMappingURL=sms-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sms-provider.js","sourceRoot":"","sources":["../../../../src/providers/web/sms-provider.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAyBnD,MAAM,OAAO,WAAW;IAMtB,YAAY,MAAiB;QAL7B,SAAI,GAAG,KAAK,CAAC;QAEL,yBAAoB,GAA4B,IAAI,GAAG,EAAE,CAAC;QACjD,iBAAY,GAAG,CAAC,CAAC;QAGhC,yBAAyB;QACzB,IAAI,CAAC,MAAM,mBACT,WAAW,EAAE,IAAI,EACjB,UAAU,EAAE,CAAC,EACb,WAAW,EAAE,KAAK,IACf,MAAM,CACV,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAoB;QAC/B,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAA,EAAE,CAAC;YAC1B,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E,CAAC;IACpC,CAAC;CACF;AAED,wCAAwC;AACxC,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,IAAI,EAAE,KAAK;IACX,WAAW,EAAE,oBAAoB;IACjC,OAAO,EAAE,4DAA4D;IACrE,WAAW,EAAE,qCAAqC;IAClD,iBAAiB,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCpB;CACA,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { AuthResult, AuthUser, SignInOptions, SignUpOptions, RefreshTokenOptions } from '../../definitions';
|
|
2
|
+
import { AuthProviderInterface } from '../../core/types';
|
|
3
|
+
export interface UsernamePasswordConfig {
|
|
4
|
+
apiUrl: string;
|
|
5
|
+
clientId?: string;
|
|
6
|
+
usernameRequirements?: {
|
|
7
|
+
minLength?: number;
|
|
8
|
+
maxLength?: number;
|
|
9
|
+
allowedCharacters?: RegExp;
|
|
10
|
+
reservedUsernames?: string[];
|
|
11
|
+
};
|
|
12
|
+
passwordRequirements?: {
|
|
13
|
+
minLength?: number;
|
|
14
|
+
requireUppercase?: boolean;
|
|
15
|
+
requireLowercase?: boolean;
|
|
16
|
+
requireNumbers?: boolean;
|
|
17
|
+
requireSpecialChars?: boolean;
|
|
18
|
+
};
|
|
19
|
+
allowSignUp?: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface UsernamePasswordSignInOptions extends SignInOptions {
|
|
22
|
+
username: string;
|
|
23
|
+
password: string;
|
|
24
|
+
}
|
|
25
|
+
interface UsernamePasswordSignUpOptions extends SignUpOptions {
|
|
26
|
+
username: string;
|
|
27
|
+
password: string;
|
|
28
|
+
email?: string;
|
|
29
|
+
displayName?: string;
|
|
30
|
+
photoURL?: string;
|
|
31
|
+
}
|
|
32
|
+
export declare class UsernamePasswordProvider implements AuthProviderInterface {
|
|
33
|
+
name: string;
|
|
34
|
+
private config;
|
|
35
|
+
private currentUser;
|
|
36
|
+
private authToken;
|
|
37
|
+
private refreshTokenValue;
|
|
38
|
+
constructor(config: UsernamePasswordConfig);
|
|
39
|
+
signIn(options?: UsernamePasswordSignInOptions): Promise<AuthResult>;
|
|
40
|
+
signUp(options?: UsernamePasswordSignUpOptions): Promise<AuthResult>;
|
|
41
|
+
signOut(): Promise<void>;
|
|
42
|
+
getCurrentUser(): Promise<AuthUser | null>;
|
|
43
|
+
refreshToken(_options?: RefreshTokenOptions): Promise<AuthResult>;
|
|
44
|
+
updatePassword(currentPassword: string, newPassword: string): Promise<void>;
|
|
45
|
+
checkUsernameAvailability(username: string): Promise<boolean>;
|
|
46
|
+
private isValidEmail;
|
|
47
|
+
private validateUsername;
|
|
48
|
+
private validatePassword;
|
|
49
|
+
initialize(): Promise<void>;
|
|
50
|
+
isSupported(): Promise<boolean>;
|
|
51
|
+
linkAccount(_options: any): Promise<AuthResult>;
|
|
52
|
+
unlinkAccount(_options: any): Promise<void>;
|
|
53
|
+
revokeAccess(_token?: string): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
export declare const UsernamePasswordProviderManifest: {
|
|
56
|
+
name: string;
|
|
57
|
+
displayName: string;
|
|
58
|
+
iconUrl: string;
|
|
59
|
+
description: string;
|
|
60
|
+
setupInstructions: string;
|
|
61
|
+
};
|
|
62
|
+
export {};
|