-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Feature/7675 social login service call #7872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
863a27f
da40ded
f82c550
a5f0bb8
44d8f1e
f6f81a9
3f2f53d
54645b5
2e7efac
ad0ae95
778ed5d
75b05bf
e54c0f9
511086c
449d94c
89c5cc8
acbf134
d93c956
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import Foundation | ||
| import WordPressComKit | ||
|
|
||
| extension AccountService { | ||
|
|
||
| /// Connect an account a social service via an ID token. | ||
| /// | ||
| /// - Parameters: | ||
| /// - service The name of the social service. | ||
| /// - token The service's OpenID Connect (JWT) ID token for the user. | ||
| /// - success | ||
| /// - failure | ||
| func connectToSocialService(_ service: SocialServiceName, serviceIDToken token:String, success:@escaping (() -> Void), failure:@escaping ((NSError) -> Void)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Colon Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. (colon) |
||
| guard let api = defaultWordPressComAccount()?.wordPressComRestApi, | ||
| let remote = AccountServiceRemoteREST(wordPressComRestApi: api) else { | ||
| fatalError("Failed to initialize a valid remote via the default WordPress.com account.") | ||
| } | ||
| remote.connectToSocialService(service, serviceIDToken: token, success: success, failure: failure) | ||
| } | ||
|
|
||
| /// Disconnect an account a social service via an ID token. | ||
| /// - Parameters: | ||
| /// - service The name of the social service. | ||
| /// - success | ||
| /// - failure | ||
| func disconnectFromSocialService(_ service: SocialServiceName, success:@escaping (() -> Void), failure:@escaping ((NSError) -> Void)) { | ||
| guard let api = defaultWordPressComAccount()?.wordPressComRestApi, | ||
| let remote = AccountServiceRemoteREST(wordPressComRestApi: api) else { | ||
| fatalError("Failed to initialize a valid remote via the default WordPress.com account.") | ||
| } | ||
| remote.disconnectFromSocialService(service, success: success, failure: failure) | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,6 @@ - (void)signInWithLoginFields:(LoginFields *)loginFields | |
| } | ||
| } | ||
|
|
||
|
|
||
| - (void)loginWithLoginFields:(LoginFields *)loginFields | ||
| { | ||
| NSAssert(self.delegate != nil, @"Must set delegate to use service"); | ||
|
|
@@ -52,7 +51,6 @@ - (void)loginWithLoginFields:(LoginFields *)loginFields | |
| } | ||
| } | ||
|
|
||
|
|
||
| - (void)requestOneTimeCodeWithLoginFields:(LoginFields *)loginFields | ||
| { | ||
| [self.wordpressComOAuthClientFacade requestOneTimeCodeWithUsername:loginFields.username password:loginFields.password success:^{ | ||
|
|
@@ -62,6 +60,28 @@ - (void)requestOneTimeCodeWithLoginFields:(LoginFields *)loginFields | |
| }]; | ||
| } | ||
|
|
||
| - (void)loginToWordPressDotComWithGoogleIDToken:(NSString *)googleIDToken | ||
| { | ||
| if ([self.delegate respondsToSelector:@selector(displayLoginMessage:)]) { | ||
| [self.delegate displayLoginMessage:NSLocalizedString(@"Connecting to WordPress.com", nil)]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know we already do this in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not too much of a fan either. I still have the dream of nuking the facade completely, but until then I think we should be consistent. |
||
| } | ||
|
|
||
| [self.wordpressComOAuthClientFacade authenticateWithGoogleIDToken:googleIDToken success:^(NSString *authToken) { | ||
| if ([self.delegate respondsToSelector:@selector(finishedLoginWithGoogleIDToken:authToken:)]) { | ||
| [self.delegate finishedLoginWithGoogleIDToken:googleIDToken authToken:authToken]; | ||
| } | ||
| } needsMultiFactor:^(NSInteger userID, SocialLogin2FANonceInfo *nonceInfo){ | ||
| if ([self.delegate respondsToSelector:@selector(needsMultifactorCodeForUserID:andNonceInfo:)]) { | ||
| [self.delegate needsMultifactorCodeForUserID:userID andNonceInfo:nonceInfo]; | ||
| } | ||
| } failure:^(NSError *error) { | ||
| [WPAppAnalytics track:WPAnalyticsStatLoginFailed error:error]; | ||
| if ([self.delegate respondsToSelector:@selector(displayRemoteError:)]) { | ||
| [self.delegate displayRemoteError:error]; | ||
| } | ||
| }]; | ||
| } | ||
|
|
||
| - (void)signInToWordpressDotCom:(LoginFields *)loginFields | ||
| { | ||
| if ([self.delegate respondsToSelector:@selector(displayLoginMessage:)]) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this.