@capgo/capacitor-social-login 0.0.50 → 0.0.52
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 +1 -1
- package/android/src/main/java/ee/forgr/capacitor/social/login/FacebookProvider.java +4 -6
- package/dist/docs.json +1 -1
- package/dist/esm/definitions.d.ts +4 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +4 -0
- package/dist/esm/web.js +90 -12
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +90 -12
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +90 -12
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/SocialLoginPlugin/AppleProvider.swift +104 -60
- package/ios/Sources/SocialLoginPlugin/FacebookProvider.swift +35 -22
- package/ios/Sources/SocialLoginPlugin/SocialLoginPlugin.swift +24 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -347,7 +347,7 @@ Refresh the access token
|
|
|
347
347
|
|
|
348
348
|
| Prop | Type |
|
|
349
349
|
| -------------- | ---------------------------------------------------------------------------------------- |
|
|
350
|
-
| **`facebook`** | <code>{ appId: string; }</code>
|
|
350
|
+
| **`facebook`** | <code>{ appId: string; clientToken: string; }</code> |
|
|
351
351
|
| **`google`** | <code>{ iOSClientId?: string; iOSServerClientId?: string; webClientId?: string; }</code> |
|
|
352
352
|
| **`apple`** | <code>{ clientId?: string; redirectUrl?: string; }</code> |
|
|
353
353
|
|
|
@@ -30,7 +30,6 @@ public class FacebookProvider implements SocialProvider {
|
|
|
30
30
|
|
|
31
31
|
private Activity activity;
|
|
32
32
|
private CallbackManager callbackManager;
|
|
33
|
-
private PluginCall savedCall;
|
|
34
33
|
|
|
35
34
|
public FacebookProvider(Activity activity) {
|
|
36
35
|
this.activity = activity;
|
|
@@ -76,7 +75,6 @@ public class FacebookProvider implements SocialProvider {
|
|
|
76
75
|
|
|
77
76
|
@Override
|
|
78
77
|
public void login(PluginCall call, JSONObject config) {
|
|
79
|
-
this.savedCall = call;
|
|
80
78
|
try {
|
|
81
79
|
Collection<String> permissions = JsonHelper.jsonArrayToList(
|
|
82
80
|
config.getJSONArray("permissions")
|
|
@@ -94,19 +92,19 @@ public class FacebookProvider implements SocialProvider {
|
|
|
94
92
|
result.put("accessToken", createAccessTokenObject(accessToken));
|
|
95
93
|
result.put("authenticationToken", loginResult.getAuthenticationToken() != null ? loginResult.getAuthenticationToken().getToken() : null);
|
|
96
94
|
// TODO: Fetch profile information and add it to the result
|
|
97
|
-
|
|
95
|
+
call.resolve(result);
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
@Override
|
|
101
99
|
public void onCancel() {
|
|
102
100
|
Log.d(LOG_TAG, "LoginManager.onCancel");
|
|
103
|
-
|
|
101
|
+
call.reject("Login cancelled");
|
|
104
102
|
}
|
|
105
103
|
|
|
106
104
|
@Override
|
|
107
105
|
public void onError(FacebookException exception) {
|
|
108
106
|
Log.e(LOG_TAG, "LoginManager.onError", exception);
|
|
109
|
-
|
|
107
|
+
call.reject(exception.getMessage());
|
|
110
108
|
}
|
|
111
109
|
});
|
|
112
110
|
|
|
@@ -122,7 +120,7 @@ public class FacebookProvider implements SocialProvider {
|
|
|
122
120
|
loginManager.logIn((ActivityResultRegistryOwner) activity, callbackManager, permissions);
|
|
123
121
|
}
|
|
124
122
|
} catch (JSONException e) {
|
|
125
|
-
|
|
123
|
+
call.reject("Invalid login options format");
|
|
126
124
|
}
|
|
127
125
|
}
|
|
128
126
|
|
package/dist/docs.json
CHANGED
|
@@ -4,6 +4,10 @@ export interface InitializeOptions {
|
|
|
4
4
|
* Facebook App ID, provided by Facebook for web, in mobile it's set in the native files
|
|
5
5
|
*/
|
|
6
6
|
appId: string;
|
|
7
|
+
/**
|
|
8
|
+
* Facebook Client Token, provided by Facebook for web, in mobile it's set in the native files
|
|
9
|
+
*/
|
|
10
|
+
clientToken: string;
|
|
7
11
|
};
|
|
8
12
|
google?: {
|
|
9
13
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface InitializeOptions {\n facebook?: {\n /**\n * Facebook App ID, provided by Facebook for web, in mobile it's set in the native files\n */\n appId: string;\n };\n\n google?: {\n /**\n * The app's client ID, found and created in the Google Developers Console.\n * For iOS.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n iOSClientId?: string;\n /**\n * The app's server client ID, found and created in the Google Developers Console.\n * For iOS.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n iOSServerClientId?: string;\n /**\n * The app's web client ID, found and created in the Google Developers Console.\n * For Android (and web in the future).\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n webClientId?: string;\n };\n apple?: {\n /**\n * Apple Client ID, provided by Apple for web and Android\n */\n clientId?: string;\n /**\n * Apple Redirect URL, should be your backend url that is configured in your apple app, only for android\n */\n redirectUrl?: string;\n };\n}\n\nexport interface FacebookLoginOptions {\n /**\n * Permissions\n * @description select permissions to login with\n */\n permissions: string[];\n /**\n * Is Limited Login\n * @description use limited login for Facebook IOS\n * @default false\n */\n limitedLogin?: boolean;\n /**\n * Nonce\n * @description A custom nonce to use for the login request\n */\n nonce?: string;\n}\n\nexport interface GoogleLoginOptions {\n /**\n * Specifies the scopes required for accessing Google APIs\n * The default is defined in the configuration.\n * @example [\"profile\", \"email\"]\n * @see [Google OAuth2 Scopes](https://developers.google.com/identity/protocols/oauth2/scopes)\n */\n scopes?: string[];\n /**\n * Nonce\n * @description nonce\n */\n nonce?: string;\n /**\n * Set if your application needs to refresh access tokens when the user is not present at the browser.\n * In response use `serverAuthCode` key\n *\n * @default false\n * @since 3.1.0\n * */\n grantOfflineAccess?: boolean;\n}\n\nexport interface GoogleLoginResponse {\n accessToken: AccessToken | null;\n idToken: string | null;\n profile: {\n email: string | null;\n familyName: string | null;\n givenName: string | null;\n id: string | null;\n name: string | null;\n imageUrl: string | null;\n };\n}\n\nexport interface AppleProviderOptions {\n /**\n * Scopes\n * @description select scopes to login with\n */\n scopes?: string[];\n /**\n * Nonce\n * @description nonce\n */\n nonce?: string;\n /**\n * State\n * @description state\n */\n state?: string;\n}\n\nexport interface AppleProviderResponse {\n user: string | null;\n email: string | null;\n givenName: string | null;\n familyName: string | null;\n identityToken: string | null;\n authorizationCode: string | null;\n}\n\nexport interface LoginOptions {\n /**\n * Provider\n * @description select provider to login with\n */\n provider: \"facebook\" | \"google\" | \"apple\" | \"twitter\";\n /**\n * Options\n * @description payload to login with\n */\n options: FacebookLoginOptions | GoogleLoginOptions | AppleProviderOptions;\n}\n\nexport interface LoginResult {\n /**\n * Provider\n * @description select provider to login with\n */\n provider: \"facebook\" | \"google\" | \"apple\" | \"twitter\";\n /**\n * Payload\n * @description payload to login with\n */\n result: FacebookLoginResponse | GoogleLoginResponse | AppleProviderResponse;\n}\n\nexport interface AccessToken {\n applicationId?: string;\n declinedPermissions?: string[];\n expires?: string;\n isExpired?: boolean;\n lastRefresh?: string;\n permissions?: string[];\n token: string;\n userId?: string;\n}\n\nexport interface FacebookLoginResponse {\n accessToken: AccessToken | null;\n profile: {\n userID: string;\n email: string | null;\n friendIDs: string[];\n birthday: string | null;\n ageRange: { min?: number; max?: number } | null;\n gender: string | null;\n location: { id: string; name: string } | null;\n hometown: { id: string; name: string } | null;\n profileURL: string | null;\n name: string | null;\n imageURL: string | null;\n };\n authenticationToken: string | null;\n}\n\nexport interface AuthorizationCode {\n /**\n * Jwt\n * @description A JSON web token\n */\n jwt: string;\n}\n\nexport interface AuthorizationCodeOptions {\n /**\n * Provider\n * @description Provider for the authorization code\n */\n provider: \"apple\" | \"google\" | \"facebook\";\n}\n\nexport interface isLoggedInOptions {\n /**\n * Provider\n * @description Provider for the isLoggedIn\n */\n provider: \"apple\" | \"google\" | \"facebook\";\n}\n\nexport interface SocialLoginPlugin {\n /**\n * Initialize the plugin\n * @description initialize the plugin with the required options\n */\n initialize(options: InitializeOptions): Promise<void>;\n /**\n * Login with the selected provider\n * @description login with the selected provider\n */\n login(options: LoginOptions): Promise<LoginResult>;\n /**\n * Logout\n * @description logout the user\n */\n logout(options: { provider: \"apple\" | \"google\" | \"facebook\" }): Promise<void>;\n /**\n * IsLoggedIn\n * @description logout the user\n */\n isLoggedIn(options: isLoggedInOptions): Promise<{ isLoggedIn: boolean }>;\n\n /**\n * Get the current access token\n * @description get the current access token\n */\n getAuthorizationCode(\n options: AuthorizationCodeOptions,\n ): Promise<AuthorizationCode>;\n /**\n * Refresh the access token\n * @description refresh the access token\n */\n refresh(options: LoginOptions): Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface InitializeOptions {\n facebook?: {\n /**\n * Facebook App ID, provided by Facebook for web, in mobile it's set in the native files\n */\n appId: string;\n /**\n * Facebook Client Token, provided by Facebook for web, in mobile it's set in the native files\n */\n clientToken: string;\n };\n\n google?: {\n /**\n * The app's client ID, found and created in the Google Developers Console.\n * For iOS.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n iOSClientId?: string;\n /**\n * The app's server client ID, found and created in the Google Developers Console.\n * For iOS.\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n iOSServerClientId?: string;\n /**\n * The app's web client ID, found and created in the Google Developers Console.\n * For Android (and web in the future).\n * @example xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\n * @since 3.1.0\n */\n webClientId?: string;\n };\n apple?: {\n /**\n * Apple Client ID, provided by Apple for web and Android\n */\n clientId?: string;\n /**\n * Apple Redirect URL, should be your backend url that is configured in your apple app, only for android\n */\n redirectUrl?: string;\n };\n}\n\nexport interface FacebookLoginOptions {\n /**\n * Permissions\n * @description select permissions to login with\n */\n permissions: string[];\n /**\n * Is Limited Login\n * @description use limited login for Facebook IOS\n * @default false\n */\n limitedLogin?: boolean;\n /**\n * Nonce\n * @description A custom nonce to use for the login request\n */\n nonce?: string;\n}\n\nexport interface GoogleLoginOptions {\n /**\n * Specifies the scopes required for accessing Google APIs\n * The default is defined in the configuration.\n * @example [\"profile\", \"email\"]\n * @see [Google OAuth2 Scopes](https://developers.google.com/identity/protocols/oauth2/scopes)\n */\n scopes?: string[];\n /**\n * Nonce\n * @description nonce\n */\n nonce?: string;\n /**\n * Set if your application needs to refresh access tokens when the user is not present at the browser.\n * In response use `serverAuthCode` key\n *\n * @default false\n * @since 3.1.0\n * */\n grantOfflineAccess?: boolean;\n}\n\nexport interface GoogleLoginResponse {\n accessToken: AccessToken | null;\n idToken: string | null;\n profile: {\n email: string | null;\n familyName: string | null;\n givenName: string | null;\n id: string | null;\n name: string | null;\n imageUrl: string | null;\n };\n}\n\nexport interface AppleProviderOptions {\n /**\n * Scopes\n * @description select scopes to login with\n */\n scopes?: string[];\n /**\n * Nonce\n * @description nonce\n */\n nonce?: string;\n /**\n * State\n * @description state\n */\n state?: string;\n}\n\nexport interface AppleProviderResponse {\n user: string | null;\n email: string | null;\n givenName: string | null;\n familyName: string | null;\n identityToken: string | null;\n authorizationCode: string | null;\n}\n\nexport interface LoginOptions {\n /**\n * Provider\n * @description select provider to login with\n */\n provider: \"facebook\" | \"google\" | \"apple\" | \"twitter\";\n /**\n * Options\n * @description payload to login with\n */\n options: FacebookLoginOptions | GoogleLoginOptions | AppleProviderOptions;\n}\n\nexport interface LoginResult {\n /**\n * Provider\n * @description select provider to login with\n */\n provider: \"facebook\" | \"google\" | \"apple\" | \"twitter\";\n /**\n * Payload\n * @description payload to login with\n */\n result: FacebookLoginResponse | GoogleLoginResponse | AppleProviderResponse;\n}\n\nexport interface AccessToken {\n applicationId?: string;\n declinedPermissions?: string[];\n expires?: string;\n isExpired?: boolean;\n lastRefresh?: string;\n permissions?: string[];\n token: string;\n userId?: string;\n}\n\nexport interface FacebookLoginResponse {\n accessToken: AccessToken | null;\n profile: {\n userID: string;\n email: string | null;\n friendIDs: string[];\n birthday: string | null;\n ageRange: { min?: number; max?: number } | null;\n gender: string | null;\n location: { id: string; name: string } | null;\n hometown: { id: string; name: string } | null;\n profileURL: string | null;\n name: string | null;\n imageURL: string | null;\n };\n authenticationToken: string | null;\n}\n\nexport interface AuthorizationCode {\n /**\n * Jwt\n * @description A JSON web token\n */\n jwt: string;\n}\n\nexport interface AuthorizationCodeOptions {\n /**\n * Provider\n * @description Provider for the authorization code\n */\n provider: \"apple\" | \"google\" | \"facebook\";\n}\n\nexport interface isLoggedInOptions {\n /**\n * Provider\n * @description Provider for the isLoggedIn\n */\n provider: \"apple\" | \"google\" | \"facebook\";\n}\n\nexport interface SocialLoginPlugin {\n /**\n * Initialize the plugin\n * @description initialize the plugin with the required options\n */\n initialize(options: InitializeOptions): Promise<void>;\n /**\n * Login with the selected provider\n * @description login with the selected provider\n */\n login(options: LoginOptions): Promise<LoginResult>;\n /**\n * Logout\n * @description logout the user\n */\n logout(options: { provider: \"apple\" | \"google\" | \"facebook\" }): Promise<void>;\n /**\n * IsLoggedIn\n * @description logout the user\n */\n isLoggedIn(options: isLoggedInOptions): Promise<{ isLoggedIn: boolean }>;\n\n /**\n * Get the current access token\n * @description get the current access token\n */\n getAuthorizationCode(\n options: AuthorizationCodeOptions,\n ): Promise<AuthorizationCode>;\n /**\n * Refresh the access token\n * @description refresh the access token\n */\n refresh(options: LoginOptions): Promise<void>;\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export declare class SocialLoginWeb extends WebPlugin implements SocialLoginPlug
|
|
|
6
6
|
private googleScriptLoaded;
|
|
7
7
|
private appleScriptLoaded;
|
|
8
8
|
private appleScriptUrl;
|
|
9
|
+
private facebookAppId;
|
|
10
|
+
private facebookScriptLoaded;
|
|
9
11
|
initialize(options: InitializeOptions): Promise<void>;
|
|
10
12
|
login(options: LoginOptions): Promise<LoginResult>;
|
|
11
13
|
logout(options: {
|
|
@@ -22,4 +24,6 @@ export declare class SocialLoginWeb extends WebPlugin implements SocialLoginPlug
|
|
|
22
24
|
private loginWithApple;
|
|
23
25
|
private loadAppleScript;
|
|
24
26
|
private getGoogleUser;
|
|
27
|
+
private loadFacebookScript;
|
|
28
|
+
private loginWithFacebook;
|
|
25
29
|
}
|
package/dist/esm/web.js
CHANGED
|
@@ -7,9 +7,11 @@ export class SocialLoginWeb extends WebPlugin {
|
|
|
7
7
|
this.googleScriptLoaded = false;
|
|
8
8
|
this.appleScriptLoaded = false;
|
|
9
9
|
this.appleScriptUrl = "https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js";
|
|
10
|
+
this.facebookAppId = null;
|
|
11
|
+
this.facebookScriptLoaded = false;
|
|
10
12
|
}
|
|
11
13
|
async initialize(options) {
|
|
12
|
-
var _a, _b;
|
|
14
|
+
var _a, _b, _c;
|
|
13
15
|
if ((_a = options.google) === null || _a === void 0 ? void 0 : _a.webClientId) {
|
|
14
16
|
this.googleClientId = options.google.webClientId;
|
|
15
17
|
await this.loadGoogleScript();
|
|
@@ -18,6 +20,16 @@ export class SocialLoginWeb extends WebPlugin {
|
|
|
18
20
|
this.appleClientId = options.apple.clientId;
|
|
19
21
|
await this.loadAppleScript();
|
|
20
22
|
}
|
|
23
|
+
if ((_c = options.facebook) === null || _c === void 0 ? void 0 : _c.appId) {
|
|
24
|
+
this.facebookAppId = options.facebook.appId;
|
|
25
|
+
await this.loadFacebookScript();
|
|
26
|
+
FB.init({
|
|
27
|
+
appId: this.facebookAppId,
|
|
28
|
+
version: 'v17.0',
|
|
29
|
+
xfbml: true,
|
|
30
|
+
cookie: true,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
21
33
|
// Implement initialization for other providers if needed
|
|
22
34
|
}
|
|
23
35
|
async login(options) {
|
|
@@ -27,6 +39,9 @@ export class SocialLoginWeb extends WebPlugin {
|
|
|
27
39
|
else if (options.provider === "apple") {
|
|
28
40
|
return this.loginWithApple(options.options);
|
|
29
41
|
}
|
|
42
|
+
else if (options.provider === "facebook") {
|
|
43
|
+
return this.loginWithFacebook(options.options);
|
|
44
|
+
}
|
|
30
45
|
// Implement login for other providers
|
|
31
46
|
throw new Error(`Login for ${options.provider} is not implemented on web`);
|
|
32
47
|
}
|
|
@@ -42,9 +57,9 @@ export class SocialLoginWeb extends WebPlugin {
|
|
|
42
57
|
console.log("Apple logout: Session should be managed on the client side");
|
|
43
58
|
break;
|
|
44
59
|
case "facebook":
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
FB.logout(() => resolve());
|
|
62
|
+
});
|
|
48
63
|
default:
|
|
49
64
|
throw new Error(`Logout for ${options.provider} is not implemented`);
|
|
50
65
|
}
|
|
@@ -60,9 +75,11 @@ export class SocialLoginWeb extends WebPlugin {
|
|
|
60
75
|
console.log("Apple login status should be managed on the client side");
|
|
61
76
|
return { isLoggedIn: false };
|
|
62
77
|
case "facebook":
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
78
|
+
return new Promise((resolve) => {
|
|
79
|
+
FB.getLoginStatus((response) => {
|
|
80
|
+
resolve({ isLoggedIn: response.status === 'connected' });
|
|
81
|
+
});
|
|
82
|
+
});
|
|
66
83
|
default:
|
|
67
84
|
throw new Error(`isLoggedIn for ${options.provider} is not implemented`);
|
|
68
85
|
}
|
|
@@ -81,9 +98,17 @@ export class SocialLoginWeb extends WebPlugin {
|
|
|
81
98
|
console.log("Apple authorization code should be stored during login");
|
|
82
99
|
throw new Error("Apple authorization code not available");
|
|
83
100
|
case "facebook":
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
FB.getLoginStatus((response) => {
|
|
103
|
+
var _a;
|
|
104
|
+
if (response.status === 'connected') {
|
|
105
|
+
resolve({ jwt: ((_a = response.authResponse) === null || _a === void 0 ? void 0 : _a.accessToken) || "" });
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
reject(new Error("No Facebook authorization code available"));
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
87
112
|
default:
|
|
88
113
|
throw new Error(`getAuthorizationCode for ${options.provider} is not implemented`);
|
|
89
114
|
}
|
|
@@ -99,8 +124,7 @@ export class SocialLoginWeb extends WebPlugin {
|
|
|
99
124
|
console.log("Apple refresh not available on web");
|
|
100
125
|
break;
|
|
101
126
|
case "facebook":
|
|
102
|
-
|
|
103
|
-
console.log("Facebook refresh not implemented");
|
|
127
|
+
await this.loginWithFacebook(options.options);
|
|
104
128
|
break;
|
|
105
129
|
default:
|
|
106
130
|
throw new Error(`Refresh for ${options.provider} is not implemented`);
|
|
@@ -239,5 +263,59 @@ export class SocialLoginWeb extends WebPlugin {
|
|
|
239
263
|
});
|
|
240
264
|
});
|
|
241
265
|
}
|
|
266
|
+
async loadFacebookScript() {
|
|
267
|
+
if (this.facebookScriptLoaded)
|
|
268
|
+
return;
|
|
269
|
+
return new Promise((resolve, reject) => {
|
|
270
|
+
const script = document.createElement('script');
|
|
271
|
+
script.src = 'https://connect.facebook.net/en_US/sdk.js';
|
|
272
|
+
script.async = true;
|
|
273
|
+
script.defer = true;
|
|
274
|
+
script.onload = () => {
|
|
275
|
+
this.facebookScriptLoaded = true;
|
|
276
|
+
resolve();
|
|
277
|
+
};
|
|
278
|
+
script.onerror = reject;
|
|
279
|
+
document.body.appendChild(script);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
async loginWithFacebook(options) {
|
|
283
|
+
if (!this.facebookAppId) {
|
|
284
|
+
throw new Error("Facebook App ID not set. Call initialize() first.");
|
|
285
|
+
}
|
|
286
|
+
return new Promise((resolve, reject) => {
|
|
287
|
+
FB.login((response) => {
|
|
288
|
+
if (response.status === 'connected') {
|
|
289
|
+
FB.api('/me', { fields: 'id,name,email,picture' }, (userInfo) => {
|
|
290
|
+
var _a, _b;
|
|
291
|
+
const result = {
|
|
292
|
+
accessToken: {
|
|
293
|
+
token: response.authResponse.accessToken,
|
|
294
|
+
userId: response.authResponse.userID,
|
|
295
|
+
},
|
|
296
|
+
profile: {
|
|
297
|
+
userID: userInfo.id,
|
|
298
|
+
name: userInfo.name,
|
|
299
|
+
email: userInfo.email || null,
|
|
300
|
+
imageURL: ((_b = (_a = userInfo.picture) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.url) || null,
|
|
301
|
+
friendIDs: [],
|
|
302
|
+
birthday: null,
|
|
303
|
+
ageRange: null,
|
|
304
|
+
gender: null,
|
|
305
|
+
location: null,
|
|
306
|
+
hometown: null,
|
|
307
|
+
profileURL: null,
|
|
308
|
+
},
|
|
309
|
+
authenticationToken: null,
|
|
310
|
+
};
|
|
311
|
+
resolve({ provider: "facebook", result });
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
reject(new Error("Facebook login failed"));
|
|
316
|
+
}
|
|
317
|
+
}, { scope: options.permissions.join(',') });
|
|
318
|
+
});
|
|
319
|
+
}
|
|
242
320
|
}
|
|
243
321
|
//# sourceMappingURL=web.js.map
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AA6B5C,MAAM,OAAO,cAAe,SAAQ,SAAS;IAA7C;;QACU,mBAAc,GAAkB,IAAI,CAAC;QACrC,kBAAa,GAAkB,IAAI,CAAC;QACpC,uBAAkB,GAAG,KAAK,CAAC;QAC3B,sBAAiB,GAAG,KAAK,CAAC;QAC1B,mBAAc,GACpB,sFAAsF,CAAC;IAoQ3F,CAAC;IAlQC,KAAK,CAAC,UAAU,CAAC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AAO,CAAC,IAAI,CAAC,CAAC;gBAChB,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { WebPlugin } from \"@capacitor/core\";\n\nimport type {\n SocialLoginPlugin,\n InitializeOptions,\n LoginOptions,\n LoginResult,\n AuthorizationCode,\n GoogleLoginResponse,\n AppleProviderResponse,\n isLoggedInOptions,\n AuthorizationCodeOptions,\n} from \"./definitions\";\n\n// Add this declaration at the top of the file\ndeclare const google: {\n accounts: {\n id: {\n initialize(config: {\n client_id: string;\n callback: (response: any) => void;\n }): void;\n prompt(callback: (notification: any) => void): void;\n };\n };\n};\n\ndeclare const AppleID: any;\n\nexport class SocialLoginWeb extends WebPlugin implements SocialLoginPlugin {\n private googleClientId: string | null = null;\n private appleClientId: string | null = null;\n private googleScriptLoaded = false;\n private appleScriptLoaded = false;\n private appleScriptUrl =\n \"https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js\";\n\n async initialize(options: InitializeOptions): Promise<void> {\n if (options.google?.webClientId) {\n this.googleClientId = options.google.webClientId;\n await this.loadGoogleScript();\n }\n if (options.apple?.clientId) {\n this.appleClientId = options.apple.clientId;\n await this.loadAppleScript();\n }\n // Implement initialization for other providers if needed\n }\n\n async login(options: LoginOptions): Promise<LoginResult> {\n if (options.provider === \"google\") {\n return this.loginWithGoogle(options.options);\n } else if (options.provider === \"apple\") {\n return this.loginWithApple(options.options);\n }\n // Implement login for other providers\n throw new Error(`Login for ${options.provider} is not implemented on web`);\n }\n\n async logout(options: {\n provider: \"apple\" | \"google\" | \"facebook\";\n }): Promise<void> {\n switch (options.provider) {\n case \"google\":\n // Google doesn't have a specific logout method for web\n // We can revoke the token if we have it stored\n console.log(\n \"Google logout: Token should be revoked on the client side if stored\",\n );\n break;\n case \"apple\":\n // Apple doesn't provide a logout method for web\n console.log(\n \"Apple logout: Session should be managed on the client side\",\n );\n break;\n case \"facebook\":\n // Implement Facebook logout when Facebook login is added\n console.log(\"Facebook logout not implemented\");\n break;\n default:\n throw new Error(`Logout for ${options.provider} is not implemented`);\n }\n }\n\n async isLoggedIn(\n options: isLoggedInOptions,\n ): Promise<{ isLoggedIn: boolean }> {\n switch (options.provider) {\n case \"google\":\n // For Google, we can check if there's a valid token\n const googleUser = await this.getGoogleUser();\n return { isLoggedIn: !!googleUser };\n case \"apple\":\n // Apple doesn't provide a method to check login status on web\n console.log(\"Apple login status should be managed on the client side\");\n return { isLoggedIn: false };\n case \"facebook\":\n // Implement Facebook isLoggedIn when Facebook login is added\n console.log(\"Facebook isLoggedIn not implemented\");\n return { isLoggedIn: false };\n default:\n throw new Error(\n `isLoggedIn for ${options.provider} is not implemented`,\n );\n }\n }\n\n async getAuthorizationCode(\n options: AuthorizationCodeOptions,\n ): Promise<AuthorizationCode> {\n switch (options.provider) {\n case \"google\":\n // For Google, we can use the id_token as the authorization code\n const googleUser = await this.getGoogleUser();\n if (googleUser && googleUser.credential) {\n return { jwt: googleUser.credential };\n }\n throw new Error(\"No Google authorization code available\");\n case \"apple\":\n // Apple authorization code should be obtained during login\n console.log(\"Apple authorization code should be stored during login\");\n throw new Error(\"Apple authorization code not available\");\n case \"facebook\":\n // Implement Facebook getAuthorizationCode when Facebook login is added\n console.log(\"Facebook getAuthorizationCode not implemented\");\n throw new Error(\"Facebook authorization code not available\");\n default:\n throw new Error(\n `getAuthorizationCode for ${options.provider} is not implemented`,\n );\n }\n }\n\n async refresh(options: LoginOptions): Promise<void> {\n switch (options.provider) {\n case \"google\":\n // For Google, we can prompt for re-authentication\n await this.loginWithGoogle(options.options);\n break;\n case \"apple\":\n // Apple doesn't provide a refresh method for web\n console.log(\"Apple refresh not available on web\");\n break;\n case \"facebook\":\n // Implement Facebook refresh when Facebook login is added\n console.log(\"Facebook refresh not implemented\");\n break;\n default:\n throw new Error(`Refresh for ${options.provider} is not implemented`);\n }\n }\n\n private async loginWithGoogle(options: any): Promise<LoginResult> {\n console.log(\"isLoggedIn\", options);\n if (!this.googleClientId) {\n throw new Error(\"Google Client ID not set. Call initialize() first.\");\n }\n\n return new Promise((resolve, reject) => {\n google.accounts.id.initialize({\n client_id: this.googleClientId!,\n callback: (response) => {\n console.log(\"google.accounts.id.initialize callback\", response);\n if (response.error) {\n reject(response.error);\n } else {\n const payload = this.parseJwt(response.credential);\n const result: GoogleLoginResponse = {\n accessToken: null,\n idToken: response.credential,\n profile: {\n email: payload.email || null,\n familyName: payload.family_name || null,\n givenName: payload.given_name || null,\n id: payload.sub || null,\n name: payload.name || null,\n imageUrl: payload.picture || null,\n },\n };\n resolve({ provider: \"google\", result });\n }\n },\n });\n\n google.accounts.id.prompt((notification) => {\n if (notification.isNotDisplayed() || notification.isSkippedMoment()) {\n console.log(\"OneTap is not displayed or skipped\");\n }\n console.log(\"OneTap is displayed\");\n });\n });\n }\n\n private parseJwt(token: string) {\n const base64Url = token.split(\".\")[1];\n const base64 = base64Url.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const jsonPayload = decodeURIComponent(\n atob(base64)\n .split(\"\")\n .map((c) => {\n return \"%\" + (\"00\" + c.charCodeAt(0).toString(16)).slice(-2);\n })\n .join(\"\"),\n );\n return JSON.parse(jsonPayload);\n }\n\n private async loadGoogleScript(): Promise<void> {\n if (this.googleScriptLoaded) return;\n\n return new Promise((resolve, reject) => {\n const script = document.createElement(\"script\");\n script.src = \"https://accounts.google.com/gsi/client\";\n script.async = true;\n script.onload = () => {\n this.googleScriptLoaded = true;\n resolve();\n };\n script.onerror = reject;\n document.body.appendChild(script);\n });\n }\n\n private async loginWithApple(options: any): Promise<LoginResult> {\n if (!this.appleClientId) {\n throw new Error(\"Apple Client ID not set. Call initialize() first.\");\n }\n\n if (!this.appleScriptLoaded) {\n throw new Error(\"Apple Sign-In script not loaded.\");\n }\n\n return new Promise((resolve, reject) => {\n AppleID.auth.init({\n clientId: this.appleClientId!,\n scope: options.scopes?.join(\" \") || \"name email\",\n redirectURI: options.redirectUrl || window.location.href,\n state: options.state,\n nonce: options.nonce,\n usePopup: true,\n });\n\n AppleID.auth\n .signIn()\n .then((res: any) => {\n const result: AppleProviderResponse = {\n user: res.user?.name?.firstName\n ? `${res.user.name.firstName} ${res.user.name.lastName}`\n : null,\n email: res.user?.email || null,\n givenName: res.user?.name?.firstName || null,\n familyName: res.user?.name?.lastName || null,\n identityToken: res.authorization.id_token || null,\n authorizationCode: res.authorization.code || null,\n };\n resolve({ provider: \"apple\", result });\n })\n .catch((error: any) => {\n reject(error);\n });\n });\n }\n\n private async loadAppleScript(): Promise<void> {\n if (this.appleScriptLoaded) return;\n\n return new Promise((resolve, reject) => {\n const script = document.createElement(\"script\");\n script.src = this.appleScriptUrl;\n script.async = true;\n script.onload = () => {\n this.appleScriptLoaded = true;\n resolve();\n };\n script.onerror = reject;\n document.body.appendChild(script);\n });\n }\n\n private async getGoogleUser(): Promise<any> {\n return new Promise((resolve) => {\n google.accounts.id.initialize({\n client_id: this.googleClientId!,\n callback: (response) => {\n resolve(response);\n },\n });\n google.accounts.id.prompt((notification) => {\n if (notification.isNotDisplayed() || notification.isSkippedMoment()) {\n resolve(null);\n }\n });\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAgD5C,MAAM,OAAO,cAAe,SAAQ,SAAS;IAA7C;;QACU,mBAAc,GAAkB,IAAI,CAAC;QACrC,kBAAa,GAAkB,IAAI,CAAC;QACpC,uBAAkB,GAAG,KAAK,CAAC;QAC3B,sBAAiB,GAAG,KAAK,CAAC;QAC1B,mBAAc,GACpB,sFAAsF,CAAC;QACjF,kBAAa,GAAkB,IAAI,CAAC;QACpC,yBAAoB,GAAG,KAAK,CAAC;IA8UvC,CAAC;IA5UC,KAAK,CAAC,UAAU,CAAC,OAA0B;;QACzC,IAAI,MAAA,OAAO,CAAC,MAAM,0CAAE,WAAW,EAAE,CAA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G,KAAI,IAAI;gCAC7C,SAAS,EAAE,EAAE;gCACb,QAAQ,EAAE,IAAI;gCACd,QAAQ,EAAE,IAAI;gCACd,MAAM,EAAE,IAAI;gCACZ,QAAQ,EAAE,IAAI;gCACd,QAAQ,EAAE,IAAI;gCACd,UAAU,EAAE,IAAI;6BACjB;4BACD,mBAAmB,EAAE,IAAI;yBAC1B,CAAC;wBACF,OAAO,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;oBAC5C,CAAC,CAAC,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC,CAAC;gBAC7C,CAAC;YACH,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { WebPlugin } from \"@capacitor/core\";\n\nimport type {\n SocialLoginPlugin,\n InitializeOptions,\n LoginOptions,\n LoginResult,\n AuthorizationCode,\n GoogleLoginResponse,\n AppleProviderResponse,\n isLoggedInOptions,\n AuthorizationCodeOptions,\n FacebookLoginOptions,\n FacebookLoginResponse,\n} from \"./definitions\";\n\n// Add this declaration at the top of the file\ndeclare const google: {\n accounts: {\n id: {\n initialize(config: {\n client_id: string;\n callback: (response: any) => void;\n }): void;\n prompt(callback: (notification: any) => void): void;\n };\n };\n};\n\ndeclare const AppleID: any;\n\ndeclare const FB: {\n init(options: any): void;\n login(\n callback: (response: { status: string; authResponse: { accessToken: string; userID: string } }) => void,\n options?: { scope: string }\n ): void;\n logout(callback: () => void): void;\n api(\n path: string,\n params: { fields: string },\n callback: (response: any) => void\n ): void;\n getLoginStatus(\n callback: (response: { status: string; authResponse?: { accessToken: string } }) => void\n ): void;\n};\n\nexport class SocialLoginWeb extends WebPlugin implements SocialLoginPlugin {\n private googleClientId: string | null = null;\n private appleClientId: string | null = null;\n private googleScriptLoaded = false;\n private appleScriptLoaded = false;\n private appleScriptUrl =\n \"https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js\";\n private facebookAppId: string | null = null;\n private facebookScriptLoaded = false;\n\n async initialize(options: InitializeOptions): Promise<void> {\n if (options.google?.webClientId) {\n this.googleClientId = options.google.webClientId;\n await this.loadGoogleScript();\n }\n if (options.apple?.clientId) {\n this.appleClientId = options.apple.clientId;\n await this.loadAppleScript();\n }\n if (options.facebook?.appId) {\n this.facebookAppId = options.facebook.appId;\n await this.loadFacebookScript();\n FB.init({\n appId: this.facebookAppId,\n version: 'v17.0',\n xfbml: true,\n cookie: true,\n });\n }\n // Implement initialization for other providers if needed\n }\n\n async login(options: LoginOptions): Promise<LoginResult> {\n if (options.provider === \"google\") {\n return this.loginWithGoogle(options.options);\n } else if (options.provider === \"apple\") {\n return this.loginWithApple(options.options);\n } else if (options.provider === \"facebook\") {\n return this.loginWithFacebook(options.options as FacebookLoginOptions);\n }\n // Implement login for other providers\n throw new Error(`Login for ${options.provider} is not implemented on web`);\n }\n\n async logout(options: {\n provider: \"apple\" | \"google\" | \"facebook\";\n }): Promise<void> {\n switch (options.provider) {\n case \"google\":\n // Google doesn't have a specific logout method for web\n // We can revoke the token if we have it stored\n console.log(\n \"Google logout: Token should be revoked on the client side if stored\",\n );\n break;\n case \"apple\":\n // Apple doesn't provide a logout method for web\n console.log(\n \"Apple logout: Session should be managed on the client side\",\n );\n break;\n case \"facebook\":\n return new Promise<void>((resolve) => {\n FB.logout(() => resolve());\n });\n default:\n throw new Error(`Logout for ${options.provider} is not implemented`);\n }\n }\n\n async isLoggedIn(\n options: isLoggedInOptions,\n ): Promise<{ isLoggedIn: boolean }> {\n switch (options.provider) {\n case \"google\":\n // For Google, we can check if there's a valid token\n const googleUser = await this.getGoogleUser();\n return { isLoggedIn: !!googleUser };\n case \"apple\":\n // Apple doesn't provide a method to check login status on web\n console.log(\"Apple login status should be managed on the client side\");\n return { isLoggedIn: false };\n case \"facebook\":\n return new Promise((resolve) => {\n FB.getLoginStatus((response) => {\n resolve({ isLoggedIn: response.status === 'connected' });\n });\n });\n default:\n throw new Error(\n `isLoggedIn for ${options.provider} is not implemented`,\n );\n }\n }\n\n async getAuthorizationCode(\n options: AuthorizationCodeOptions,\n ): Promise<AuthorizationCode> {\n switch (options.provider) {\n case \"google\":\n // For Google, we can use the id_token as the authorization code\n const googleUser = await this.getGoogleUser();\n if (googleUser && googleUser.credential) {\n return { jwt: googleUser.credential };\n }\n throw new Error(\"No Google authorization code available\");\n case \"apple\":\n // Apple authorization code should be obtained during login\n console.log(\"Apple authorization code should be stored during login\");\n throw new Error(\"Apple authorization code not available\");\n case \"facebook\":\n return new Promise((resolve, reject) => {\n FB.getLoginStatus((response) => {\n if (response.status === 'connected') {\n resolve({ jwt: response.authResponse?.accessToken || \"\" });\n } else {\n reject(new Error(\"No Facebook authorization code available\"));\n }\n });\n });\n default:\n throw new Error(\n `getAuthorizationCode for ${options.provider} is not implemented`,\n );\n }\n }\n\n async refresh(options: LoginOptions): Promise<void> {\n switch (options.provider) {\n case \"google\":\n // For Google, we can prompt for re-authentication\n await this.loginWithGoogle(options.options);\n break;\n case \"apple\":\n // Apple doesn't provide a refresh method for web\n console.log(\"Apple refresh not available on web\");\n break;\n case \"facebook\":\n await this.loginWithFacebook(options.options as FacebookLoginOptions);\n break;\n default:\n throw new Error(`Refresh for ${options.provider} is not implemented`);\n }\n }\n\n private async loginWithGoogle(options: any): Promise<LoginResult> {\n console.log(\"isLoggedIn\", options);\n if (!this.googleClientId) {\n throw new Error(\"Google Client ID not set. Call initialize() first.\");\n }\n\n return new Promise((resolve, reject) => {\n google.accounts.id.initialize({\n client_id: this.googleClientId!,\n callback: (response) => {\n console.log(\"google.accounts.id.initialize callback\", response);\n if (response.error) {\n reject(response.error);\n } else {\n const payload = this.parseJwt(response.credential);\n const result: GoogleLoginResponse = {\n accessToken: null,\n idToken: response.credential,\n profile: {\n email: payload.email || null,\n familyName: payload.family_name || null,\n givenName: payload.given_name || null,\n id: payload.sub || null,\n name: payload.name || null,\n imageUrl: payload.picture || null,\n },\n };\n resolve({ provider: \"google\", result });\n }\n },\n });\n\n google.accounts.id.prompt((notification) => {\n if (notification.isNotDisplayed() || notification.isSkippedMoment()) {\n console.log(\"OneTap is not displayed or skipped\");\n }\n console.log(\"OneTap is displayed\");\n });\n });\n }\n\n private parseJwt(token: string) {\n const base64Url = token.split(\".\")[1];\n const base64 = base64Url.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const jsonPayload = decodeURIComponent(\n atob(base64)\n .split(\"\")\n .map((c) => {\n return \"%\" + (\"00\" + c.charCodeAt(0).toString(16)).slice(-2);\n })\n .join(\"\"),\n );\n return JSON.parse(jsonPayload);\n }\n\n private async loadGoogleScript(): Promise<void> {\n if (this.googleScriptLoaded) return;\n\n return new Promise((resolve, reject) => {\n const script = document.createElement(\"script\");\n script.src = \"https://accounts.google.com/gsi/client\";\n script.async = true;\n script.onload = () => {\n this.googleScriptLoaded = true;\n resolve();\n };\n script.onerror = reject;\n document.body.appendChild(script);\n });\n }\n\n private async loginWithApple(options: any): Promise<LoginResult> {\n if (!this.appleClientId) {\n throw new Error(\"Apple Client ID not set. Call initialize() first.\");\n }\n\n if (!this.appleScriptLoaded) {\n throw new Error(\"Apple Sign-In script not loaded.\");\n }\n\n return new Promise((resolve, reject) => {\n AppleID.auth.init({\n clientId: this.appleClientId!,\n scope: options.scopes?.join(\" \") || \"name email\",\n redirectURI: options.redirectUrl || window.location.href,\n state: options.state,\n nonce: options.nonce,\n usePopup: true,\n });\n\n AppleID.auth\n .signIn()\n .then((res: any) => {\n const result: AppleProviderResponse = {\n user: res.user?.name?.firstName\n ? `${res.user.name.firstName} ${res.user.name.lastName}`\n : null,\n email: res.user?.email || null,\n givenName: res.user?.name?.firstName || null,\n familyName: res.user?.name?.lastName || null,\n identityToken: res.authorization.id_token || null,\n authorizationCode: res.authorization.code || null,\n };\n resolve({ provider: \"apple\", result });\n })\n .catch((error: any) => {\n reject(error);\n });\n });\n }\n\n private async loadAppleScript(): Promise<void> {\n if (this.appleScriptLoaded) return;\n\n return new Promise((resolve, reject) => {\n const script = document.createElement(\"script\");\n script.src = this.appleScriptUrl;\n script.async = true;\n script.onload = () => {\n this.appleScriptLoaded = true;\n resolve();\n };\n script.onerror = reject;\n document.body.appendChild(script);\n });\n }\n\n private async getGoogleUser(): Promise<any> {\n return new Promise((resolve) => {\n google.accounts.id.initialize({\n client_id: this.googleClientId!,\n callback: (response) => {\n resolve(response);\n },\n });\n google.accounts.id.prompt((notification) => {\n if (notification.isNotDisplayed() || notification.isSkippedMoment()) {\n resolve(null);\n }\n });\n });\n }\n\n private async loadFacebookScript(): Promise<void> {\n if (this.facebookScriptLoaded) return;\n\n return new Promise((resolve, reject) => {\n const script = document.createElement('script');\n script.src = 'https://connect.facebook.net/en_US/sdk.js';\n script.async = true;\n script.defer = true;\n script.onload = () => {\n this.facebookScriptLoaded = true;\n resolve();\n };\n script.onerror = reject;\n document.body.appendChild(script);\n });\n }\n\n private async loginWithFacebook(options: FacebookLoginOptions): Promise<LoginResult> {\n if (!this.facebookAppId) {\n throw new Error(\"Facebook App ID not set. Call initialize() first.\");\n }\n\n return new Promise((resolve, reject) => {\n FB.login((response) => {\n if (response.status === 'connected') {\n FB.api('/me', { fields: 'id,name,email,picture' }, (userInfo: any) => {\n const result: FacebookLoginResponse = {\n accessToken: {\n token: response.authResponse.accessToken,\n userId: response.authResponse.userID,\n },\n profile: {\n userID: userInfo.id,\n name: userInfo.name,\n email: userInfo.email || null,\n imageURL: userInfo.picture?.data?.url || null,\n friendIDs: [],\n birthday: null,\n ageRange: null,\n gender: null,\n location: null,\n hometown: null,\n profileURL: null,\n },\n authenticationToken: null,\n };\n resolve({ provider: \"facebook\", result });\n });\n } else {\n reject(new Error(\"Facebook login failed\"));\n }\n }, { scope: options.permissions.join(',') });\n });\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -14,9 +14,11 @@ class SocialLoginWeb extends core.WebPlugin {
|
|
|
14
14
|
this.googleScriptLoaded = false;
|
|
15
15
|
this.appleScriptLoaded = false;
|
|
16
16
|
this.appleScriptUrl = "https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js";
|
|
17
|
+
this.facebookAppId = null;
|
|
18
|
+
this.facebookScriptLoaded = false;
|
|
17
19
|
}
|
|
18
20
|
async initialize(options) {
|
|
19
|
-
var _a, _b;
|
|
21
|
+
var _a, _b, _c;
|
|
20
22
|
if ((_a = options.google) === null || _a === void 0 ? void 0 : _a.webClientId) {
|
|
21
23
|
this.googleClientId = options.google.webClientId;
|
|
22
24
|
await this.loadGoogleScript();
|
|
@@ -25,6 +27,16 @@ class SocialLoginWeb extends core.WebPlugin {
|
|
|
25
27
|
this.appleClientId = options.apple.clientId;
|
|
26
28
|
await this.loadAppleScript();
|
|
27
29
|
}
|
|
30
|
+
if ((_c = options.facebook) === null || _c === void 0 ? void 0 : _c.appId) {
|
|
31
|
+
this.facebookAppId = options.facebook.appId;
|
|
32
|
+
await this.loadFacebookScript();
|
|
33
|
+
FB.init({
|
|
34
|
+
appId: this.facebookAppId,
|
|
35
|
+
version: 'v17.0',
|
|
36
|
+
xfbml: true,
|
|
37
|
+
cookie: true,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
28
40
|
// Implement initialization for other providers if needed
|
|
29
41
|
}
|
|
30
42
|
async login(options) {
|
|
@@ -34,6 +46,9 @@ class SocialLoginWeb extends core.WebPlugin {
|
|
|
34
46
|
else if (options.provider === "apple") {
|
|
35
47
|
return this.loginWithApple(options.options);
|
|
36
48
|
}
|
|
49
|
+
else if (options.provider === "facebook") {
|
|
50
|
+
return this.loginWithFacebook(options.options);
|
|
51
|
+
}
|
|
37
52
|
// Implement login for other providers
|
|
38
53
|
throw new Error(`Login for ${options.provider} is not implemented on web`);
|
|
39
54
|
}
|
|
@@ -49,9 +64,9 @@ class SocialLoginWeb extends core.WebPlugin {
|
|
|
49
64
|
console.log("Apple logout: Session should be managed on the client side");
|
|
50
65
|
break;
|
|
51
66
|
case "facebook":
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
67
|
+
return new Promise((resolve) => {
|
|
68
|
+
FB.logout(() => resolve());
|
|
69
|
+
});
|
|
55
70
|
default:
|
|
56
71
|
throw new Error(`Logout for ${options.provider} is not implemented`);
|
|
57
72
|
}
|
|
@@ -67,9 +82,11 @@ class SocialLoginWeb extends core.WebPlugin {
|
|
|
67
82
|
console.log("Apple login status should be managed on the client side");
|
|
68
83
|
return { isLoggedIn: false };
|
|
69
84
|
case "facebook":
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
85
|
+
return new Promise((resolve) => {
|
|
86
|
+
FB.getLoginStatus((response) => {
|
|
87
|
+
resolve({ isLoggedIn: response.status === 'connected' });
|
|
88
|
+
});
|
|
89
|
+
});
|
|
73
90
|
default:
|
|
74
91
|
throw new Error(`isLoggedIn for ${options.provider} is not implemented`);
|
|
75
92
|
}
|
|
@@ -88,9 +105,17 @@ class SocialLoginWeb extends core.WebPlugin {
|
|
|
88
105
|
console.log("Apple authorization code should be stored during login");
|
|
89
106
|
throw new Error("Apple authorization code not available");
|
|
90
107
|
case "facebook":
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
108
|
+
return new Promise((resolve, reject) => {
|
|
109
|
+
FB.getLoginStatus((response) => {
|
|
110
|
+
var _a;
|
|
111
|
+
if (response.status === 'connected') {
|
|
112
|
+
resolve({ jwt: ((_a = response.authResponse) === null || _a === void 0 ? void 0 : _a.accessToken) || "" });
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
reject(new Error("No Facebook authorization code available"));
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
});
|
|
94
119
|
default:
|
|
95
120
|
throw new Error(`getAuthorizationCode for ${options.provider} is not implemented`);
|
|
96
121
|
}
|
|
@@ -106,8 +131,7 @@ class SocialLoginWeb extends core.WebPlugin {
|
|
|
106
131
|
console.log("Apple refresh not available on web");
|
|
107
132
|
break;
|
|
108
133
|
case "facebook":
|
|
109
|
-
|
|
110
|
-
console.log("Facebook refresh not implemented");
|
|
134
|
+
await this.loginWithFacebook(options.options);
|
|
111
135
|
break;
|
|
112
136
|
default:
|
|
113
137
|
throw new Error(`Refresh for ${options.provider} is not implemented`);
|
|
@@ -246,6 +270,60 @@ class SocialLoginWeb extends core.WebPlugin {
|
|
|
246
270
|
});
|
|
247
271
|
});
|
|
248
272
|
}
|
|
273
|
+
async loadFacebookScript() {
|
|
274
|
+
if (this.facebookScriptLoaded)
|
|
275
|
+
return;
|
|
276
|
+
return new Promise((resolve, reject) => {
|
|
277
|
+
const script = document.createElement('script');
|
|
278
|
+
script.src = 'https://connect.facebook.net/en_US/sdk.js';
|
|
279
|
+
script.async = true;
|
|
280
|
+
script.defer = true;
|
|
281
|
+
script.onload = () => {
|
|
282
|
+
this.facebookScriptLoaded = true;
|
|
283
|
+
resolve();
|
|
284
|
+
};
|
|
285
|
+
script.onerror = reject;
|
|
286
|
+
document.body.appendChild(script);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
async loginWithFacebook(options) {
|
|
290
|
+
if (!this.facebookAppId) {
|
|
291
|
+
throw new Error("Facebook App ID not set. Call initialize() first.");
|
|
292
|
+
}
|
|
293
|
+
return new Promise((resolve, reject) => {
|
|
294
|
+
FB.login((response) => {
|
|
295
|
+
if (response.status === 'connected') {
|
|
296
|
+
FB.api('/me', { fields: 'id,name,email,picture' }, (userInfo) => {
|
|
297
|
+
var _a, _b;
|
|
298
|
+
const result = {
|
|
299
|
+
accessToken: {
|
|
300
|
+
token: response.authResponse.accessToken,
|
|
301
|
+
userId: response.authResponse.userID,
|
|
302
|
+
},
|
|
303
|
+
profile: {
|
|
304
|
+
userID: userInfo.id,
|
|
305
|
+
name: userInfo.name,
|
|
306
|
+
email: userInfo.email || null,
|
|
307
|
+
imageURL: ((_b = (_a = userInfo.picture) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.url) || null,
|
|
308
|
+
friendIDs: [],
|
|
309
|
+
birthday: null,
|
|
310
|
+
ageRange: null,
|
|
311
|
+
gender: null,
|
|
312
|
+
location: null,
|
|
313
|
+
hometown: null,
|
|
314
|
+
profileURL: null,
|
|
315
|
+
},
|
|
316
|
+
authenticationToken: null,
|
|
317
|
+
};
|
|
318
|
+
resolve({ provider: "facebook", result });
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
reject(new Error("Facebook login failed"));
|
|
323
|
+
}
|
|
324
|
+
}, { scope: options.permissions.join(',') });
|
|
325
|
+
});
|
|
326
|
+
}
|
|
249
327
|
}
|
|
250
328
|
|
|
251
329
|
var web = /*#__PURE__*/Object.freeze({
|