|
|
@@ -1320,10 +1320,17 @@ extension Auth: AuthInterop {
|
|
|
/// dictionary will contain more information about the error encountered.
|
|
|
@objc(signOut:) open func signOut() throws {
|
|
|
try kAuthGlobalWorkQueue.sync {
|
|
|
- guard self._currentUser != nil else {
|
|
|
- return
|
|
|
+ if self._currentUser != nil {
|
|
|
+ // Clear standard user session if one exists.
|
|
|
+ try self.updateCurrentUser(nil, byForce: false, savingToDisk: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Clear R-GCIP token-only session.
|
|
|
+ self.rGCIPFirebaseTokenLock.withLock { token in
|
|
|
+ if token != nil {
|
|
|
+ token = nil
|
|
|
+ }
|
|
|
}
|
|
|
- return try self.updateCurrentUser(nil, byForce: false, savingToDisk: true)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -2541,13 +2548,17 @@ public extension Auth {
|
|
|
/// call fails, or if the token response parsing fails.
|
|
|
func exchangeToken(idToken: String, idpConfigId: String,
|
|
|
useStaging: Bool = false) async throws -> FirebaseToken {
|
|
|
- // Ensure R-GCIP is configured with location and tenant ID
|
|
|
- guard let _ = requestConfiguration.tenantConfig?.location,
|
|
|
- let _ = requestConfiguration.tenantConfig?.tenantId
|
|
|
- else {
|
|
|
+ /// Ensure R-GCIP is configured with location and tenant ID.
|
|
|
+ guard requestConfiguration.tenantConfig != nil else {
|
|
|
/// This should never happen in production code, as it indicates a misconfiguration.
|
|
|
fatalError("R-GCIP is not configured correctly.")
|
|
|
}
|
|
|
+ /// This method should only be called on an R-GCIP instance
|
|
|
+ guard _currentUser == nil else {
|
|
|
+ fatalError(
|
|
|
+ "exchangeToken cannot be called on an Auth instance with an active standard user session."
|
|
|
+ )
|
|
|
+ }
|
|
|
let request = ExchangeTokenRequest(
|
|
|
idToken: idToken,
|
|
|
idpConfigID: idpConfigId,
|
|
|
@@ -2560,11 +2571,8 @@ public extension Auth {
|
|
|
token: response.firebaseToken,
|
|
|
expirationDate: response.expirationDate
|
|
|
)
|
|
|
- // Lock and update the token, signing out any current user.
|
|
|
+ // Lock and update the R-GCIP token.
|
|
|
rGCIPFirebaseTokenLock.withLock { token in
|
|
|
- if self._currentUser != nil {
|
|
|
- try? self.signOut()
|
|
|
- }
|
|
|
token = newToken
|
|
|
}
|
|
|
return newToken
|