Skip to content

Commit 6c84a95

Browse files
committed
Fix crash when identityToken is null
1 parent 03acf0a commit 6c84a95

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

OAuth/FirebaseOAuthUI/FUIOAuth.m

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ + (FUIOAuth *)yahooAuthProvider {
191191
}
192192

193193
+ (FUIOAuth *)appleAuthProvider {
194-
return [self appleAuthProviderWithUserInterfaceStyle:UITraitCollection.currentTraitCollection.userInterfaceStyle];
194+
UIUserInterfaceStyle style = UITraitCollection.currentTraitCollection.userInterfaceStyle;
195+
return [self appleAuthProviderWithUserInterfaceStyle:style];
195196
}
196197

197198
+ (FUIOAuth *)appleAuthProviderWithUserInterfaceStyle:(UIUserInterfaceStyle)userInterfaceStyle {
@@ -203,6 +204,12 @@ + (FUIOAuth *)appleAuthProviderWithUserInterfaceStyle:(UIUserInterfaceStyle)user
203204
iconImage = [iconImage imageWithTintColor:[UIColor blackColor]];
204205
buttonColor = [UIColor whiteColor];
205206
buttonTextColor = [UIColor blackColor];
207+
} else if (userInterfaceStyle == UIUserInterfaceStyleLight) {
208+
iconImage = [iconImage imageWithTintColor:[UIColor whiteColor]];
209+
buttonColor = [UIColor blackColor];
210+
buttonTextColor = [UIColor whiteColor];
211+
} else {
212+
iconImage = [iconImage imageWithTintColor:[UIColor whiteColor]];
206213
}
207214
FUIOAuth *provider = [[FUIOAuth alloc] initWithAuthUI:[FUIAuth defaultAuthUI]
208215
providerID:@"apple.com"
@@ -213,7 +220,7 @@ + (FUIOAuth *)appleAuthProviderWithUserInterfaceStyle:(UIUserInterfaceStyle)user
213220
scopes:@[@"name", @"email"]
214221
customParameters:nil
215222
loginHintKey:nil];
216-
provider.buttonAlignment = FUIButtonAlignmentCenter;
223+
provider.buttonAlignment = FUIButtonAlignmentLeading;
217224
provider.buttonTextColor = buttonTextColor;
218225
return provider;
219226
}
@@ -312,6 +319,14 @@ - (BOOL)handleOpenURL:(NSURL *)URL sourceApplication:(nullable NSString *)source
312319

313320
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization API_AVAILABLE(ios(13.0)) {
314321
ASAuthorizationAppleIDCredential* appleIDCredential = authorization.credential;
322+
NSData *rawIdentityToken = appleIDCredential.identityToken;
323+
if (rawIdentityToken == nil) {
324+
// It's pretty awful to not have an error when login is unsuccessful, but Apple's docs
325+
// don't provide any useful information here.
326+
// https://developer.apple.com/documentation/authenticationservices/asauthorizationappleidcredential
327+
NSLog(@"Sign in with Apple completed with authorization, but no jwt: %@", authorization);
328+
_providerSignInCompletion(nil, nil, nil, nil);
329+
}
315330
NSString *idToken = [[NSString alloc] initWithData:appleIDCredential.identityToken encoding:NSUTF8StringEncoding];
316331
FIROAuthCredential *credential = [FIROAuthProvider credentialWithProviderID:@"apple.com"
317332
IDToken:idToken

0 commit comments

Comments
 (0)