| Index: remoting/ios/facade/remoting_oauth_authentication.mm
|
| diff --git a/remoting/ios/facade/remoting_authentication.mm b/remoting/ios/facade/remoting_oauth_authentication.mm
|
| similarity index 77%
|
| rename from remoting/ios/facade/remoting_authentication.mm
|
| rename to remoting/ios/facade/remoting_oauth_authentication.mm
|
| index 9327511208ebabe46a9b367314b797e8c8f8084a..91648c0d2c85c05b3ee0a3da5c6e5a45a7c49c40 100644
|
| --- a/remoting/ios/facade/remoting_authentication.mm
|
| +++ b/remoting/ios/facade/remoting_oauth_authentication.mm
|
| @@ -6,7 +6,7 @@
|
| #error "This file requires ARC support."
|
| #endif
|
|
|
| -#import "remoting/ios/facade/remoting_authentication.h"
|
| +#import "remoting/ios/facade/remoting_oauth_authentication.h"
|
|
|
| #import <Foundation/Foundation.h>
|
| #import <Security/Security.h>
|
| @@ -66,14 +66,26 @@ std::unique_ptr<remoting::OAuthTokenGetter> CreateOAuthTokenWithRefreshToken(
|
| return oauth_tokenGetter;
|
| }
|
|
|
| -@interface RemotingAuthentication () {
|
| +RemotingAuthenticationStatus oauthStatusToRemotingAuthenticationStatus(
|
| + remoting::OAuthTokenGetter::Status status) {
|
| + switch (status) {
|
| + case remoting::OAuthTokenGetter::Status::AUTH_ERROR:
|
| + return RemotingAuthenticationStatusAuthError;
|
| + case remoting::OAuthTokenGetter::Status::NETWORK_ERROR:
|
| + return RemotingAuthenticationStatusNetworkError;
|
| + case remoting::OAuthTokenGetter::Status::SUCCESS:
|
| + return RemotingAuthenticationStatusSuccess;
|
| + }
|
| +}
|
| +
|
| +@interface RemotingOAuthAuthentication () {
|
| std::unique_ptr<remoting::OAuthTokenGetter> _tokenGetter;
|
| KeychainWrapper* _keychainWrapper;
|
| BOOL _firstLoadUserAttempt;
|
| }
|
| @end
|
|
|
| -@implementation RemotingAuthentication
|
| +@implementation RemotingOAuthAuthentication
|
|
|
| @synthesize user = _user;
|
| @synthesize delegate = _delegate;
|
| @@ -107,7 +119,7 @@ std::unique_ptr<remoting::OAuthTokenGetter> CreateOAuthTokenWithRefreshToken(
|
| #pragma mark - Class Implementation
|
|
|
| - (void)authenticateWithAuthorizationCode:(NSString*)authorizationCode {
|
| - __weak RemotingAuthentication* weakSelf = self;
|
| + __weak RemotingOAuthAuthentication* weakSelf = self;
|
| _tokenGetter = CreateOAuthTokenGetterWithAuthorizationCode(
|
| std::string(base::SysNSStringToUTF8(authorizationCode)),
|
| base::BindBlockArc(
|
| @@ -122,19 +134,17 @@ std::unique_ptr<remoting::OAuthTokenGetter> CreateOAuthTokenWithRefreshToken(
|
| // Stimulate the oAuth Token Getter to fetch and access token, this forces it
|
| // to convert the authorization code into a refresh token, and saving the
|
| // refresh token will happen automaticly in the above block.
|
| - [self callbackWithAccessToken:base::BindBlockArc(^(
|
| - remoting::OAuthTokenGetter::Status status,
|
| - const std::string& user_email,
|
| - const std::string& access_token) {
|
| - if (status == remoting::OAuthTokenGetter::Status::SUCCESS) {
|
| - VLOG(1) << "Success fetching access token from authorization code.";
|
| - } else {
|
| - LOG(ERROR)
|
| - << "Failed to fetch access token from authorization code. ("
|
| - << status << ")";
|
| - // TODO(nicholss): Deal with the sad path for a bad auth token.
|
| - }
|
| - })];
|
| + [self callbackWithAccessToken:^(RemotingAuthenticationStatus status,
|
| + NSString* user_email,
|
| + NSString* access_token) {
|
| + if (status == RemotingAuthenticationStatusSuccess) {
|
| + VLOG(1) << "Success fetching access token from authorization code.";
|
| + } else {
|
| + LOG(ERROR) << "Failed to fetch access token from authorization code. ("
|
| + << status << ")";
|
| + // TODO(nicholss): Deal with the sad path for a bad auth token.
|
| + }
|
| + }];
|
| }
|
|
|
| #pragma mark - Private
|
| @@ -148,12 +158,17 @@ std::unique_ptr<remoting::OAuthTokenGetter> CreateOAuthTokenWithRefreshToken(
|
| base::SysNSStringToUTF8(email));
|
| }
|
|
|
| -- (void)callbackWithAccessToken:
|
| - (const remoting::OAuthTokenGetter::TokenCallback&)onAccessToken {
|
| +- (void)callbackWithAccessToken:(AccessTokenCallback)onAccessToken {
|
| // TODO(nicholss): Be careful here since a failure to reset onAccessToken
|
| // will end up with retain cycle and memory leakage.
|
| if (_tokenGetter) {
|
| - _tokenGetter->CallWithToken(onAccessToken);
|
| + _tokenGetter->CallWithToken(base::BindBlockArc(
|
| + ^(remoting::OAuthTokenGetter::Status status,
|
| + const std::string& user_email, const std::string& access_token) {
|
| + onAccessToken(oauthStatusToRemotingAuthenticationStatus(status),
|
| + base::SysUTF8ToNSString(user_email),
|
| + base::SysUTF8ToNSString(access_token));
|
| + }));
|
| }
|
| }
|
|
|
|
|