capacitor-auth-manager 1.1.0 → 2.2.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 +495 -630
- 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 +7017 -0
- package/dist/angular.cjs.js.map +1 -0
- package/dist/core.cjs.js +6663 -0
- package/dist/core.cjs.js.map +1 -0
- 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/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 +93 -0
- package/dist/esm/core/auth-manager.js +557 -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 +24 -0
- package/dist/esm/core/platform.js +100 -0
- package/dist/esm/core/platform.js.map +1 -0
- 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 +39 -0
- package/dist/esm/core/provider-registry.js +197 -0
- package/dist/esm/core/provider-registry.js.map +1 -0
- package/dist/esm/core/types.d.ts +46 -0
- package/dist/esm/core/types.js +2 -0
- package/dist/esm/core/types.js.map +1 -0
- package/dist/esm/definitions.d.ts +81 -5
- package/dist/esm/definitions.js +42 -4
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +11 -5
- package/dist/esm/index.js +14 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/providers/base-provider.d.ts +6 -4
- package/dist/esm/providers/base-provider.js +34 -6
- 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 +152 -33
- 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 +30 -42
- 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 +52 -28
- package/dist/esm/providers/web/apple-provider.js.map +1 -1
- package/dist/esm/providers/web/biometric-provider.d.ts +61 -0
- package/dist/esm/providers/web/biometric-provider.js +365 -0
- package/dist/esm/providers/web/biometric-provider.js.map +1 -0
- package/dist/esm/providers/web/email-code-provider.d.ts +48 -0
- package/dist/esm/providers/web/email-code-provider.js +295 -0
- package/dist/esm/providers/web/email-code-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 +430 -0
- package/dist/esm/providers/web/email-password-provider.js.map +1 -0
- package/dist/esm/providers/web/facebook-provider.d.ts +80 -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 +22 -0
- package/dist/esm/providers/web/firebase-provider.js +338 -0
- package/dist/esm/providers/web/firebase-provider.js.map +1 -0
- package/dist/esm/providers/web/github-provider.d.ts +34 -0
- package/dist/esm/providers/web/github-provider.js +325 -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 +15 -0
- package/dist/esm/providers/web/index.js +17 -0
- package/dist/esm/providers/web/index.js.map +1 -0
- package/dist/esm/providers/web/linkedin-provider.d.ts +37 -0
- package/dist/esm/providers/web/linkedin-provider.js +178 -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 +312 -0
- package/dist/esm/providers/web/magic-link-provider.js.map +1 -0
- package/dist/esm/providers/web/microsoft-provider.d.ts +23 -0
- package/dist/esm/providers/web/microsoft-provider.js +236 -0
- package/dist/esm/providers/web/microsoft-provider.js.map +1 -0
- package/dist/esm/providers/web/phone-password-provider.d.ts +66 -0
- package/dist/esm/providers/web/phone-password-provider.js +438 -0
- package/dist/esm/providers/web/phone-password-provider.js.map +1 -0
- package/dist/esm/providers/web/slack-provider.d.ts +39 -0
- package/dist/esm/providers/web/slack-provider.js +175 -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 +308 -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 +433 -0
- package/dist/esm/providers/web/username-password-provider.js.map +1 -0
- 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 +38 -10
- 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 +9 -3
- 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 +33 -5
- package/dist/esm/utils/storage.js +77 -8
- 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 +254 -55
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +6625 -950
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +6625 -950
- package/dist/plugin.js.map +1 -1
- package/dist/react.cjs.js +6972 -0
- package/dist/react.cjs.js.map +1 -0
- package/dist/vue.cjs.js +6955 -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 +106 -24
- package/scripts/configure.js +105 -61
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SignInOptions, SignOutOptions, LinkAccountOptions, UnlinkAccountOptions, AuthResult } from '../../definitions';
|
|
1
|
+
import { SignInOptions, SignOutOptions, LinkAccountOptions, UnlinkAccountOptions, RefreshTokenOptions, AuthResult } from '../../definitions';
|
|
2
2
|
import { OAuthProvider, OAuthConfig, OAuthTokenResponse, OAuthUserInfo } from '../oauth-provider';
|
|
3
3
|
import { BaseProviderConfig } from '../base-provider';
|
|
4
4
|
interface AppleSignInResponse {
|
|
@@ -41,6 +41,7 @@ export declare class AppleAuthProviderWeb extends OAuthProvider {
|
|
|
41
41
|
private _initialize;
|
|
42
42
|
signIn(options?: SignInOptions): Promise<AuthResult>;
|
|
43
43
|
signOut(_options?: SignOutOptions): Promise<void>;
|
|
44
|
+
refreshToken(_options?: RefreshTokenOptions): Promise<AuthResult>;
|
|
44
45
|
isSupported(): Promise<boolean>;
|
|
45
46
|
linkAccount(options: LinkAccountOptions): Promise<AuthResult>;
|
|
46
47
|
unlinkAccount(_options: UnlinkAccountOptions): Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AuthProvider, AppleAuthScope, AuthErrorCode, } from '../../definitions';
|
|
2
|
-
import { OAuthProvider } from '../oauth-provider';
|
|
2
|
+
import { OAuthProvider, } from '../oauth-provider';
|
|
3
3
|
import { AuthError } from '../../utils/auth-error';
|
|
4
4
|
export class AppleAuthProviderWeb extends OAuthProvider {
|
|
5
5
|
constructor(config) {
|
|
@@ -83,8 +83,8 @@ export class AppleAuthProviderWeb extends OAuthProvider {
|
|
|
83
83
|
const response = await window.AppleID.auth.signIn(signInConfig);
|
|
84
84
|
// Validate response
|
|
85
85
|
await this.validateAppleResponse(response, state, nonce);
|
|
86
|
-
// Parse user information from response
|
|
87
|
-
const user = this.createAppleAuthUser(response);
|
|
86
|
+
// Parse user information from response (validates ID token nonce + expiry first)
|
|
87
|
+
const user = this.createAppleAuthUser(response, nonce);
|
|
88
88
|
const credential = this.createAppleCredential(response);
|
|
89
89
|
// Save user and credential
|
|
90
90
|
await this.setCurrentUser(user);
|
|
@@ -118,13 +118,20 @@ export class AppleAuthProviderWeb extends OAuthProvider {
|
|
|
118
118
|
throw AuthError.fromError(error, this.provider);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
+
async refreshToken(_options) {
|
|
122
|
+
// Apple's JS (web) Sign In flow never issues a refresh token, so the inherited
|
|
123
|
+
// OAuthProvider.refreshToken() would fail with a confusing "No refresh token available".
|
|
124
|
+
// Surface an explicit, accurate error instead: callers must re-authenticate.
|
|
125
|
+
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Apple web sign-in does not issue refresh tokens; re-authenticate instead.', this.provider);
|
|
126
|
+
}
|
|
121
127
|
async isSupported() {
|
|
122
128
|
// Check if we're in a browser environment
|
|
123
129
|
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
124
130
|
return false;
|
|
125
131
|
}
|
|
126
132
|
// Check if we're on HTTPS (required for Apple Sign In)
|
|
127
|
-
if (window.location.protocol !== 'https:' &&
|
|
133
|
+
if (window.location.protocol !== 'https:' &&
|
|
134
|
+
window.location.hostname !== 'localhost') {
|
|
128
135
|
return false;
|
|
129
136
|
}
|
|
130
137
|
return true;
|
|
@@ -153,7 +160,8 @@ export class AppleAuthProviderWeb extends OAuthProvider {
|
|
|
153
160
|
}
|
|
154
161
|
return new Promise((resolve, reject) => {
|
|
155
162
|
const script = document.createElement('script');
|
|
156
|
-
script.src =
|
|
163
|
+
script.src =
|
|
164
|
+
'https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js';
|
|
157
165
|
script.async = true;
|
|
158
166
|
script.defer = true;
|
|
159
167
|
script.onload = () => {
|
|
@@ -175,7 +183,7 @@ export class AppleAuthProviderWeb extends OAuthProvider {
|
|
|
175
183
|
if (!scopes || scopes.length === 0) {
|
|
176
184
|
return [];
|
|
177
185
|
}
|
|
178
|
-
return scopes.map(scope => {
|
|
186
|
+
return scopes.map((scope) => {
|
|
179
187
|
switch (scope) {
|
|
180
188
|
case AppleAuthScope.EMAIL:
|
|
181
189
|
return 'email';
|
|
@@ -196,38 +204,54 @@ export class AppleAuthProviderWeb extends OAuthProvider {
|
|
|
196
204
|
// ID token validation with nonce would be done here
|
|
197
205
|
// For production, you should validate the ID token on your backend
|
|
198
206
|
}
|
|
199
|
-
createAppleAuthUser(response) {
|
|
207
|
+
createAppleAuthUser(response, expectedNonce) {
|
|
200
208
|
var _a, _b, _c;
|
|
201
209
|
const user = response.user || {};
|
|
202
210
|
const idToken = (_a = response.authorization) === null || _a === void 0 ? void 0 : _a.id_token;
|
|
203
|
-
//
|
|
211
|
+
// Validate the ID token's nonce (replay protection) and expiry BEFORE trusting any
|
|
212
|
+
// claims. The signature is NOT verified client-side — always re-validate on your backend.
|
|
213
|
+
// Defensive: only enforce the nonce when both an expected nonce and a token nonce exist.
|
|
204
214
|
let claims = {};
|
|
205
215
|
if (idToken) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
claims =
|
|
216
|
+
const payload = this.decodeJwtPayload(idToken);
|
|
217
|
+
if (payload) {
|
|
218
|
+
claims = payload;
|
|
219
|
+
if (expectedNonce &&
|
|
220
|
+
claims.nonce !== undefined &&
|
|
221
|
+
claims.nonce !== expectedNonce) {
|
|
222
|
+
throw new AuthError(AuthErrorCode.INVALID_NONCE, 'Apple ID token nonce does not match the expected value', this.provider);
|
|
223
|
+
}
|
|
224
|
+
if (typeof claims.exp === 'number' && claims.exp * 1000 < Date.now()) {
|
|
225
|
+
throw new AuthError(AuthErrorCode.TOKEN_EXPIRED, 'Apple ID token is expired', this.provider);
|
|
226
|
+
}
|
|
209
227
|
}
|
|
210
|
-
|
|
211
|
-
this.logger.error('Failed to
|
|
228
|
+
else {
|
|
229
|
+
this.logger.error('Failed to decode Apple ID token payload');
|
|
212
230
|
}
|
|
213
231
|
}
|
|
214
232
|
return {
|
|
215
233
|
uid: claims.sub || ((_b = response.authorization) === null || _b === void 0 ? void 0 : _b.code) || this.generateUniqueId(),
|
|
216
234
|
email: user.email || claims.email || null,
|
|
217
235
|
emailVerified: claims.email_verified || false,
|
|
218
|
-
displayName: user.name
|
|
236
|
+
displayName: user.name
|
|
237
|
+
? `${user.name.firstName || ''} ${user.name.lastName || ''}`.trim()
|
|
238
|
+
: null,
|
|
219
239
|
photoURL: null, // Apple doesn't provide profile photos
|
|
220
240
|
phoneNumber: null,
|
|
221
241
|
isAnonymous: false,
|
|
222
242
|
tenantId: null,
|
|
223
|
-
providerData: [
|
|
243
|
+
providerData: [
|
|
244
|
+
{
|
|
224
245
|
providerId: AuthProvider.APPLE,
|
|
225
246
|
uid: claims.sub || ((_c = response.authorization) === null || _c === void 0 ? void 0 : _c.code) || '',
|
|
226
|
-
displayName: user.name
|
|
247
|
+
displayName: user.name
|
|
248
|
+
? `${user.name.firstName || ''} ${user.name.lastName || ''}`.trim()
|
|
249
|
+
: null,
|
|
227
250
|
email: user.email || claims.email || null,
|
|
228
251
|
phoneNumber: null,
|
|
229
252
|
photoURL: null,
|
|
230
|
-
}
|
|
253
|
+
},
|
|
254
|
+
],
|
|
231
255
|
metadata: {
|
|
232
256
|
creationTime: new Date().toISOString(),
|
|
233
257
|
lastSignInTime: new Date().toISOString(),
|
|
@@ -251,17 +275,17 @@ export class AppleAuthProviderWeb extends OAuthProvider {
|
|
|
251
275
|
}
|
|
252
276
|
mapAppleError(error) {
|
|
253
277
|
const errorMap = {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
278
|
+
user_cancelled_authorize: AuthErrorCode.USER_CANCELLED,
|
|
279
|
+
popup_closed_by_user: AuthErrorCode.POPUP_CLOSED_BY_USER,
|
|
280
|
+
popup_blocked: AuthErrorCode.POPUP_BLOCKED,
|
|
281
|
+
invalid_request: AuthErrorCode.INVALID_REQUEST,
|
|
282
|
+
invalid_client: AuthErrorCode.CLIENT_NOT_FOUND,
|
|
283
|
+
invalid_scope: AuthErrorCode.INVALID_SCOPE,
|
|
284
|
+
unauthorized_client: AuthErrorCode.APP_NOT_AUTHORIZED,
|
|
285
|
+
access_denied: AuthErrorCode.ACCESS_DENIED,
|
|
286
|
+
unsupported_response_type: AuthErrorCode.UNSUPPORTED_GRANT_TYPE,
|
|
287
|
+
server_error: AuthErrorCode.SERVER_ERROR,
|
|
288
|
+
temporarily_unavailable: AuthErrorCode.TEMPORARILY_UNAVAILABLE,
|
|
265
289
|
};
|
|
266
290
|
return errorMap[error] || AuthErrorCode.INTERNAL_ERROR;
|
|
267
291
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apple-provider.js","sourceRoot":"","sources":["../../../../src/providers/web/apple-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAEZ,cAAc,
|
|
1
|
+
{"version":3,"file":"apple-provider.js","sourceRoot":"","sources":["../../../../src/providers/web/apple-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAEZ,cAAc,EAOd,aAAa,GAGd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,aAAa,GAId,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAqCnD,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IAGrD,YAAY,MAA0B;QACpC,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,SAAS,EAAE,qDAAqD;YAC7E,OAAO,EAAE,MAAA,QAAQ,CAAC,aAAa,0CAAE,QAAQ;YACzC,YAAY,EAAE,SAAS,EAAE,sDAAsD;YAC/E,SAAS,EAAE,SAAS;YACpB,SAAS,EAAE,QAAQ;YACnB,KAAK,EAAE,SAAS,EAAE,sDAAsD;YACxE,QAAQ,EAAE,MAAA,QAAQ,CAAC,aAAa,0CAAE,KAAK;SACxC,CAAC;IACJ,CAAC;IAEO,aAAa,CAAC,KAAa;QACjC,MAAM,QAAQ,GAAkC;YAC9C,wBAAwB,EAAE,aAAa,CAAC,cAAc;YACtD,oBAAoB,EAAE,aAAa,CAAC,oBAAoB;YACxD,aAAa,EAAE,aAAa,CAAC,aAAa;YAC1C,eAAe,EAAE,aAAa,CAAC,eAAe;YAC9C,cAAc,EAAE,aAAa,CAAC,gBAAgB;YAC9C,aAAa,EAAE,aAAa,CAAC,aAAa;YAC1C,mBAAmB,EAAE,aAAa,CAAC,kBAAkB;YACrD,aAAa,EAAE,aAAa,CAAC,aAAa;YAC1C,yBAAyB,EAAE,aAAa,CAAC,sBAAsB;YAC/D,YAAY,EAAE,aAAa,CAAC,YAAY;YACxC,uBAAuB,EAAE,aAAa,CAAC,uBAAuB;SAC/D,CAAC;QAEF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,cAAc,CAAC;IACzD,CAAC;CACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { AuthResult, AuthUser, SignInOptions } from '../../definitions';
|
|
2
|
+
import { AuthProviderInterface } from '../../core/types';
|
|
3
|
+
export interface BiometricConfig {
|
|
4
|
+
reason?: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
subtitle?: string;
|
|
7
|
+
fallbackTitle?: string;
|
|
8
|
+
storageKey?: string;
|
|
9
|
+
requireRecentAuth?: boolean;
|
|
10
|
+
recentAuthTimeout?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class BiometricProvider implements AuthProviderInterface {
|
|
13
|
+
name: string;
|
|
14
|
+
private config;
|
|
15
|
+
private biometricAuth;
|
|
16
|
+
private storageKey;
|
|
17
|
+
private cryptoKeyPromise;
|
|
18
|
+
constructor(config?: BiometricConfig);
|
|
19
|
+
private loadBiometricPlugin;
|
|
20
|
+
signIn(_options?: SignInOptions): Promise<AuthResult>;
|
|
21
|
+
signOut(): Promise<void>;
|
|
22
|
+
getCurrentUser(): Promise<AuthUser | null>;
|
|
23
|
+
refreshToken(): Promise<AuthResult>;
|
|
24
|
+
storeUserCredentials(user: AuthUser, credential?: any): Promise<void>;
|
|
25
|
+
isAvailable(): Promise<{
|
|
26
|
+
available: boolean;
|
|
27
|
+
biometryType?: string;
|
|
28
|
+
reason?: string;
|
|
29
|
+
}>;
|
|
30
|
+
hasStoredCredentials(): Promise<boolean>;
|
|
31
|
+
private getStoredCredentials;
|
|
32
|
+
private storeCredentials;
|
|
33
|
+
private clearStoredCredentials;
|
|
34
|
+
/**
|
|
35
|
+
* Persistent, non-extractable AES-GCM key kept in IndexedDB so it cannot be read back out by
|
|
36
|
+
* script — stored biometric credentials are therefore not recoverable by simply reading
|
|
37
|
+
* localStorage (unlike the previous base64 encoding).
|
|
38
|
+
*/
|
|
39
|
+
private getEncryptionKey;
|
|
40
|
+
private openKeyDb;
|
|
41
|
+
private loadKeyFromIndexedDb;
|
|
42
|
+
private saveKeyToIndexedDb;
|
|
43
|
+
/**
|
|
44
|
+
* Encrypts with AES-GCM (Web Crypto). Falls back to base64 ONLY when Web Crypto / IndexedDB
|
|
45
|
+
* are unavailable (insecure context); the `b64:`/`aes:` prefix tells decrypt() the format.
|
|
46
|
+
*/
|
|
47
|
+
private encrypt;
|
|
48
|
+
private decrypt;
|
|
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 BiometricProviderManifest: {
|
|
56
|
+
name: string;
|
|
57
|
+
displayName: string;
|
|
58
|
+
iconUrl: string;
|
|
59
|
+
description: string;
|
|
60
|
+
setupInstructions: string;
|
|
61
|
+
};
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import { AuthErrorCode, } from '../../definitions';
|
|
2
|
+
import { AuthError } from '../../utils/auth-error';
|
|
3
|
+
import { defaultLogger } from '../../utils/logger';
|
|
4
|
+
export class BiometricProvider {
|
|
5
|
+
constructor(config = {}) {
|
|
6
|
+
this.name = 'biometric';
|
|
7
|
+
this.biometricAuth = null;
|
|
8
|
+
this.cryptoKeyPromise = null;
|
|
9
|
+
this.config = Object.assign({ reason: 'Authenticate to access your account', title: 'Authentication Required', subtitle: 'Access your account securely', fallbackTitle: 'Use Passcode', requireRecentAuth: true, recentAuthTimeout: 5 * 60 * 1000 }, config);
|
|
10
|
+
this.storageKey =
|
|
11
|
+
config.storageKey || 'capacitor-auth-biometric-credentials';
|
|
12
|
+
// Try to load biometric plugin
|
|
13
|
+
this.loadBiometricPlugin();
|
|
14
|
+
}
|
|
15
|
+
async loadBiometricPlugin() {
|
|
16
|
+
try {
|
|
17
|
+
// Dynamic import to avoid errors if plugin not installed
|
|
18
|
+
const { BiometricAuth } = await import('capacitor-biometric-authentication');
|
|
19
|
+
this.biometricAuth = BiometricAuth;
|
|
20
|
+
}
|
|
21
|
+
catch (_a) {
|
|
22
|
+
defaultLogger.warn('Biometric authentication plugin not available');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async signIn(_options) {
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
if (!this.biometricAuth) {
|
|
28
|
+
throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_AVAILABLE, 'Biometric authentication plugin is not installed. Please install capacitor-biometric-authentication');
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
// Check if biometry is available
|
|
32
|
+
const checkResult = await this.biometricAuth.checkBiometry();
|
|
33
|
+
if (!checkResult.isAvailable) {
|
|
34
|
+
throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_AVAILABLE, checkResult.reason ||
|
|
35
|
+
'Biometric authentication is not available on this device');
|
|
36
|
+
}
|
|
37
|
+
// Check if we have stored credentials
|
|
38
|
+
const storedCredentials = await this.getStoredCredentials();
|
|
39
|
+
if (!storedCredentials) {
|
|
40
|
+
throw new AuthError(AuthErrorCode.NO_STORED_CREDENTIALS, 'No stored credentials found. Please sign in with another method first.');
|
|
41
|
+
}
|
|
42
|
+
// Check if recent auth is required
|
|
43
|
+
if (this.config.requireRecentAuth) {
|
|
44
|
+
const timeSinceLastAuth = Date.now() - storedCredentials.lastAuthTime;
|
|
45
|
+
if (timeSinceLastAuth > this.config.recentAuthTimeout) {
|
|
46
|
+
throw new AuthError(AuthErrorCode.REQUIRES_RECENT_LOGIN, 'Authentication expired. Please sign in with another method.');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Perform biometric authentication
|
|
50
|
+
await this.biometricAuth.authenticate({
|
|
51
|
+
reason: this.config.reason,
|
|
52
|
+
title: this.config.title,
|
|
53
|
+
subtitle: this.config.subtitle,
|
|
54
|
+
fallbackTitle: this.config.fallbackTitle,
|
|
55
|
+
});
|
|
56
|
+
// Update last auth time
|
|
57
|
+
storedCredentials.lastAuthTime = Date.now();
|
|
58
|
+
await this.storeCredentials(storedCredentials);
|
|
59
|
+
// Return stored user data
|
|
60
|
+
return {
|
|
61
|
+
user: storedCredentials.user,
|
|
62
|
+
credential: {
|
|
63
|
+
providerId: this.name,
|
|
64
|
+
signInMethod: 'biometric',
|
|
65
|
+
accessToken: storedCredentials.accessToken,
|
|
66
|
+
refreshToken: storedCredentials.refreshToken,
|
|
67
|
+
},
|
|
68
|
+
additionalUserInfo: {
|
|
69
|
+
isNewUser: false,
|
|
70
|
+
providerId: this.name,
|
|
71
|
+
profile: {
|
|
72
|
+
biometryType: checkResult.biometryType,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (error instanceof AuthError)
|
|
79
|
+
throw error;
|
|
80
|
+
// Handle biometric errors
|
|
81
|
+
if (error.code === 'userCancel' || ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('cancel'))) {
|
|
82
|
+
throw new AuthError(AuthErrorCode.USER_CANCELLED, 'Authentication cancelled by user');
|
|
83
|
+
}
|
|
84
|
+
else if (error.code === 'biometryLockout' ||
|
|
85
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('lockout'))) {
|
|
86
|
+
throw new AuthError(AuthErrorCode.BIOMETRIC_LOCKOUT, 'Too many failed attempts. Biometry is locked.');
|
|
87
|
+
}
|
|
88
|
+
else if (error.code === 'biometryNotEnrolled' ||
|
|
89
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('enrolled'))) {
|
|
90
|
+
throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_ENROLLED, 'No biometric credentials are enrolled');
|
|
91
|
+
}
|
|
92
|
+
throw new AuthError(AuthErrorCode.BIOMETRIC_AUTHENTICATION_FAILED, error.message || 'Biometric authentication failed');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async signOut() {
|
|
96
|
+
// Clear stored credentials
|
|
97
|
+
await this.clearStoredCredentials();
|
|
98
|
+
}
|
|
99
|
+
async getCurrentUser() {
|
|
100
|
+
const stored = await this.getStoredCredentials();
|
|
101
|
+
return (stored === null || stored === void 0 ? void 0 : stored.user) || null;
|
|
102
|
+
}
|
|
103
|
+
async refreshToken() {
|
|
104
|
+
// Re-authenticate with biometrics
|
|
105
|
+
return this.signIn();
|
|
106
|
+
}
|
|
107
|
+
// Store credentials for biometric access
|
|
108
|
+
async storeUserCredentials(user, credential) {
|
|
109
|
+
const credentials = {
|
|
110
|
+
user,
|
|
111
|
+
accessToken: credential === null || credential === void 0 ? void 0 : credential.accessToken,
|
|
112
|
+
refreshToken: credential === null || credential === void 0 ? void 0 : credential.refreshToken,
|
|
113
|
+
lastAuthTime: Date.now(),
|
|
114
|
+
};
|
|
115
|
+
await this.storeCredentials(credentials);
|
|
116
|
+
}
|
|
117
|
+
// Check if biometric authentication is available
|
|
118
|
+
async isAvailable() {
|
|
119
|
+
if (!this.biometricAuth) {
|
|
120
|
+
await this.loadBiometricPlugin();
|
|
121
|
+
if (!this.biometricAuth) {
|
|
122
|
+
return {
|
|
123
|
+
available: false,
|
|
124
|
+
reason: 'Biometric authentication plugin not installed',
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
const result = await this.biometricAuth.checkBiometry();
|
|
130
|
+
return {
|
|
131
|
+
available: result.isAvailable,
|
|
132
|
+
biometryType: result.biometryType,
|
|
133
|
+
reason: result.reason,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
catch (_a) {
|
|
137
|
+
return {
|
|
138
|
+
available: false,
|
|
139
|
+
reason: 'Failed to check biometry availability',
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Check if credentials are stored
|
|
144
|
+
async hasStoredCredentials() {
|
|
145
|
+
const stored = await this.getStoredCredentials();
|
|
146
|
+
if (!stored)
|
|
147
|
+
return false;
|
|
148
|
+
// Check if auth is still valid
|
|
149
|
+
if (this.config.requireRecentAuth) {
|
|
150
|
+
const timeSinceLastAuth = Date.now() - stored.lastAuthTime;
|
|
151
|
+
return timeSinceLastAuth <= this.config.recentAuthTimeout;
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
async getStoredCredentials() {
|
|
156
|
+
if (typeof localStorage === 'undefined')
|
|
157
|
+
return null;
|
|
158
|
+
try {
|
|
159
|
+
const stored = localStorage.getItem(this.storageKey);
|
|
160
|
+
if (!stored)
|
|
161
|
+
return null;
|
|
162
|
+
const decrypted = await this.decrypt(stored);
|
|
163
|
+
return JSON.parse(decrypted);
|
|
164
|
+
}
|
|
165
|
+
catch (_a) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async storeCredentials(credentials) {
|
|
170
|
+
if (typeof localStorage === 'undefined') {
|
|
171
|
+
throw new AuthError(AuthErrorCode.BIOMETRIC_NOT_AVAILABLE, 'Biometric credential storage is unavailable in this environment');
|
|
172
|
+
}
|
|
173
|
+
try {
|
|
174
|
+
const encrypted = await this.encrypt(JSON.stringify(credentials));
|
|
175
|
+
localStorage.setItem(this.storageKey, encrypted);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
throw new AuthError(AuthErrorCode.STORAGE_ERROR, 'Failed to store credentials', undefined, { cause: String(error) });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async clearStoredCredentials() {
|
|
182
|
+
if (typeof localStorage !== 'undefined') {
|
|
183
|
+
localStorage.removeItem(this.storageKey);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Persistent, non-extractable AES-GCM key kept in IndexedDB so it cannot be read back out by
|
|
188
|
+
* script — stored biometric credentials are therefore not recoverable by simply reading
|
|
189
|
+
* localStorage (unlike the previous base64 encoding).
|
|
190
|
+
*/
|
|
191
|
+
getEncryptionKey() {
|
|
192
|
+
if (!this.cryptoKeyPromise) {
|
|
193
|
+
this.cryptoKeyPromise = (async () => {
|
|
194
|
+
const existing = await this.loadKeyFromIndexedDb();
|
|
195
|
+
if (existing)
|
|
196
|
+
return existing;
|
|
197
|
+
const key = await crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']);
|
|
198
|
+
await this.saveKeyToIndexedDb(key);
|
|
199
|
+
return key;
|
|
200
|
+
})();
|
|
201
|
+
}
|
|
202
|
+
return this.cryptoKeyPromise;
|
|
203
|
+
}
|
|
204
|
+
openKeyDb() {
|
|
205
|
+
return new Promise((resolve, reject) => {
|
|
206
|
+
const req = indexedDB.open('capacitor-auth-keys', 1);
|
|
207
|
+
req.onupgradeneeded = () => req.result.createObjectStore('keys');
|
|
208
|
+
req.onsuccess = () => resolve(req.result);
|
|
209
|
+
req.onerror = () => reject(req.error);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
async loadKeyFromIndexedDb() {
|
|
213
|
+
if (typeof indexedDB === 'undefined')
|
|
214
|
+
return null;
|
|
215
|
+
try {
|
|
216
|
+
const db = await this.openKeyDb();
|
|
217
|
+
return await new Promise((resolve) => {
|
|
218
|
+
const tx = db.transaction('keys', 'readonly');
|
|
219
|
+
const req = tx.objectStore('keys').get(this.storageKey);
|
|
220
|
+
req.onsuccess = () => { var _a; return resolve((_a = req.result) !== null && _a !== void 0 ? _a : null); };
|
|
221
|
+
req.onerror = () => resolve(null);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
catch (_a) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async saveKeyToIndexedDb(key) {
|
|
229
|
+
if (typeof indexedDB === 'undefined')
|
|
230
|
+
return;
|
|
231
|
+
try {
|
|
232
|
+
const db = await this.openKeyDb();
|
|
233
|
+
await new Promise((resolve) => {
|
|
234
|
+
const tx = db.transaction('keys', 'readwrite');
|
|
235
|
+
tx.objectStore('keys').put(key, this.storageKey);
|
|
236
|
+
tx.oncomplete = () => resolve();
|
|
237
|
+
tx.onerror = () => resolve();
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
catch (_a) {
|
|
241
|
+
// Best-effort: a fresh key is generated next time if persistence fails.
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Encrypts with AES-GCM (Web Crypto). Falls back to base64 ONLY when Web Crypto / IndexedDB
|
|
246
|
+
* are unavailable (insecure context); the `b64:`/`aes:` prefix tells decrypt() the format.
|
|
247
|
+
*/
|
|
248
|
+
async encrypt(data) {
|
|
249
|
+
if (typeof crypto === 'undefined' ||
|
|
250
|
+
!crypto.subtle ||
|
|
251
|
+
typeof indexedDB === 'undefined') {
|
|
252
|
+
return `b64:${btoa(data)}`;
|
|
253
|
+
}
|
|
254
|
+
const key = await this.getEncryptionKey();
|
|
255
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
256
|
+
const ciphertext = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, new TextEncoder().encode(data));
|
|
257
|
+
const packed = new Uint8Array(iv.length + ciphertext.byteLength);
|
|
258
|
+
packed.set(iv, 0);
|
|
259
|
+
packed.set(new Uint8Array(ciphertext), iv.length);
|
|
260
|
+
let binary = '';
|
|
261
|
+
for (let i = 0; i < packed.length; i++) {
|
|
262
|
+
binary += String.fromCharCode(packed[i]);
|
|
263
|
+
}
|
|
264
|
+
return `aes:${btoa(binary)}`;
|
|
265
|
+
}
|
|
266
|
+
async decrypt(data) {
|
|
267
|
+
if (data.startsWith('aes:')) {
|
|
268
|
+
const key = await this.getEncryptionKey();
|
|
269
|
+
const binary = atob(data.slice(4));
|
|
270
|
+
const bytes = new Uint8Array(binary.length);
|
|
271
|
+
for (let i = 0; i < binary.length; i++) {
|
|
272
|
+
bytes[i] = binary.charCodeAt(i);
|
|
273
|
+
}
|
|
274
|
+
const iv = bytes.slice(0, 12);
|
|
275
|
+
const ciphertext = bytes.slice(12);
|
|
276
|
+
const plaintext = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, ciphertext);
|
|
277
|
+
return new TextDecoder().decode(plaintext);
|
|
278
|
+
}
|
|
279
|
+
// Legacy (older versions) or insecure-context fallback: base64-encoded payload.
|
|
280
|
+
const payload = data.startsWith('b64:') ? data.slice(4) : data;
|
|
281
|
+
return atob(payload);
|
|
282
|
+
}
|
|
283
|
+
async initialize() {
|
|
284
|
+
// Biometric provider is initialized in constructor
|
|
285
|
+
// Provider is initialized
|
|
286
|
+
}
|
|
287
|
+
async isSupported() {
|
|
288
|
+
// Check if biometric authentication is available
|
|
289
|
+
const result = await this.isAvailable();
|
|
290
|
+
return result.available;
|
|
291
|
+
}
|
|
292
|
+
async linkAccount(_options) {
|
|
293
|
+
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for biometric authentication');
|
|
294
|
+
}
|
|
295
|
+
async unlinkAccount(_options) {
|
|
296
|
+
// Unlinking biometric auth means clearing stored credentials
|
|
297
|
+
await this.clearStoredCredentials();
|
|
298
|
+
}
|
|
299
|
+
async revokeAccess(_token) {
|
|
300
|
+
// For biometric auth, revoking access means clearing stored credentials
|
|
301
|
+
await this.clearStoredCredentials();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
// Provider manifest for dynamic loading
|
|
305
|
+
export const BiometricProviderManifest = {
|
|
306
|
+
name: 'biometric',
|
|
307
|
+
displayName: 'Biometric Authentication',
|
|
308
|
+
iconUrl: 'https://cdn.jsdelivr.net/npm/simple-icons@v9/icons/fingerprint.svg',
|
|
309
|
+
description: 'Face ID, Touch ID, and Fingerprint authentication',
|
|
310
|
+
setupInstructions: `
|
|
311
|
+
To use Biometric authentication:
|
|
312
|
+
|
|
313
|
+
1. Install the capacitor-biometric-authentication plugin:
|
|
314
|
+
\`\`\`bash
|
|
315
|
+
npm install capacitor-biometric-authentication
|
|
316
|
+
npx cap sync
|
|
317
|
+
\`\`\`
|
|
318
|
+
|
|
319
|
+
2. Configure the provider:
|
|
320
|
+
\`\`\`javascript
|
|
321
|
+
auth.configure({
|
|
322
|
+
providers: {
|
|
323
|
+
biometric: {
|
|
324
|
+
reason: 'Authenticate to access your account',
|
|
325
|
+
title: 'Authentication Required',
|
|
326
|
+
subtitle: 'Access your account securely',
|
|
327
|
+
fallbackTitle: 'Use Passcode',
|
|
328
|
+
requireRecentAuth: true,
|
|
329
|
+
recentAuthTimeout: 5 * 60 * 1000 // 5 minutes
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
\`\`\`
|
|
334
|
+
|
|
335
|
+
3. Store user credentials after initial sign in:
|
|
336
|
+
\`\`\`javascript
|
|
337
|
+
// Sign in with another provider first
|
|
338
|
+
const result = await auth.signIn('google');
|
|
339
|
+
|
|
340
|
+
// Store credentials for biometric access
|
|
341
|
+
const biometricProvider = await auth.getProvider('biometric');
|
|
342
|
+
await biometricProvider.storeUserCredentials(result.user, result.credential);
|
|
343
|
+
\`\`\`
|
|
344
|
+
|
|
345
|
+
4. Use biometric authentication:
|
|
346
|
+
\`\`\`javascript
|
|
347
|
+
// Check availability
|
|
348
|
+
const biometric = await auth.getProvider('biometric');
|
|
349
|
+
const { available, biometryType } = await biometric.isAvailable();
|
|
350
|
+
|
|
351
|
+
if (available) {
|
|
352
|
+
// Authenticate with biometrics
|
|
353
|
+
await auth.signIn('biometric');
|
|
354
|
+
}
|
|
355
|
+
\`\`\`
|
|
356
|
+
|
|
357
|
+
Platform Requirements:
|
|
358
|
+
- iOS: Face ID or Touch ID enabled device
|
|
359
|
+
- Android: Fingerprint sensor or Face recognition
|
|
360
|
+
- Web: WebAuthn support (limited)
|
|
361
|
+
|
|
362
|
+
Note: Users must first authenticate with another method before enabling biometric authentication.
|
|
363
|
+
`,
|
|
364
|
+
};
|
|
365
|
+
//# sourceMappingURL=biometric-provider.js.map
|