capacitor-auth-manager 0.0.1 → 1.0.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 +36 -0
- package/LICENSE +1 -1
- package/Readme.md +577 -20
- package/android/build.gradle +79 -0
- package/android/gradle.properties +25 -0
- package/android/proguard-rules.pro +38 -0
- package/android/settings.gradle +2 -0
- package/android/src/main/AndroidManifest.xml +11 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthLogger.java +117 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthStorage.java +124 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/BaseAuthProvider.java +16 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/CapacitorAuthManager.java +385 -0
- package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/CapacitorAuthManagerPlugin.java +469 -0
- package/dist/esm/definitions.d.ts +521 -0
- package/dist/esm/definitions.js +103 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +6 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/providers/base-provider.d.ts +43 -0
- package/dist/esm/providers/base-provider.js +112 -0
- package/dist/esm/providers/base-provider.js.map +1 -0
- package/dist/esm/providers/oauth-provider.d.ts +30 -0
- package/dist/esm/providers/oauth-provider.js +255 -0
- package/dist/esm/providers/oauth-provider.js.map +1 -0
- package/dist/esm/providers/provider-factory.d.ts +7 -0
- package/dist/esm/providers/provider-factory.js +76 -0
- package/dist/esm/providers/provider-factory.js.map +1 -0
- package/dist/esm/providers/web/apple-provider.d.ts +33 -0
- package/dist/esm/providers/web/apple-provider.js +270 -0
- package/dist/esm/providers/web/apple-provider.js.map +1 -0
- package/dist/esm/providers/web/google-provider.d.ts +27 -0
- package/dist/esm/providers/web/google-provider.js +258 -0
- package/dist/esm/providers/web/google-provider.js.map +1 -0
- package/dist/esm/utils/auth-error.d.ts +16 -0
- package/dist/esm/utils/auth-error.js +53 -0
- package/dist/esm/utils/auth-error.js.map +1 -0
- package/dist/esm/utils/event-emitter.d.ts +9 -0
- package/dist/esm/utils/event-emitter.js +28 -0
- package/dist/esm/utils/event-emitter.js.map +1 -0
- package/dist/esm/utils/logger.d.ts +19 -0
- package/dist/esm/utils/logger.js +48 -0
- package/dist/esm/utils/logger.js.map +1 -0
- package/dist/esm/utils/storage.d.ts +16 -0
- package/dist/esm/utils/storage.js +86 -0
- package/dist/esm/utils/storage.js.map +1 -0
- package/dist/esm/web.d.ts +43 -0
- package/dist/esm/web.js +374 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +1650 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1652 -3
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/AuthLogger.swift +71 -0
- package/ios/Plugin/AuthStorage.swift +139 -0
- package/ios/Plugin/BaseAuthProvider.swift +33 -0
- package/ios/Plugin/CapacitorAuthManager.swift +406 -0
- package/ios/Plugin/Models.swift +376 -0
- package/ios/Plugin/Plugin.m +27 -0
- package/ios/Plugin/Plugin.swift +413 -0
- package/package.json +6 -2
- package/scripts/configure.js +295 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { AuthProvider, AppleAuthScope, AuthErrorCode, } from '../../definitions';
|
|
2
|
+
import { OAuthProvider } from '../oauth-provider';
|
|
3
|
+
import { AuthError } from '../../utils/auth-error';
|
|
4
|
+
export class AppleAuthProviderWeb extends OAuthProvider {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
super(config);
|
|
7
|
+
this.initPromise = null;
|
|
8
|
+
}
|
|
9
|
+
getOAuthConfig() {
|
|
10
|
+
const options = this.options;
|
|
11
|
+
return {
|
|
12
|
+
clientId: options.clientId,
|
|
13
|
+
redirectUri: options.redirectUri,
|
|
14
|
+
authorizationEndpoint: 'https://appleid.apple.com/auth/authorize',
|
|
15
|
+
tokenEndpoint: 'https://appleid.apple.com/auth/token',
|
|
16
|
+
scopes: this.mapAppleScopes(options.scopes),
|
|
17
|
+
responseType: options.responseType || 'code id_token',
|
|
18
|
+
additionalParams: {
|
|
19
|
+
response_mode: options.responseMode || 'form_post',
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async initialize() {
|
|
24
|
+
if (this.isInitialized) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (this.initPromise) {
|
|
28
|
+
return this.initPromise;
|
|
29
|
+
}
|
|
30
|
+
this.initPromise = this._initialize();
|
|
31
|
+
try {
|
|
32
|
+
await this.initPromise;
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
this.initPromise = null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async _initialize() {
|
|
39
|
+
const options = this.options;
|
|
40
|
+
try {
|
|
41
|
+
// Load Apple JS SDK
|
|
42
|
+
await this.loadAppleSDK();
|
|
43
|
+
// Initialize Apple ID auth
|
|
44
|
+
window.AppleID.auth.init({
|
|
45
|
+
clientId: options.clientId,
|
|
46
|
+
scope: this.mapAppleScopes(options.scopes).join(' '),
|
|
47
|
+
redirectURI: options.redirectUri,
|
|
48
|
+
state: options.state,
|
|
49
|
+
nonce: options.nonce,
|
|
50
|
+
usePopup: options.usePopup !== false, // Default to true
|
|
51
|
+
});
|
|
52
|
+
// Load previously authenticated user
|
|
53
|
+
await this.loadCurrentUser();
|
|
54
|
+
this.isInitialized = true;
|
|
55
|
+
this.logger.info('Apple Auth provider initialized');
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
this.logger.error('Failed to initialize Apple Auth', error);
|
|
59
|
+
throw AuthError.fromError(error, this.provider);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async signIn(options) {
|
|
63
|
+
var _a, _b, _c;
|
|
64
|
+
this.validateInitialized();
|
|
65
|
+
try {
|
|
66
|
+
const appleOptions = this.options;
|
|
67
|
+
// Generate state and nonce for security
|
|
68
|
+
const state = ((_a = options === null || options === void 0 ? void 0 : options.options) === null || _a === void 0 ? void 0 : _a.state) || this.generateSecureRandomString();
|
|
69
|
+
const nonce = ((_b = options === null || options === void 0 ? void 0 : options.options) === null || _b === void 0 ? void 0 : _b.nonce) || this.generateSecureRandomString();
|
|
70
|
+
// Store state and nonce for validation
|
|
71
|
+
await this.storage.set(`${this.provider}_oauth_state`, state);
|
|
72
|
+
await this.storage.set(`${this.provider}_oauth_nonce`, nonce);
|
|
73
|
+
// Configure sign-in options
|
|
74
|
+
const signInConfig = {
|
|
75
|
+
clientId: appleOptions.clientId,
|
|
76
|
+
scope: this.mapAppleScopes(((_c = options === null || options === void 0 ? void 0 : options.options) === null || _c === void 0 ? void 0 : _c.scopes) || appleOptions.scopes).join(' '),
|
|
77
|
+
redirectURI: appleOptions.redirectUri,
|
|
78
|
+
state,
|
|
79
|
+
nonce,
|
|
80
|
+
usePopup: appleOptions.usePopup !== false,
|
|
81
|
+
};
|
|
82
|
+
// Perform sign in
|
|
83
|
+
const response = await window.AppleID.auth.signIn(signInConfig);
|
|
84
|
+
// Validate response
|
|
85
|
+
await this.validateAppleResponse(response, state, nonce);
|
|
86
|
+
// Parse user information from response
|
|
87
|
+
const user = this.createAppleAuthUser(response);
|
|
88
|
+
const credential = this.createAppleCredential(response);
|
|
89
|
+
// Save user and credential
|
|
90
|
+
await this.setCurrentUser(user);
|
|
91
|
+
await this.saveCredential(credential);
|
|
92
|
+
return this.createAuthResult(user, credential, response.user ? true : false);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
this.logger.error('Apple sign in failed', error);
|
|
96
|
+
if (error && typeof error === 'object' && 'error' in error) {
|
|
97
|
+
throw new AuthError(this.mapAppleError(error.error), error.error, this.provider);
|
|
98
|
+
}
|
|
99
|
+
throw AuthError.fromError(error, this.provider);
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
// Clean up temporary storage
|
|
103
|
+
await this.storage.remove(`${this.provider}_oauth_state`);
|
|
104
|
+
await this.storage.remove(`${this.provider}_oauth_nonce`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async signOut(_options) {
|
|
108
|
+
this.validateInitialized();
|
|
109
|
+
try {
|
|
110
|
+
// Apple doesn't provide a sign-out method in their JS SDK
|
|
111
|
+
// Just clear local data
|
|
112
|
+
await this.clearStoredData();
|
|
113
|
+
await this.setCurrentUser(null);
|
|
114
|
+
this.logger.info('Signed out from Apple');
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
this.logger.error('Failed to sign out from Apple', error);
|
|
118
|
+
throw AuthError.fromError(error, this.provider);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async isSupported() {
|
|
122
|
+
// Check if we're in a browser environment
|
|
123
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
// Check if we're on HTTPS (required for Apple Sign In)
|
|
127
|
+
if (window.location.protocol !== 'https:' && window.location.hostname !== 'localhost') {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
async linkAccount(options) {
|
|
133
|
+
// For web, linking is the same as signing in
|
|
134
|
+
return this.signIn(options);
|
|
135
|
+
}
|
|
136
|
+
async unlinkAccount(_options) {
|
|
137
|
+
// For web, unlinking is the same as signing out
|
|
138
|
+
await this.signOut();
|
|
139
|
+
}
|
|
140
|
+
async openAuthorizationUrl(_url) {
|
|
141
|
+
// This method is not used in Apple JS SDK flow
|
|
142
|
+
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Direct OAuth flow not supported for Apple. Use signIn method instead.', this.provider);
|
|
143
|
+
}
|
|
144
|
+
async parseUserFromTokenResponse(response) {
|
|
145
|
+
// Apple provides user info directly in the authorization response
|
|
146
|
+
return response.user || {};
|
|
147
|
+
}
|
|
148
|
+
async loadAppleSDK() {
|
|
149
|
+
var _a;
|
|
150
|
+
if ((_a = window.AppleID) === null || _a === void 0 ? void 0 : _a.auth) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
return new Promise((resolve, reject) => {
|
|
154
|
+
const script = document.createElement('script');
|
|
155
|
+
script.src = 'https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js';
|
|
156
|
+
script.async = true;
|
|
157
|
+
script.defer = true;
|
|
158
|
+
script.onload = () => {
|
|
159
|
+
var _a;
|
|
160
|
+
if ((_a = window.AppleID) === null || _a === void 0 ? void 0 : _a.auth) {
|
|
161
|
+
resolve();
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
reject(new Error('Apple ID SDK failed to load'));
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
script.onerror = () => {
|
|
168
|
+
reject(new Error('Failed to load Apple ID SDK'));
|
|
169
|
+
};
|
|
170
|
+
document.head.appendChild(script);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
mapAppleScopes(scopes) {
|
|
174
|
+
if (!scopes || scopes.length === 0) {
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
return scopes.map(scope => {
|
|
178
|
+
switch (scope) {
|
|
179
|
+
case AppleAuthScope.EMAIL:
|
|
180
|
+
return 'email';
|
|
181
|
+
case AppleAuthScope.NAME:
|
|
182
|
+
return 'name';
|
|
183
|
+
default:
|
|
184
|
+
return scope;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
async validateAppleResponse(response, expectedState, _expectedNonce) {
|
|
189
|
+
if (response.error) {
|
|
190
|
+
throw new AuthError(this.mapAppleError(response.error), response.error, this.provider);
|
|
191
|
+
}
|
|
192
|
+
if (response.state !== expectedState) {
|
|
193
|
+
throw new AuthError(AuthErrorCode.INVALID_STATE, 'OAuth state mismatch', this.provider);
|
|
194
|
+
}
|
|
195
|
+
// ID token validation with nonce would be done here
|
|
196
|
+
// For production, you should validate the ID token on your backend
|
|
197
|
+
}
|
|
198
|
+
createAppleAuthUser(response) {
|
|
199
|
+
var _a, _b, _c, _d;
|
|
200
|
+
const user = response.user || {};
|
|
201
|
+
const idToken = (_a = response.authorization) === null || _a === void 0 ? void 0 : _a.id_token;
|
|
202
|
+
// Parse ID token claims (in production, do this on backend)
|
|
203
|
+
let claims = {};
|
|
204
|
+
if (idToken) {
|
|
205
|
+
try {
|
|
206
|
+
const payload = idToken.split('.')[1];
|
|
207
|
+
claims = JSON.parse(atob(payload));
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
this.logger.error('Failed to parse ID token', error);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
uid: claims.sub || ((_b = response.authorization) === null || _b === void 0 ? void 0 : _b.code) || this.generateUniqueId(),
|
|
215
|
+
email: user.email || claims.email || null,
|
|
216
|
+
emailVerified: claims.email_verified || false,
|
|
217
|
+
displayName: user.name ? `${user.name.firstName || ''} ${user.name.lastName || ''}`.trim() : null,
|
|
218
|
+
photoURL: null, // Apple doesn't provide profile photos
|
|
219
|
+
phoneNumber: null,
|
|
220
|
+
isAnonymous: false,
|
|
221
|
+
tenantId: null,
|
|
222
|
+
providerData: [{
|
|
223
|
+
providerId: AuthProvider.APPLE,
|
|
224
|
+
uid: claims.sub || ((_c = response.authorization) === null || _c === void 0 ? void 0 : _c.code),
|
|
225
|
+
displayName: user.name ? `${user.name.firstName || ''} ${user.name.lastName || ''}`.trim() : null,
|
|
226
|
+
email: user.email || claims.email || null,
|
|
227
|
+
phoneNumber: null,
|
|
228
|
+
photoURL: null,
|
|
229
|
+
}],
|
|
230
|
+
metadata: {
|
|
231
|
+
creationTime: new Date().toISOString(),
|
|
232
|
+
lastSignInTime: new Date().toISOString(),
|
|
233
|
+
},
|
|
234
|
+
refreshToken: (_d = response.authorization) === null || _d === void 0 ? void 0 : _d.refresh_token,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
createAppleCredential(response) {
|
|
238
|
+
var _a, _b, _c, _d, _e;
|
|
239
|
+
return {
|
|
240
|
+
providerId: AuthProvider.APPLE,
|
|
241
|
+
signInMethod: 'oauth',
|
|
242
|
+
accessToken: (_a = response.authorization) === null || _a === void 0 ? void 0 : _a.access_token,
|
|
243
|
+
idToken: (_b = response.authorization) === null || _b === void 0 ? void 0 : _b.id_token,
|
|
244
|
+
refreshToken: (_c = response.authorization) === null || _c === void 0 ? void 0 : _c.refresh_token,
|
|
245
|
+
expiresAt: ((_d = response.authorization) === null || _d === void 0 ? void 0 : _d.expires_in)
|
|
246
|
+
? this.calculateTokenExpiry(response.authorization.expires_in)
|
|
247
|
+
: undefined,
|
|
248
|
+
tokenType: 'Bearer',
|
|
249
|
+
scope: (_e = response.authorization) === null || _e === void 0 ? void 0 : _e.scope,
|
|
250
|
+
rawNonce: response.nonce,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
mapAppleError(error) {
|
|
254
|
+
const errorMap = {
|
|
255
|
+
'user_cancelled_authorize': AuthErrorCode.USER_CANCELLED,
|
|
256
|
+
'popup_closed_by_user': AuthErrorCode.POPUP_CLOSED_BY_USER,
|
|
257
|
+
'popup_blocked': AuthErrorCode.POPUP_BLOCKED,
|
|
258
|
+
'invalid_request': AuthErrorCode.INVALID_REQUEST,
|
|
259
|
+
'invalid_client': AuthErrorCode.CLIENT_NOT_FOUND,
|
|
260
|
+
'invalid_scope': AuthErrorCode.INVALID_SCOPE,
|
|
261
|
+
'unauthorized_client': AuthErrorCode.APP_NOT_AUTHORIZED,
|
|
262
|
+
'access_denied': AuthErrorCode.ACCESS_DENIED,
|
|
263
|
+
'unsupported_response_type': AuthErrorCode.UNSUPPORTED_GRANT_TYPE,
|
|
264
|
+
'server_error': AuthErrorCode.SERVER_ERROR,
|
|
265
|
+
'temporarily_unavailable': AuthErrorCode.TEMPORARILY_UNAVAILABLE,
|
|
266
|
+
};
|
|
267
|
+
return errorMap[error] || AuthErrorCode.INTERNAL_ERROR;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=apple-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apple-provider.js","sourceRoot":"","sources":["../../../../src/providers/web/apple-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAEZ,cAAc,EAMd,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAe,MAAM,mBAAmB,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAanD,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IAGrD,YAAY,MAA0B;QACpC,KAAK,CAAC,MAAM,CAAC,CAAC;QAHR,gBAAW,GAAyB,IAAI,CAAC;IAIjD,CAAC;IAES,cAAc;QACtB,MAAM,OAAO,GAAG,IAAI,CAAC,OAA2B,CAAC;QAEjD,OAAO;YACL,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,qBAAqB,EAAE,0CAA0C;YACjE,aAAa,EAAE,sCAAsC;YACrD,MAAM,EAAE,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC;YAC3C,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,eAAe;YACrD,gBAAgB,EAAE;gBAChB,aAAa,EAAE,OAAO,CAAC,YAAY,IAAI,WAAW;aACnD;SACF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,OAAO;QACT,CAAC;QAED,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;QAED,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAEtC,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,WAAW,CAAC;QACzB,CAAC;gBAA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AAC,oBAAoB,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC;gBAC9D,CAAC,CAAC,SAAS;YACb,SAAS,EAAE,QAAQ;YACnB,KAAK,EAAE,MAAA,QAAQ,CAAC,aAAa,0CAAE,KAAK;YACpC,QAAQ,EAAE,QAAQ,CAAC,KAAK;SACzB,CAAC;IACJ,CAAC;IAEO,aAAa,CAAC,KAAa;QACjC,MAAM,QAAQ,GAAkC;YAC9C,0BAA0B,EAAE,aAAa,CAAC,cAAc;YACxD,sBAAsB,EAAE,aAAa,CAAC,oBAAoB;YAC1D,eAAe,EAAE,aAAa,CAAC,aAAa;YAC5C,iBAAiB,EAAE,aAAa,CAAC,eAAe;YAChD,gBAAgB,EAAE,aAAa,CAAC,gBAAgB;YAChD,eAAe,EAAE,aAAa,CAAC,aAAa;YAC5C,qBAAqB,EAAE,aAAa,CAAC,kBAAkB;YACvD,eAAe,EAAE,aAAa,CAAC,aAAa;YAC5C,2BAA2B,EAAE,aAAa,CAAC,sBAAsB;YACjE,cAAc,EAAE,aAAa,CAAC,YAAY;YAC1C,yBAAyB,EAAE,aAAa,CAAC,uBAAuB;SACjE,CAAC;QAEF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,cAAc,CAAC;IACzD,CAAC;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SignInOptions, SignOutOptions, LinkAccountOptions, UnlinkAccountOptions, AuthResult } from '../../definitions';
|
|
2
|
+
import { OAuthProvider, OAuthConfig } from '../oauth-provider';
|
|
3
|
+
import { BaseProviderConfig } from '../base-provider';
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
google?: any;
|
|
7
|
+
gapi?: any;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare class GoogleAuthProviderWeb extends OAuthProvider {
|
|
11
|
+
private initPromise;
|
|
12
|
+
constructor(config: BaseProviderConfig);
|
|
13
|
+
protected getOAuthConfig(): OAuthConfig;
|
|
14
|
+
initialize(): Promise<void>;
|
|
15
|
+
private _initialize;
|
|
16
|
+
signIn(options?: SignInOptions): Promise<AuthResult>;
|
|
17
|
+
signOut(options?: SignOutOptions): Promise<void>;
|
|
18
|
+
isSupported(): Promise<boolean>;
|
|
19
|
+
linkAccount(options: LinkAccountOptions): Promise<AuthResult>;
|
|
20
|
+
unlinkAccount(_options: UnlinkAccountOptions): Promise<void>;
|
|
21
|
+
protected openAuthorizationUrl(_url: string): Promise<any>;
|
|
22
|
+
protected parseUserFromTokenResponse(response: any): Promise<any>;
|
|
23
|
+
private getUserInfo;
|
|
24
|
+
private loadGoogleIdentityServices;
|
|
25
|
+
private mapGoogleError;
|
|
26
|
+
protected createAuthUser(userInfo: any, tokenResponse: any): any;
|
|
27
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { AuthProvider, AuthErrorCode, } from '../../definitions';
|
|
2
|
+
import { OAuthProvider } from '../oauth-provider';
|
|
3
|
+
import { AuthError } from '../../utils/auth-error';
|
|
4
|
+
export class GoogleAuthProviderWeb extends OAuthProvider {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
super(config);
|
|
7
|
+
this.initPromise = null;
|
|
8
|
+
}
|
|
9
|
+
getOAuthConfig() {
|
|
10
|
+
const options = this.options;
|
|
11
|
+
return {
|
|
12
|
+
clientId: options.clientId,
|
|
13
|
+
clientSecret: options.clientSecret,
|
|
14
|
+
redirectUri: window.location.origin,
|
|
15
|
+
authorizationEndpoint: 'https://accounts.google.com/o/oauth2/v2/auth',
|
|
16
|
+
tokenEndpoint: 'https://oauth2.googleapis.com/token',
|
|
17
|
+
revokeEndpoint: 'https://oauth2.googleapis.com/revoke',
|
|
18
|
+
userInfoEndpoint: 'https://www.googleapis.com/oauth2/v3/userinfo',
|
|
19
|
+
scopes: options.scopes || ['openid', 'email', 'profile'],
|
|
20
|
+
responseType: 'code',
|
|
21
|
+
additionalParams: {
|
|
22
|
+
access_type: options.offlineAccess ? 'offline' : 'online',
|
|
23
|
+
include_granted_scopes: options.includeGrantedScopes ? 'true' : 'false',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
async initialize() {
|
|
28
|
+
if (this.isInitialized) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (this.initPromise) {
|
|
32
|
+
return this.initPromise;
|
|
33
|
+
}
|
|
34
|
+
this.initPromise = this._initialize();
|
|
35
|
+
try {
|
|
36
|
+
await this.initPromise;
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
this.initPromise = null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async _initialize() {
|
|
43
|
+
const options = this.options;
|
|
44
|
+
try {
|
|
45
|
+
// Load Google Identity Services library
|
|
46
|
+
await this.loadGoogleIdentityServices();
|
|
47
|
+
// Initialize Google client
|
|
48
|
+
window.google.accounts.oauth2.initCodeClient({
|
|
49
|
+
client_id: options.clientId,
|
|
50
|
+
scope: (options.scopes || ['openid', 'email', 'profile']).join(' '),
|
|
51
|
+
ux_mode: 'popup',
|
|
52
|
+
callback: (_response) => {
|
|
53
|
+
// This callback will be overridden per sign-in
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
// Load previously authenticated user
|
|
57
|
+
await this.loadCurrentUser();
|
|
58
|
+
this.isInitialized = true;
|
|
59
|
+
this.logger.info('Google Auth provider initialized');
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
this.logger.error('Failed to initialize Google Auth', error);
|
|
63
|
+
throw AuthError.fromError(error, this.provider);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async signIn(options) {
|
|
67
|
+
this.validateInitialized();
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
var _a, _b, _c;
|
|
70
|
+
try {
|
|
71
|
+
const googleOptions = this.options;
|
|
72
|
+
// Configure sign-in options
|
|
73
|
+
const signInConfig = {
|
|
74
|
+
client_id: googleOptions.clientId,
|
|
75
|
+
scope: (((_a = options === null || options === void 0 ? void 0 : options.options) === null || _a === void 0 ? void 0 : _a.scopes) || googleOptions.scopes || ['openid', 'email', 'profile']).join(' '),
|
|
76
|
+
callback: async (response) => {
|
|
77
|
+
if (response.error) {
|
|
78
|
+
reject(new AuthError(this.mapGoogleError(response.error), response.error_description || response.error, this.provider));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
// Exchange authorization code for tokens
|
|
83
|
+
const tokenResponse = await this.exchangeCodeForTokens(response.code, this.getOAuthConfig());
|
|
84
|
+
// Get user info
|
|
85
|
+
const userInfo = await this.getUserInfo(tokenResponse.access_token);
|
|
86
|
+
// Create AuthUser and AuthCredential
|
|
87
|
+
const user = this.createAuthUser(userInfo, tokenResponse);
|
|
88
|
+
const credential = this.createOAuthCredential(tokenResponse);
|
|
89
|
+
// Save user and credential
|
|
90
|
+
await this.setCurrentUser(user);
|
|
91
|
+
await this.saveCredential(credential);
|
|
92
|
+
resolve(this.createAuthResult(user, credential, false));
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
reject(AuthError.fromError(error, this.provider));
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
// Add login hint if provided
|
|
100
|
+
if (((_b = options === null || options === void 0 ? void 0 : options.options) === null || _b === void 0 ? void 0 : _b.loginHint) || googleOptions.loginHint) {
|
|
101
|
+
signInConfig.login_hint = ((_c = options === null || options === void 0 ? void 0 : options.options) === null || _c === void 0 ? void 0 : _c.loginHint) || googleOptions.loginHint;
|
|
102
|
+
}
|
|
103
|
+
// Add hosted domain if provided
|
|
104
|
+
if (googleOptions.hostedDomain) {
|
|
105
|
+
signInConfig.hd = googleOptions.hostedDomain;
|
|
106
|
+
}
|
|
107
|
+
// Create new client with callback
|
|
108
|
+
const client = window.google.accounts.oauth2.initCodeClient(signInConfig);
|
|
109
|
+
// Request authorization code
|
|
110
|
+
client.requestCode();
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
reject(AuthError.fromError(error, this.provider));
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async signOut(options) {
|
|
118
|
+
var _a, _b;
|
|
119
|
+
this.validateInitialized();
|
|
120
|
+
try {
|
|
121
|
+
// Revoke token if requested
|
|
122
|
+
if (options === null || options === void 0 ? void 0 : options.revokeToken) {
|
|
123
|
+
const credential = await this.loadCredential();
|
|
124
|
+
if (credential === null || credential === void 0 ? void 0 : credential.accessToken) {
|
|
125
|
+
await this.revokeAccess(credential.accessToken);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// Clear stored data
|
|
129
|
+
await this.clearStoredData();
|
|
130
|
+
await this.setCurrentUser(null);
|
|
131
|
+
// Disconnect Google account if available
|
|
132
|
+
if ((_b = (_a = window.google) === null || _a === void 0 ? void 0 : _a.accounts) === null || _b === void 0 ? void 0 : _b.id) {
|
|
133
|
+
window.google.accounts.id.disableAutoSelect();
|
|
134
|
+
}
|
|
135
|
+
this.logger.info('Signed out from Google');
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
this.logger.error('Failed to sign out from Google', error);
|
|
139
|
+
throw AuthError.fromError(error, this.provider);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async isSupported() {
|
|
143
|
+
// Check if we're in a browser environment
|
|
144
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
// Check if we can load Google Identity Services
|
|
148
|
+
try {
|
|
149
|
+
await this.loadGoogleIdentityServices();
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
catch (_a) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async linkAccount(options) {
|
|
157
|
+
// For web, linking is the same as signing in
|
|
158
|
+
return this.signIn(options);
|
|
159
|
+
}
|
|
160
|
+
async unlinkAccount(_options) {
|
|
161
|
+
// For web, unlinking is the same as signing out
|
|
162
|
+
await this.signOut();
|
|
163
|
+
}
|
|
164
|
+
async openAuthorizationUrl(_url) {
|
|
165
|
+
// This method is not used in Google Identity Services flow
|
|
166
|
+
throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Direct OAuth flow not supported for Google. Use signIn method instead.', this.provider);
|
|
167
|
+
}
|
|
168
|
+
async parseUserFromTokenResponse(response) {
|
|
169
|
+
// Get user info from the userinfo endpoint
|
|
170
|
+
if (response.access_token) {
|
|
171
|
+
return this.getUserInfo(response.access_token);
|
|
172
|
+
}
|
|
173
|
+
throw new AuthError(AuthErrorCode.INVALID_CREDENTIALS, 'No access token in response', this.provider);
|
|
174
|
+
}
|
|
175
|
+
async getUserInfo(accessToken) {
|
|
176
|
+
try {
|
|
177
|
+
const response = await fetch('https://www.googleapis.com/oauth2/v3/userinfo', {
|
|
178
|
+
headers: {
|
|
179
|
+
Authorization: `Bearer ${accessToken}`,
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
if (!response.ok) {
|
|
183
|
+
throw new AuthError(AuthErrorCode.NETWORK_ERROR, 'Failed to fetch user info', this.provider);
|
|
184
|
+
}
|
|
185
|
+
return await response.json();
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
if (error instanceof AuthError) {
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
throw new AuthError(AuthErrorCode.NETWORK_ERROR, 'Failed to fetch user info', this.provider, error);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
async loadGoogleIdentityServices() {
|
|
195
|
+
var _a, _b;
|
|
196
|
+
if ((_b = (_a = window.google) === null || _a === void 0 ? void 0 : _a.accounts) === null || _b === void 0 ? void 0 : _b.oauth2) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
return new Promise((resolve, reject) => {
|
|
200
|
+
const script = document.createElement('script');
|
|
201
|
+
script.src = 'https://accounts.google.com/gsi/client';
|
|
202
|
+
script.async = true;
|
|
203
|
+
script.defer = true;
|
|
204
|
+
script.onload = () => {
|
|
205
|
+
var _a, _b;
|
|
206
|
+
if ((_b = (_a = window.google) === null || _a === void 0 ? void 0 : _a.accounts) === null || _b === void 0 ? void 0 : _b.oauth2) {
|
|
207
|
+
resolve();
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
reject(new Error('Google Identity Services failed to load'));
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
script.onerror = () => {
|
|
214
|
+
reject(new Error('Failed to load Google Identity Services'));
|
|
215
|
+
};
|
|
216
|
+
document.head.appendChild(script);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
mapGoogleError(error) {
|
|
220
|
+
const errorMap = {
|
|
221
|
+
'access_denied': AuthErrorCode.ACCESS_DENIED,
|
|
222
|
+
'unauthorized_client': AuthErrorCode.APP_NOT_AUTHORIZED,
|
|
223
|
+
'invalid_request': AuthErrorCode.INVALID_REQUEST,
|
|
224
|
+
'invalid_scope': AuthErrorCode.INVALID_SCOPE,
|
|
225
|
+
'server_error': AuthErrorCode.SERVER_ERROR,
|
|
226
|
+
'temporarily_unavailable': AuthErrorCode.TEMPORARILY_UNAVAILABLE,
|
|
227
|
+
'popup_closed_by_user': AuthErrorCode.POPUP_CLOSED_BY_USER,
|
|
228
|
+
'popup_blocked': AuthErrorCode.POPUP_BLOCKED,
|
|
229
|
+
};
|
|
230
|
+
return errorMap[error] || AuthErrorCode.INTERNAL_ERROR;
|
|
231
|
+
}
|
|
232
|
+
createAuthUser(userInfo, tokenResponse) {
|
|
233
|
+
return {
|
|
234
|
+
uid: userInfo.sub,
|
|
235
|
+
email: userInfo.email,
|
|
236
|
+
emailVerified: userInfo.email_verified || false,
|
|
237
|
+
displayName: userInfo.name,
|
|
238
|
+
photoURL: userInfo.picture,
|
|
239
|
+
phoneNumber: null,
|
|
240
|
+
isAnonymous: false,
|
|
241
|
+
tenantId: null,
|
|
242
|
+
providerData: [{
|
|
243
|
+
providerId: AuthProvider.GOOGLE,
|
|
244
|
+
uid: userInfo.sub,
|
|
245
|
+
displayName: userInfo.name,
|
|
246
|
+
email: userInfo.email,
|
|
247
|
+
phoneNumber: null,
|
|
248
|
+
photoURL: userInfo.picture,
|
|
249
|
+
}],
|
|
250
|
+
metadata: {
|
|
251
|
+
creationTime: new Date().toISOString(),
|
|
252
|
+
lastSignInTime: new Date().toISOString(),
|
|
253
|
+
},
|
|
254
|
+
refreshToken: tokenResponse.refresh_token,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=google-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-provider.js","sourceRoot":"","sources":["../../../../src/providers/web/google-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAOZ,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAe,MAAM,mBAAmB,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AASnD,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IAGtD,YAAY,MAA0B;QACpC,KAAK,CAAC,MAAM,CAAC,CAAC;QAHR,gBAAW,GAAyB,IAAI,CAAC;IAIjD,CAAC;IAES,cAAc;QACtB,MAAM,OAAO,GAAG,IAAI,CAAC,OAA4B,CAAC;QAElD,OAAO;YACL,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;YACnC,qBAAqB,EAAE,8CAA8C;YACrE,aAAa,EAAE,qCAAqC;YACpD,cAAc,EAAE,sCAAsC;YACtD,gBAAgB,EAAE,+CAA+C;YACjE,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC;YACxD,YAAY,EAAE,MAAM;YACpB,g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CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AuthError as IAuthError, AuthProvider } from '../definitions';
|
|
2
|
+
export declare class AuthError extends Error implements IAuthError {
|
|
3
|
+
code: string;
|
|
4
|
+
details?: any;
|
|
5
|
+
provider?: AuthProvider;
|
|
6
|
+
constructor(code: string, message: string, provider?: AuthProvider, details?: any);
|
|
7
|
+
static fromError(error: any, provider?: AuthProvider): AuthError;
|
|
8
|
+
toJSON(): {
|
|
9
|
+
name: string;
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
provider: AuthProvider | undefined;
|
|
13
|
+
details: any;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function isAuthError(error: any): error is AuthError;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AuthErrorCode } from '../definitions';
|
|
2
|
+
export class AuthError extends Error {
|
|
3
|
+
constructor(code, message, provider, details) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = 'AuthError';
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.provider = provider;
|
|
8
|
+
this.details = details;
|
|
9
|
+
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
10
|
+
if (Error.captureStackTrace) {
|
|
11
|
+
Error.captureStackTrace(this, AuthError);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
static fromError(error, provider) {
|
|
15
|
+
if (error instanceof AuthError) {
|
|
16
|
+
return error;
|
|
17
|
+
}
|
|
18
|
+
let code = AuthErrorCode.INTERNAL_ERROR;
|
|
19
|
+
let message = 'An unknown error occurred';
|
|
20
|
+
let details = error;
|
|
21
|
+
if (error instanceof Error) {
|
|
22
|
+
message = error.message;
|
|
23
|
+
// Try to map common error patterns to specific error codes
|
|
24
|
+
if (error.message.includes('network')) {
|
|
25
|
+
code = AuthErrorCode.NETWORK_ERROR;
|
|
26
|
+
}
|
|
27
|
+
else if (error.message.includes('cancelled') || error.message.includes('canceled')) {
|
|
28
|
+
code = AuthErrorCode.USER_CANCELLED;
|
|
29
|
+
}
|
|
30
|
+
else if (error.message.includes('timeout')) {
|
|
31
|
+
code = AuthErrorCode.NETWORK_ERROR;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Handle provider-specific error codes
|
|
35
|
+
if (error === null || error === void 0 ? void 0 : error.code) {
|
|
36
|
+
code = error.code;
|
|
37
|
+
}
|
|
38
|
+
return new AuthError(code, message, provider, details);
|
|
39
|
+
}
|
|
40
|
+
toJSON() {
|
|
41
|
+
return {
|
|
42
|
+
name: this.name,
|
|
43
|
+
code: this.code,
|
|
44
|
+
message: this.message,
|
|
45
|
+
provider: this.provider,
|
|
46
|
+
details: this.details,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export function isAuthError(error) {
|
|
51
|
+
return error instanceof AuthError || ((error === null || error === void 0 ? void 0 : error.name) === 'AuthError' && (error === null || error === void 0 ? void 0 : error.code));
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=auth-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-error.js","sourceRoot":"","sources":["../../../src/utils/auth-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,aAAa,EAAgB,MAAM,gBAAgB,CAAC;AAEtF,MAAM,OAAO,SAAU,SAAQ,KAAK;IAKlC,YAAY,IAAY,EAAE,OAAe,EAAE,QAAuB,EAAE,OAAa;QAC/E,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,qFAAqF;QACrF,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,SAAS,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