Commit 9e6de2fd authored by Scott Nichols's avatar Scott Nichols Committed by Commit Bot

Adding error reporting and feedback for unhappy path SSO.

Change-Id: I84cc5a2fb6b09daa12fe4560664773cfaf635d54
Reviewed-on: https://chromium-review.googlesource.com/569078Reviewed-by: default avatarYuwei Huang <yuweih@chromium.org>
Commit-Queue: Scott Nichols <nicholss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486193}
parent 78e80591
...@@ -59,11 +59,15 @@ static const CGFloat kKeyboardAnimationTime = 0.3; ...@@ -59,11 +59,15 @@ static const CGFloat kKeyboardAnimationTime = 0.3;
SessionErrorCode _lastError; SessionErrorCode _lastError;
HostInfo* _hostInfo; HostInfo* _hostInfo;
} }
@property(nonatomic, assign) SessionErrorCode lastError;
@end @end
@implementation ClientConnectionViewController @implementation ClientConnectionViewController
@synthesize state = _state; @synthesize state = _state;
@synthesize lastError = _lastError;
- (instancetype)initWithHostInfo:(HostInfo*)hostInfo { - (instancetype)initWithHostInfo:(HostInfo*)hostInfo {
self = [super init]; self = [super init];
...@@ -374,16 +378,24 @@ static const CGFloat kKeyboardAnimationTime = 0.3; ...@@ -374,16 +378,24 @@ static const CGFloat kKeyboardAnimationTime = 0.3;
- (void)attemptConnectionToHost { - (void)attemptConnectionToHost {
_client = [[RemotingClient alloc] init]; _client = [[RemotingClient alloc] init];
__weak ClientConnectionViewController* weakSelf = self;
__weak RemotingClient* weakClient = _client; __weak RemotingClient* weakClient = _client;
__weak HostInfo* weakHostInfo = _hostInfo; __weak HostInfo* weakHostInfo = _hostInfo;
[RemotingService.instance.authentication [RemotingService.instance.authentication
callbackWithAccessToken:^(RemotingAuthenticationStatus status, callbackWithAccessToken:^(RemotingAuthenticationStatus status,
NSString* userEmail, NSString* accessToken) { NSString* userEmail, NSString* accessToken) {
if (status == RemotingAuthenticationStatusSuccess) {
[weakClient connectToHost:weakHostInfo [weakClient connectToHost:weakHostInfo
username:userEmail username:userEmail
accessToken:accessToken]; accessToken:accessToken];
} else {
LOG(ERROR) << "Failed to fetch access token for connectToHost. ("
<< status << ")";
weakSelf.lastError = SessionErrorOAuthTokenInvalid;
weakSelf.state = ClientViewError;
}
}]; }];
[self setState:ClientViewConnecting]; self.state = ClientViewConnecting;
} }
- (void)showConnectingState { - (void)showConnectingState {
...@@ -524,6 +536,11 @@ static const CGFloat kKeyboardAnimationTime = 0.3; ...@@ -524,6 +536,11 @@ static const CGFloat kKeyboardAnimationTime = 0.3;
message = [MDCSnackbarMessage message = [MDCSnackbarMessage
messageWithText:@"Error: SessionErrorUnknownError."]; messageWithText:@"Error: SessionErrorUnknownError."];
break; break;
case SessionErrorOAuthTokenInvalid:
message = [MDCSnackbarMessage
messageWithText:
@"Error: SessionErrorOAuthTokenInvalid. Please login again."];
break;
} }
if (message.text) { if (message.text) {
[MDCSnackbarManager showMessage:message]; [MDCSnackbarManager showMessage:message];
...@@ -586,7 +603,7 @@ static const CGFloat kKeyboardAnimationTime = 0.3; ...@@ -586,7 +603,7 @@ static const CGFloat kKeyboardAnimationTime = 0.3;
} }
_lastError = sessionDetails.error; _lastError = sessionDetails.error;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self setState:state]; self.state = state;
}]; }];
} }
......
...@@ -38,6 +38,7 @@ typedef NS_ENUM(NSInteger, SessionErrorCode) { ...@@ -38,6 +38,7 @@ typedef NS_ENUM(NSInteger, SessionErrorCode) {
SessionErrorMaxSessionLength, SessionErrorMaxSessionLength,
SessionErrorHostConfigurationError, SessionErrorHostConfigurationError,
SessionErrorUnknownError, SessionErrorUnknownError,
SessionErrorOAuthTokenInvalid, // Custom for app.
}; };
// The current state of a session and data needed for session context. // The current state of a session and data needed for session context.
......
...@@ -128,7 +128,8 @@ void HostListFetcher::OnURLFetchComplete(const net::URLFetcher* source) { ...@@ -128,7 +128,8 @@ void HostListFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
hostlist.clear(); hostlist.clear();
} }
std::sort(hostlist.begin(), hostlist.end(), &compareHost); std::sort(hostlist.begin(), hostlist.end(), &compareHost);
base::ResetAndReturn(&hostlist_callback_).Run(hostlist); base::ResetAndReturn(&hostlist_callback_)
.Run(request_->GetResponseCode(), hostlist);
} }
} // namespace remoting } // namespace remoting
...@@ -38,7 +38,8 @@ class HostListFetcher : public net::URLFetcherDelegate { ...@@ -38,7 +38,8 @@ class HostListFetcher : public net::URLFetcherDelegate {
// Supplied by the client for each hostlist request and returns a valid, // Supplied by the client for each hostlist request and returns a valid,
// initialized Hostlist object on success. // initialized Hostlist object on success.
typedef base::Callback<void(const std::vector<remoting::HostInfo>& hostlist)> typedef base::Callback<void(int response_code,
const std::vector<remoting::HostInfo>& hostlist)>
HostlistCallback; HostlistCallback;
// Makes a service call to retrieve a hostlist. The // Makes a service call to retrieve a hostlist. The
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#import <Security/Security.h> #import <Security/Security.h>
#import "base/mac/bind_objc_block.h" #import "base/mac/bind_objc_block.h"
#import "ios/third_party/material_components_ios/src/components/Snackbar/src/MaterialSnackbar.h"
#import "remoting/ios/facade/host_info.h" #import "remoting/ios/facade/host_info.h"
#import "remoting/ios/facade/host_list_fetcher.h" #import "remoting/ios/facade/host_list_fetcher.h"
#import "remoting/ios/facade/ios_client_runtime_delegate.h" #import "remoting/ios/facade/ios_client_runtime_delegate.h"
...@@ -142,7 +143,10 @@ RemotingAuthenticationStatus oauthStatusToRemotingAuthenticationStatus( ...@@ -142,7 +143,10 @@ RemotingAuthenticationStatus oauthStatusToRemotingAuthenticationStatus(
} else { } else {
LOG(ERROR) << "Failed to fetch access token from authorization code. (" LOG(ERROR) << "Failed to fetch access token from authorization code. ("
<< status << ")"; << status << ")";
// TODO(nicholss): Deal with the sad path for a bad auth token. [MDCSnackbarManager
showMessage:
[MDCSnackbarMessage
messageWithText:@"Authentication Failed. Please try again."]];
} }
}]; }];
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#import <Security/Security.h> #import <Security/Security.h>
#import "base/mac/bind_objc_block.h" #import "base/mac/bind_objc_block.h"
#import "ios/third_party/material_components_ios/src/components/Snackbar/src/MaterialSnackbar.h"
#import "remoting/ios/domain/host_info.h" #import "remoting/ios/domain/host_info.h"
#import "remoting/ios/domain/user_info.h" #import "remoting/ios/domain/user_info.h"
#import "remoting/ios/facade/host_info.h" #import "remoting/ios/facade/host_info.h"
...@@ -23,6 +24,7 @@ ...@@ -23,6 +24,7 @@
#include "base/i18n/time_formatting.h" #include "base/i18n/time_formatting.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "net/http/http_status_code.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
#include "remoting/base/oauth_token_getter.h" #include "remoting/base/oauth_token_getter.h"
#include "remoting/base/oauth_token_getter_impl.h" #include "remoting/base/oauth_token_getter_impl.h"
...@@ -85,7 +87,15 @@ NSString* const kUserInfo = @"kUserInfo"; ...@@ -85,7 +87,15 @@ NSString* const kUserInfo = @"kUserInfo";
} }
_hostListFetcher->RetrieveHostlist( _hostListFetcher->RetrieveHostlist(
base::SysNSStringToUTF8(accessToken), base::SysNSStringToUTF8(accessToken),
base::BindBlockArc(^(const std::vector<remoting::HostInfo>& hostlist) { base::BindBlockArc(^(int responseCode,
const std::vector<remoting::HostInfo>& hostlist) {
if (responseCode == net::HTTP_UNAUTHORIZED) {
[[RemotingService instance].authentication logout];
}
// TODO(nicholss): There are more |responseCode|s that we might want to
// trigger on, look into that later.
NSMutableArray<HostInfo*>* hosts = NSMutableArray<HostInfo*>* hosts =
[NSMutableArray arrayWithCapacity:hostlist.size()]; [NSMutableArray arrayWithCapacity:hostlist.size()];
std::string status; std::string status;
...@@ -173,14 +183,17 @@ NSString* const kUserInfo = @"kUserInfo"; ...@@ -173,14 +183,17 @@ NSString* const kUserInfo = @"kUserInfo";
[self startHostListFetchWith:accessToken]; [self startHostListFetchWith:accessToken];
break; break;
case RemotingAuthenticationStatusNetworkError: case RemotingAuthenticationStatusNetworkError:
NSLog( [MDCSnackbarManager
@"TODO(nicholss): implement this, " showMessage:
@"RemotingAuthenticationStatusNetworkError."); [MDCSnackbarMessage
messageWithText:@"[Network Error] Please try again."]];
break; break;
case RemotingAuthenticationStatusAuthError: case RemotingAuthenticationStatusAuthError:
NSLog( [MDCSnackbarManager
@"TODO(nicholss): implement this, " showMessage:
@"RemotingAuthenticationStatusAuthError."); [MDCSnackbarMessage
messageWithText:
@"[Authentication Failed] Please login again."]];
break; break;
} }
}]; }];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment