Skip to content

Commit 22c4c13

Browse files
authored
fix(authentication): Bad accessToken when signing in via Facebook under iOS (#843)
1 parent c42b173 commit 22c4c13

File tree

11 files changed

+333
-28
lines changed

11 files changed

+333
-28
lines changed

.changeset/happy-oranges-rush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@capacitor-firebase/authentication': minor
3+
---
4+
5+
feat(ios): support Facebook Limited Login

packages/authentication/README.md

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ const verifyBeforeUpdateEmail = async () => {
484484
* [`useAppLanguage()`](#useapplanguage)
485485
* [`useEmulator(...)`](#useemulator)
486486
* [`verifyBeforeUpdateEmail(...)`](#verifybeforeupdateemail)
487+
* [`checkAppTrackingTransparencyPermission()`](#checkapptrackingtransparencypermission)
488+
* [`requestAppTrackingTransparencyPermission()`](#requestapptrackingtransparencypermission)
487489
* [`addListener('authStateChange', ...)`](#addlistenerauthstatechange-)
488490
* [`addListener('idTokenChange', ...)`](#addlisteneridtokenchange-)
489491
* [`addListener('phoneVerificationCompleted', ...)`](#addlistenerphoneverificationcompleted-)
@@ -1231,14 +1233,14 @@ Signs in using an email and sign-in email link.
12311233
### signInWithFacebook(...)
12321234

12331235
```typescript
1234-
signInWithFacebook(options?: SignInWithOAuthOptions | undefined) => Promise<SignInResult>
1236+
signInWithFacebook(options?: SignInWithFacebookOptions | undefined) => Promise<SignInResult>
12351237
```
12361238

12371239
Starts the Facebook sign-in flow.
12381240

1239-
| Param | Type |
1240-
| ------------- | ------------------------------------------------------------------------- |
1241-
| **`options`** | <code><a href="#signinwithoauthoptions">SignInWithOAuthOptions</a></code> |
1241+
| Param | Type |
1242+
| ------------- | ------------------------------------------------------------------------------- |
1243+
| **`options`** | <code><a href="#signinwithfacebookoptions">SignInWithFacebookOptions</a></code> |
12421244

12431245
**Returns:** <code>Promise&lt;<a href="#signinresult">SignInResult</a>&gt;</code>
12441246

@@ -1556,6 +1558,42 @@ Verifies the new email address before updating the email address of the currentl
15561558
--------------------
15571559

15581560

1561+
### checkAppTrackingTransparencyPermission()
1562+
1563+
```typescript
1564+
checkAppTrackingTransparencyPermission() => Promise<CheckAppTrackingTransparencyPermissionResult>
1565+
```
1566+
1567+
Checks the current status of app tracking transparency.
1568+
1569+
Only available on iOS.
1570+
1571+
**Returns:** <code>Promise&lt;<a href="#checkapptrackingtransparencypermissionresult">CheckAppTrackingTransparencyPermissionResult</a>&gt;</code>
1572+
1573+
**Since:** 7.2.0
1574+
1575+
--------------------
1576+
1577+
1578+
### requestAppTrackingTransparencyPermission()
1579+
1580+
```typescript
1581+
requestAppTrackingTransparencyPermission() => Promise<RequestAppTrackingTransparencyPermissionResult>
1582+
```
1583+
1584+
Opens the system dialog to authorize app tracking transparency.
1585+
1586+
**Attention:** The user may have disabled the tracking request in the device settings, see [Apple's documentation](https://support.apple.com/guide/iphone/iph4f4cbd242/ios).
1587+
1588+
Only available on iOS.
1589+
1590+
**Returns:** <code>Promise&lt;<a href="#checkapptrackingtransparencypermissionresult">CheckAppTrackingTransparencyPermissionResult</a>&gt;</code>
1591+
1592+
**Since:** 7.2.0
1593+
1594+
--------------------
1595+
1596+
15591597
### addListener('authStateChange', ...)
15601598

15611599
```typescript
@@ -1988,6 +2026,13 @@ An interface covering the possible persistence mechanism types.
19882026
| **`emailLink`** | <code>string</code> | The link sent to the user's email address. | 1.1.0 |
19892027

19902028

2029+
#### SignInWithFacebookOptions
2030+
2031+
| Prop | Type | Description | Default | Since |
2032+
| --------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
2033+
| **`useLimitedLogin`** | <code>boolean</code> | Whether to use the Facebook Limited Login mode. If set to `true`, no access token will be returned but the user does not have to grant App Tracking Transparency permission. If set to `false`, the user has to grant App Tracking Transparency permission. You can request the permission with `requestAppTrackingTransparencyPermission()`. Only available for iOS. | <code>false</code> | 7.2.0 |
2034+
2035+
19912036
#### SignInOptions
19922037

19932038
| Prop | Type | Description | Since |
@@ -2048,6 +2093,13 @@ An interface covering the possible persistence mechanism types.
20482093
| **`actionCodeSettings`** | <code><a href="#actioncodesettings">ActionCodeSettings</a></code> | The action code settings | 6.3.0 |
20492094

20502095

2096+
#### CheckAppTrackingTransparencyPermissionResult
2097+
2098+
| Prop | Type | Description | Since |
2099+
| ------------ | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------- | ----- |
2100+
| **`status`** | <code><a href="#apptrackingtransparencypermissionstate">AppTrackingTransparencyPermissionState</a></code> | The permission status of App Tracking Transparency. | 7.2.0 |
2101+
2102+
20512103
#### PluginListenerHandle
20522104

20532105
| Prop | Type |
@@ -2106,6 +2158,21 @@ An interface covering the possible persistence mechanism types.
21062158
<code><a href="#signinwithphonenumberoptions">SignInWithPhoneNumberOptions</a></code>
21072159

21082160

2161+
#### AppTrackingTransparencyPermissionState
2162+
2163+
<code><a href="#permissionstate">PermissionState</a> | 'restricted'</code>
2164+
2165+
2166+
#### PermissionState
2167+
2168+
<code>'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'</code>
2169+
2170+
2171+
#### RequestAppTrackingTransparencyPermissionResult
2172+
2173+
<code><a href="#checkapptrackingtransparencypermissionresult">CheckAppTrackingTransparencyPermissionResult</a></code>
2174+
2175+
21092176
#### AuthStateChangeListener
21102177

21112178
Callback to receive the user's sign-in state change notifications.

packages/authentication/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/authentication/FirebaseAuthenticationPlugin.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,16 @@ public void useEmulator(PluginCall call) {
955955
}
956956
}
957957

958+
@PluginMethod
959+
public void requestAppTrackingTransparencyPermission(PluginCall call) {
960+
call.reject("Not available on Android.");
961+
}
962+
963+
@PluginMethod
964+
public void checkAppTrackingTransparencyPermission(PluginCall call) {
965+
call.reject("Not available on Android.");
966+
}
967+
958968
public void handlePhoneVerificationCompleted(@NonNull final PhoneVerificationCompletedEvent event) {
959969
notifyListeners(PHONE_VERIFICATION_COMPLETED_EVENT, event.toJSObject(), true);
960970
}

packages/authentication/docs/setup-facebook.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@
155155
`[CLIENT_TOKEN]` must be replaced with your Facebook Client Token (App Dashboard > Settings > Advanced > Client Token).
156156
`[APP_NAME]` must be replaced with your Facebook app name.
157157

158+
1. Set the `NSUserTrackingUsageDescription` key in your app's `Info.plist`:
159+
160+
```
161+
<key>NSUserTrackingUsageDescription</key>
162+
<string>This identifier will be used to request permission to track the user's activity.</string>
163+
```
164+
158165
## Web
159166

160167
1. See [Before you begin](https://firebase.google.com/docs/auth/web/facebook-login#before_you_begin) and follow the instructions to configure and enable sign-in with Facebook correctly.

packages/authentication/ios/Plugin.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
50E1A94820377CB70090CE1A /* FirebaseAuthenticationPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E1A94720377CB70090CE1A /* FirebaseAuthenticationPlugin.swift */; };
1717
7C0C050B2BAD80E2004252BE /* FetchSignInMethodsForEmailOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C0C050A2BAD80E2004252BE /* FetchSignInMethodsForEmailOptions.swift */; };
1818
7C0C050D2BAD80EC004252BE /* FetchSignInMethodsForEmailResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C0C050C2BAD80EC004252BE /* FetchSignInMethodsForEmailResult.swift */; };
19+
7C1F76152D83359D00386F35 /* CheckAppTrackingTransparencyPermissionResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C1F76142D83359100386F35 /* CheckAppTrackingTransparencyPermissionResult.swift */; };
1920
7C20942E2C2D8FC400C75248 /* SendEmailVerificationOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C20942D2C2D8FC400C75248 /* SendEmailVerificationOptions.swift */; };
2021
7C2094302C2D8FD100C75248 /* SendPasswordResetEmailOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C20942F2C2D8FD100C75248 /* SendPasswordResetEmailOptions.swift */; };
2122
7C3D92CA26D3CC62000C0B29 /* PhoneAuthProviderHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C3D92C926D3CC62000C0B29 /* PhoneAuthProviderHandler.swift */; };
@@ -61,6 +62,7 @@
6162
5E23F77F099397094342571A /* Pods-Plugin.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Plugin.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Plugin/Pods-Plugin.debug.xcconfig"; sourceTree = "<group>"; };
6263
7C0C050A2BAD80E2004252BE /* FetchSignInMethodsForEmailOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchSignInMethodsForEmailOptions.swift; sourceTree = "<group>"; };
6364
7C0C050C2BAD80EC004252BE /* FetchSignInMethodsForEmailResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchSignInMethodsForEmailResult.swift; sourceTree = "<group>"; };
65+
7C1F76142D83359100386F35 /* CheckAppTrackingTransparencyPermissionResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckAppTrackingTransparencyPermissionResult.swift; sourceTree = "<group>"; };
6466
7C20942D2C2D8FC400C75248 /* SendEmailVerificationOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendEmailVerificationOptions.swift; sourceTree = "<group>"; };
6567
7C20942F2C2D8FD100C75248 /* SendPasswordResetEmailOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendPasswordResetEmailOptions.swift; sourceTree = "<group>"; };
6668
7C3D92C926D3CC62000C0B29 /* PhoneAuthProviderHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneAuthProviderHandler.swift; sourceTree = "<group>"; };
@@ -167,6 +169,7 @@
167169
7C0C05092BAD80CF004252BE /* Results */ = {
168170
isa = PBXGroup;
169171
children = (
172+
7C1F76142D83359100386F35 /* CheckAppTrackingTransparencyPermissionResult.swift */,
170173
7C0C050C2BAD80EC004252BE /* FetchSignInMethodsForEmailResult.swift */,
171174
);
172175
path = Results;
@@ -461,6 +464,7 @@
461464
7C2094302C2D8FD100C75248 /* SendPasswordResetEmailOptions.swift in Sources */,
462465
7C20942E2C2D8FC400C75248 /* SendEmailVerificationOptions.swift in Sources */,
463466
7C57A00129F4023E00B7778B /* RuntimeError.swift in Sources */,
467+
7C1F76152D83359D00386F35 /* CheckAppTrackingTransparencyPermissionResult.swift in Sources */,
464468
);
465469
runOnlyForDeploymentPostprocessing = 0;
466470
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Capacitor
2+
import AppTrackingTransparency
3+
4+
@objc public class CheckAppTrackingTransparencyPermissionResult: NSObject, Result {
5+
let status: ATTrackingManager.AuthorizationStatus
6+
7+
init(_ status: ATTrackingManager.AuthorizationStatus) {
8+
self.status = status
9+
}
10+
11+
func toJSObject() -> AnyObject {
12+
var result = JSObject()
13+
result["status"] = convertStatusToPermissionStatus(status)
14+
return result as AnyObject
15+
}
16+
17+
private func convertStatusToPermissionStatus(_ status: ATTrackingManager.AuthorizationStatus) -> String {
18+
switch status {
19+
case .notDetermined:
20+
return "prompt"
21+
case .denied:
22+
return "denied"
23+
case .authorized:
24+
return "granted"
25+
case .restricted:
26+
return "restricted"
27+
@unknown default:
28+
return "prompt"
29+
}
30+
}
31+
}

packages/authentication/ios/Plugin/FirebaseAuthentication.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Foundation
22
import Capacitor
33
import FirebaseCore
44
import FirebaseAuth
5+
import AppTrackingTransparency
56

67
public typealias AuthStateChangedObserver = () -> Void
78

@@ -645,6 +646,16 @@ public typealias AuthStateChangedObserver = () -> Void
645646
return self.config
646647
}
647648

649+
func requestAppTrackingTransparencyPermission(completion: @escaping (CheckAppTrackingTransparencyPermissionResult) -> Void) {
650+
ATTrackingManager.requestTrackingAuthorization { result in
651+
completion(CheckAppTrackingTransparencyPermissionResult(result))
652+
}
653+
}
654+
655+
func checkAppTrackingTransparencyPermission(completion: @escaping (CheckAppTrackingTransparencyPermissionResult) -> Void) {
656+
completion(CheckAppTrackingTransparencyPermissionResult(ATTrackingManager.trackingAuthorizationStatus))
657+
}
658+
648659
private func initAuthProviderHandlers(config: FirebaseAuthenticationConfig) {
649660
if config.providers.contains(ProviderId.apple) {
650661
self.appleAuthProviderHandler = AppleAuthProviderHandler(self)

packages/authentication/ios/Plugin/FirebaseAuthenticationPlugin.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public class FirebaseAuthenticationPlugin: CAPPlugin, CAPBridgedPlugin {
6868
CAPPluginMethod(name: "updateProfile", returnType: CAPPluginReturnPromise),
6969
CAPPluginMethod(name: "useAppLanguage", returnType: CAPPluginReturnPromise),
7070
CAPPluginMethod(name: "useEmulator", returnType: CAPPluginReturnPromise),
71-
CAPPluginMethod(name: "verifyBeforeUpdateEmail", returnType: CAPPluginReturnPromise)
71+
CAPPluginMethod(name: "verifyBeforeUpdateEmail", returnType: CAPPluginReturnPromise),
72+
CAPPluginMethod(name: "requestAppTrackingTransparencyPermission", returnType: CAPPluginReturnPromise),
73+
CAPPluginMethod(name: "checkAppTrackingTransparencyPermission", returnType: CAPPluginReturnPromise)
7274
]
7375
public let tag = "FirebaseAuthentication"
7476
public let errorProviderIdMissing = "providerId must be provided."
@@ -643,6 +645,22 @@ public class FirebaseAuthenticationPlugin: CAPPlugin, CAPBridgedPlugin {
643645
call.resolve()
644646
}
645647

648+
@objc func requestAppTrackingTransparencyPermission(_ call: CAPPluginCall) {
649+
implementation?.requestAppTrackingTransparencyPermission { status in
650+
if let result = status.toJSObject() as? JSObject {
651+
call.resolve(result)
652+
}
653+
}
654+
}
655+
656+
@objc func checkAppTrackingTransparencyPermission(_ call: CAPPluginCall) {
657+
implementation?.checkAppTrackingTransparencyPermission { status in
658+
if let result = status.toJSObject() as? JSObject {
659+
call.resolve(result)
660+
}
661+
}
662+
}
663+
646664
@objc func handleAuthStateChange() {
647665
let user = implementation?.getCurrentUser()
648666
let userResult = FirebaseAuthenticationHelper.createUserResult(user)

0 commit comments

Comments
 (0)