Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions Example/Auth/Sample/MainViewController+OAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ - (StaticContentTableViewSection *)oAuthSection {
return [StaticContentTableViewSection sectionWithTitle:@"OAuth" cells:@[
[StaticContentTableViewCell cellWithTitle:@"Sign in with Google"
action:^{ [weakSelf signInGoogleHeadfulLite]; }],
[StaticContentTableViewCell cellWithTitle:@"Link with Google"
action:^{ [weakSelf linkWithGoogleHeadfulLite]; }],
[StaticContentTableViewCell cellWithTitle:@"Reauthenticate with Google"
action:^{ [weakSelf reauthenticateWithGoogleHeadfulLite]; }],
[StaticContentTableViewCell cellWithTitle:@"Sign in with Twitter"
action:^{ [weakSelf signInTwitterHeadfulLite]; }],
[StaticContentTableViewCell cellWithTitle:@"Sign in with GitHub"
Expand Down Expand Up @@ -75,6 +79,68 @@ - (void)signInGoogleHeadfulLite {
}];
}

- (void)linkWithGoogleHeadfulLite {
FIROAuthProvider *provider = self.googleOAuthProvider;
provider.customParameters = @{
@"prompt" : @"consent",
};
provider.scopes = @[ @"profile", @"email", @"https://www.googleapis.com/auth/plus.me" ];
[self showSpinner:^{
[[AppManager auth].currentUser linkWithProvider:provider
UIDelegate:nil
completion:^(FIRAuthDataResult *_Nullable authResult,
NSError *_Nullable error) {
[self hideSpinner:^{
if (error) {
[self logFailure:@"Reauthenticate with provider (Google) failed" error:error];
} else if (authResult.additionalUserInfo) {
[self logSuccess:[self stringWithAdditionalUserInfo:authResult.additionalUserInfo]];
if (self.isNewUserToggleOn) {
NSString *newUserString = authResult.additionalUserInfo.newUser ?
@"New user" : @"Existing user";
[self showMessagePromptWithTitle:@"New or Existing"
message:newUserString
showCancelButton:NO
completion:nil];
}
}
[self showTypicalUIForUserUpdateResultsWithTitle:@"Link Error" error:error];
}];
}];
}];
}

- (void)reauthenticateWithGoogleHeadfulLite {
FIROAuthProvider *provider = self.googleOAuthProvider;
provider.customParameters = @{
@"prompt" : @"consent",
};
provider.scopes = @[ @"profile", @"email", @"https://www.googleapis.com/auth/plus.me" ];
[self showSpinner:^{
[[AppManager auth].currentUser reauthenticateWithProvider:provider
UIDelegate:nil
completion:^(FIRAuthDataResult *_Nullable authResult,
NSError *_Nullable error) {
[self hideSpinner:^{
if (error) {
[self logFailure:@"Link with provider (Google) failed" error:error];
} else if (authResult.additionalUserInfo) {
[self logSuccess:[self stringWithAdditionalUserInfo:authResult.additionalUserInfo]];
if (self.isNewUserToggleOn) {
NSString *newUserString = authResult.additionalUserInfo.newUser ?
@"New user" : @"Existing user";
[self showMessagePromptWithTitle:@"New or Existing"
message:newUserString
showCancelButton:NO
completion:nil];
}
}
[self showTypicalUIForUserUpdateResultsWithTitle:@"Reauthenticate Error" error:error];
}];
}];
}];
}

- (void)signInTwitterHeadfulLite {
FIROAuthProvider *provider = self.twitterOAuthProvider;
[self showSpinner:^{
Expand Down
33 changes: 33 additions & 0 deletions Firebase/Auth/Source/Public/FIRUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@class FIRPhoneAuthCredential;
@class FIRUserProfileChangeRequest;
@class FIRUserMetadata;
@protocol FIRAuthUIDelegate;

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -269,6 +270,22 @@ DEPRECATED_MSG_ATTRIBUTE( "Please use reauthenticateWithCredential:completion: f
" Objective-C or reauthenticate(withCredential:completion:)"
" for Swift instead.");

/** @fn reauthenticateWithProvider:UIDelegate:completion:
@brief Renews the user's authentication using the provided auth provider instance.

@param provider An instance of an auth provider used to initiate the reauthenticate flow.
@param UIDelegate Optionally an instance of a class conforming to the FIRAuthUIDelegate
protocol, this is used for presenting the web context. If nil, a default FIRAuthUIDelegate
will be used.
@param completion Optionally; a block which is invoked when the reauthenticate flow finishes, or
is canceled. Invoked asynchronously on the main thread in the future.
*/
- (void)reauthenticateWithProvider:(id<FIRFederatedAuthProvider>)provider
UIDelegate:(nullable id<FIRAuthUIDelegate>)UIDelegate
completion:(nullable FIRAuthDataResultCallback)completion
NS_SWIFT_NAME(reauthenticate(with:uiDelegate:completion:))
API_AVAILABLE(ios(8.0));

/** @fn getIDTokenResultWithCompletion:
@brief Retrieves the Firebase authentication token, possibly refreshing it if it has expired.

Expand Down Expand Up @@ -359,6 +376,22 @@ DEPRECATED_MSG_ATTRIBUTE("Please use linkWithCredential:completion: for Objectiv
- (void)linkWithCredential:(FIRAuthCredential *)credential
completion:(nullable FIRAuthDataResultCallback)completion;

/** @fn linkWithProvider:UIDelegate:completion:
@brief link the user with the provided auth provider instance.

@param provider An instance of an auth provider used to initiate the link flow.
@param UIDelegate Optionally an instance of a class conforming to the FIRAuthUIDelegate
protocol, this is used for presenting the web context. If nil, a default FIRAuthUIDelegate
will be used.
@param completion Optionally; a block which is invoked when the link flow finishes, or
is canceled. Invoked asynchronously on the main thread in the future.
*/
- (void)linkWithProvider:(id<FIRFederatedAuthProvider>)provider
UIDelegate:(nullable id<FIRAuthUIDelegate>)UIDelegate
completion:(nullable FIRAuthDataResultCallback)completion
NS_SWIFT_NAME(link(with:uiDelegate:completion:))
API_AVAILABLE(ios(8.0));

/** @fn unlinkFromProvider:completion:
@brief Disassociates a user account from a third-party identity provider with this user.

Expand Down
31 changes: 31 additions & 0 deletions Firebase/Auth/Source/User/FIRUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#import "FIREmailAuthProvider.h"
#import "FIREmailPasswordAuthCredential.h"
#import "FIREmailLinkSignInRequest.h"
#import "FIRFederatedAuthProvider.h"
#import "FIRGameCenterAuthCredential.h"
#import "FIRGetAccountInfoRequest.h"
#import "FIRGetAccountInfoResponse.h"
Expand Down Expand Up @@ -791,6 +792,21 @@ - (void)reauthenticateAndRetrieveDataWithCredential:(FIRAuthCredential *) creden
});
}

- (void)reauthenticateWithProvider:(id<FIRFederatedAuthProvider>)provider
UIDelegate:(nullable id<FIRAuthUIDelegate>)UIDelegate
completion:(nullable FIRAuthDataResultCallback)completion {
#if TARGET_OS_IOS
dispatch_async(FIRAuthGlobalWorkQueue(), ^{
[provider getCredentialWithUIDelegate:UIDelegate
completion:^(FIRAuthCredential *_Nullable credential,
NSError *_Nullable error) {
[self reauthenticateWithCredential:credential
completion:completion];
}];
});
#endif // TARGET_OS_IOS
}

- (nullable NSString *)refreshToken {
__block NSString *result;
dispatch_sync(FIRAuthGlobalWorkQueue(), ^{
Expand Down Expand Up @@ -1234,6 +1250,21 @@ - (void)linkAndRetrieveDataWithCredential:(FIRAuthCredential *)credential
});
}

- (void)linkWithProvider:(id<FIRFederatedAuthProvider>)provider
UIDelegate:(nullable id<FIRAuthUIDelegate>)UIDelegate
completion:(nullable FIRAuthDataResultCallback)completion {
#if TARGET_OS_IOS
dispatch_async(FIRAuthGlobalWorkQueue(), ^{
[provider getCredentialWithUIDelegate:UIDelegate
completion:^(FIRAuthCredential *_Nullable credential,
NSError *_Nullable error) {
[self linkWithCredential:credential
completion:completion];
}];
});
#endif // TARGET_OS_IOS
}

- (void)unlinkFromProvider:(NSString *)provider
completion:(nullable FIRAuthResultCallback)completion {
[_taskQueue enqueueTask:^(FIRAuthSerialTaskCompletionBlock _Nonnull complete) {
Expand Down