@capgo/capacitor-social-login 0.0.28 → 0.0.30
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
CHANGED
|
@@ -371,10 +371,11 @@ Refresh the access token
|
|
|
371
371
|
|
|
372
372
|
#### FacebookLoginResponse
|
|
373
373
|
|
|
374
|
-
| Prop
|
|
375
|
-
|
|
|
376
|
-
| **`accessToken`**
|
|
377
|
-
| **`profile`**
|
|
374
|
+
| Prop | Type |
|
|
375
|
+
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
376
|
+
| **`accessToken`** | <code><a href="#accesstoken">AccessToken</a> \| null</code> |
|
|
377
|
+
| **`profile`** | <code>{ userID: string; email: string \| null; friendIDs: string[]; birthday: string \| null; ageRange: { min?: number; max?: number; } \| null; gender: string \| null; location: { id: string; name: string; } \| null; hometown: { id: string; name: string; } \| null; profileURL: string \| null; name: string \| null; imageURL: string \| null; }</code> |
|
|
378
|
+
| **`authenticationToken`** | <code>string \| null</code> |
|
|
378
379
|
|
|
379
380
|
|
|
380
381
|
#### AccessToken
|
|
@@ -422,9 +423,11 @@ Refresh the access token
|
|
|
422
423
|
|
|
423
424
|
#### FacebookLoginOptions
|
|
424
425
|
|
|
425
|
-
| Prop
|
|
426
|
-
|
|
|
427
|
-
| **`permissions`**
|
|
426
|
+
| Prop | Type | Description | Default |
|
|
427
|
+
| ------------------ | --------------------- | ---------------- | ------------------ |
|
|
428
|
+
| **`permissions`** | <code>string[]</code> | Permissions | |
|
|
429
|
+
| **`limitedLogin`** | <code>boolean</code> | Is Limited Login | <code>false</code> |
|
|
430
|
+
| **`nonce`** | <code>string</code> | Nonce | |
|
|
428
431
|
|
|
429
432
|
|
|
430
433
|
#### GoogleLoginOptions
|
package/dist/docs.json
CHANGED
|
@@ -235,7 +235,14 @@
|
|
|
235
235
|
"tags": [],
|
|
236
236
|
"docs": "",
|
|
237
237
|
"complexTypes": [],
|
|
238
|
-
"type": "{
|
|
238
|
+
"type": "{ userID: string; email: string | null; friendIDs: string[]; birthday: string | null; ageRange: { min?: number | undefined; max?: number | undefined; } | null; gender: string | null; location: { id: string; name: string; } | null; hometown: { id: string; name: string; } | null; profileURL: string | null; name: string | null; imageURL: string | null; }"
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
"name": "authenticationToken",
|
|
242
|
+
"tags": [],
|
|
243
|
+
"docs": "",
|
|
244
|
+
"complexTypes": [],
|
|
245
|
+
"type": "string | null"
|
|
239
246
|
}
|
|
240
247
|
]
|
|
241
248
|
},
|
|
@@ -442,6 +449,34 @@
|
|
|
442
449
|
"docs": "Permissions",
|
|
443
450
|
"complexTypes": [],
|
|
444
451
|
"type": "string[]"
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
"name": "limitedLogin",
|
|
455
|
+
"tags": [
|
|
456
|
+
{
|
|
457
|
+
"text": "use limited login for Facebook IOS",
|
|
458
|
+
"name": "description"
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
"text": "false",
|
|
462
|
+
"name": "default"
|
|
463
|
+
}
|
|
464
|
+
],
|
|
465
|
+
"docs": "Is Limited Login",
|
|
466
|
+
"complexTypes": [],
|
|
467
|
+
"type": "boolean | undefined"
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
"name": "nonce",
|
|
471
|
+
"tags": [
|
|
472
|
+
{
|
|
473
|
+
"text": "A custom nonce to use for the login request",
|
|
474
|
+
"name": "description"
|
|
475
|
+
}
|
|
476
|
+
],
|
|
477
|
+
"docs": "Nonce",
|
|
478
|
+
"complexTypes": [],
|
|
479
|
+
"type": "string | undefined"
|
|
445
480
|
}
|
|
446
481
|
]
|
|
447
482
|
},
|
|
@@ -45,6 +45,17 @@ export interface FacebookLoginOptions {
|
|
|
45
45
|
* @description select permissions to login with
|
|
46
46
|
*/
|
|
47
47
|
permissions: string[];
|
|
48
|
+
/**
|
|
49
|
+
* Is Limited Login
|
|
50
|
+
* @description use limited login for Facebook IOS
|
|
51
|
+
* @default false
|
|
52
|
+
*/
|
|
53
|
+
limitedLogin?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Nonce
|
|
56
|
+
* @description A custom nonce to use for the login request
|
|
57
|
+
*/
|
|
58
|
+
nonce?: string;
|
|
48
59
|
}
|
|
49
60
|
export interface GoogleLoginOptions {
|
|
50
61
|
/**
|
|
@@ -142,8 +153,28 @@ export interface AccessToken {
|
|
|
142
153
|
export interface FacebookLoginResponse {
|
|
143
154
|
accessToken: AccessToken | null;
|
|
144
155
|
profile: {
|
|
145
|
-
|
|
156
|
+
userID: string;
|
|
157
|
+
email: string | null;
|
|
158
|
+
friendIDs: string[];
|
|
159
|
+
birthday: string | null;
|
|
160
|
+
ageRange: {
|
|
161
|
+
min?: number;
|
|
162
|
+
max?: number;
|
|
163
|
+
} | null;
|
|
164
|
+
gender: string | null;
|
|
165
|
+
location: {
|
|
166
|
+
id: string;
|
|
167
|
+
name: string;
|
|
168
|
+
} | null;
|
|
169
|
+
hometown: {
|
|
170
|
+
id: string;
|
|
171
|
+
name: string;
|
|
172
|
+
} | null;
|
|
173
|
+
profileURL: string | null;
|
|
174
|
+
name: string | null;
|
|
175
|
+
imageURL: string | null;
|
|
146
176
|
};
|
|
177
|
+
authenticationToken: string | null;
|
|
147
178
|
}
|
|
148
179
|
export interface AuthorizationCode {
|
|
149
180
|
/**
|
|
@@ -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\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\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
|
|
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\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"]}
|
|
@@ -9,6 +9,7 @@ import FacebookLogin
|
|
|
9
9
|
struct FacebookLoginResponse {
|
|
10
10
|
let accessToken: [String: Any]
|
|
11
11
|
let profile: [String: Any]
|
|
12
|
+
let authenticationToken: String?
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
class FacebookProvider {
|
|
@@ -37,38 +38,90 @@ class FacebookProvider {
|
|
|
37
38
|
return
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
let limitedLogin = payload["limitedLogin"] as? Bool ?? false
|
|
42
|
+
let nonce = payload["nonce"] as? String ?? "123"
|
|
43
|
+
|
|
44
|
+
let tracking: LoginTracking = limitedLogin ? .limited : .enabled
|
|
45
|
+
|
|
46
|
+
guard let configuration = LoginConfiguration(
|
|
47
|
+
permissions: permissions,
|
|
48
|
+
tracking: tracking,
|
|
49
|
+
nonce: nonce
|
|
50
|
+
) else {
|
|
51
|
+
completion(.failure(NSError(domain: "FacebookProvider", code: 0, userInfo: [NSLocalizedDescriptionKey: "Invalid login configuration"])))
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
|
|
40
55
|
DispatchQueue.main.async {
|
|
41
|
-
self.loginManager.logIn(
|
|
42
|
-
|
|
56
|
+
self.loginManager.logIn(configuration: configuration) { result in
|
|
57
|
+
switch result {
|
|
58
|
+
case .success:
|
|
59
|
+
let response = self.createLoginResponse()
|
|
60
|
+
completion(.success(response))
|
|
61
|
+
case .failed(let error):
|
|
43
62
|
completion(.failure(error))
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
guard let result = result, !result.isCancelled else {
|
|
63
|
+
case .cancelled:
|
|
48
64
|
completion(.failure(NSError(domain: "FacebookProvider", code: 0, userInfo: [NSLocalizedDescriptionKey: "Login cancelled"])))
|
|
49
|
-
return
|
|
50
65
|
}
|
|
51
66
|
|
|
52
|
-
let accessToken = result.token
|
|
53
|
-
let response = FacebookLoginResponse(
|
|
54
|
-
accessToken: [
|
|
55
|
-
"applicationID": accessToken?.appID ?? "",
|
|
56
|
-
"declinedPermissions": accessToken?.declinedPermissions.map { $0.name } ?? [],
|
|
57
|
-
"expirationDate": accessToken?.expirationDate ?? Date(),
|
|
58
|
-
"isExpired": accessToken?.isExpired ?? false,
|
|
59
|
-
"refreshDate": accessToken?.refreshDate ?? Date(),
|
|
60
|
-
"permissions": accessToken?.permissions.map { $0.name } ?? [],
|
|
61
|
-
"tokenString": accessToken?.tokenString ?? "",
|
|
62
|
-
"userID": accessToken?.userID ?? ""
|
|
63
|
-
],
|
|
64
|
-
profile: [:]
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
completion(.success(response))
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
|
|
71
|
+
private func createLoginResponse() -> FacebookLoginResponse {
|
|
72
|
+
let profile = Profile.current
|
|
73
|
+
let authToken = AuthenticationToken.current
|
|
74
|
+
|
|
75
|
+
let accessToken: [String: Any] = [
|
|
76
|
+
"applicationID": AccessToken.current?.appID ?? "",
|
|
77
|
+
"declinedPermissions": AccessToken.current?.declinedPermissions.map { $0.name } ?? [],
|
|
78
|
+
"expirationDate": AccessToken.current?.expirationDate ?? Date(),
|
|
79
|
+
"isExpired": AccessToken.current?.isExpired ?? false,
|
|
80
|
+
"refreshDate": AccessToken.current?.refreshDate ?? Date(),
|
|
81
|
+
"permissions": AccessToken.current?.permissions.map { $0.name } ?? [],
|
|
82
|
+
"tokenString": AccessToken.current?.tokenString ?? "",
|
|
83
|
+
"userID": AccessToken.current?.userID ?? ""
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
let profileData: [String: Any] = [
|
|
87
|
+
"userID": profile?.userID ?? "",
|
|
88
|
+
"email": profile?.email ?? "",
|
|
89
|
+
"friendIDs": profile?.friendIDs ?? [],
|
|
90
|
+
"birthday": profile?.birthday ?? "",
|
|
91
|
+
"ageRange": profile?.ageRange.flatMap(ageRangeToDictionary) ?? [:],
|
|
92
|
+
"gender": profile?.gender ?? "",
|
|
93
|
+
"location": profile?.location.flatMap(locationToDictionary) ?? [:],
|
|
94
|
+
"hometown": profile?.hometown.flatMap(locationToDictionary) ?? [:],
|
|
95
|
+
"profileURL": profile?.linkURL?.absoluteString ?? "",
|
|
96
|
+
"name": profile?.name ?? "",
|
|
97
|
+
"imageURL": profile?.imageURL?.absoluteString ?? ""
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
return FacebookLoginResponse(
|
|
101
|
+
accessToken: accessToken,
|
|
102
|
+
profile: profileData,
|
|
103
|
+
authenticationToken: authToken?.tokenString
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private func locationToDictionary(_ location: Location) -> [String: String] {
|
|
108
|
+
return [
|
|
109
|
+
"id": location.id,
|
|
110
|
+
"name": location.name
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private func ageRangeToDictionary(_ ageRange: UserAgeRange) -> [String: Int] {
|
|
115
|
+
var result: [String: Int] = [:]
|
|
116
|
+
if let min = ageRange.min {
|
|
117
|
+
result["min"] = min.intValue
|
|
118
|
+
}
|
|
119
|
+
if let max = ageRange.max {
|
|
120
|
+
result["max"] = max.intValue
|
|
121
|
+
}
|
|
122
|
+
return result
|
|
123
|
+
}
|
|
124
|
+
|
|
72
125
|
func logout(completion: @escaping (Result<Void, Error>) -> Void) {
|
|
73
126
|
loginManager.logOut()
|
|
74
127
|
completion(.success(()))
|