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;
SessionErrorCode _lastError;
HostInfo* _hostInfo;
}
@property(nonatomic, assign) SessionErrorCode lastError;
@end
@implementation ClientConnectionViewController
@synthesize state = _state;
@synthesize lastError = _lastError;
- (instancetype)initWithHostInfo:(HostInfo*)hostInfo {
self = [super init];
......@@ -374,16 +378,24 @@ static const CGFloat kKeyboardAnimationTime = 0.3;
- (void)attemptConnectionToHost {
_client = [[RemotingClient alloc] init];
__weak ClientConnectionViewController* weakSelf = self;
__weak RemotingClient* weakClient = _client;
__weak HostInfo* weakHostInfo = _hostInfo;
[RemotingService.instance.authentication
callbackWithAccessToken:^(RemotingAuthenticationStatus status,
NSString* userEmail, NSString* accessToken) {
if (status == RemotingAuthenticationStatusSuccess) {
[weakClient connectToHost:weakHostInfo
username:userEmail
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 {
......@@ -524,6 +536,11 @@ static const CGFloat kKeyboardAnimationTime = 0.3;
message = [MDCSnackbarMessage
messageWithText:@"Error: SessionErrorUnknownError."];
break;
case SessionErrorOAuthTokenInvalid:
message = [MDCSnackbarMessage
messageWithText:
@"Error: SessionErrorOAuthTokenInvalid. Please login again."];
break;
}
if (message.text) {
[MDCSnackbarManager showMessage:message];
......@@ -586,7 +603,7 @@ static const CGFloat kKeyboardAnimationTime = 0.3;
}
_lastError = sessionDetails.error;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self setState:state];
self.state = state;
}];
}
......
......@@ -38,6 +38,7 @@ typedef NS_ENUM(NSInteger, SessionErrorCode) {
SessionErrorMaxSessionLength,
SessionErrorHostConfigurationError,
SessionErrorUnknownError,
SessionErrorOAuthTokenInvalid, // Custom for app.
};
// The current state of a session and data needed for session context.
......
......@@ -128,7 +128,8 @@ void HostListFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
hostlist.clear();
}
std::sort(hostlist.begin(), hostlist.end(), &compareHost);
base::ResetAndReturn(&hostlist_callback_).Run(hostlist);
base::ResetAndReturn(&hostlist_callback_)
.Run(request_->GetResponseCode(), hostlist);
}
} // namespace remoting
......@@ -38,7 +38,8 @@ class HostListFetcher : public net::URLFetcherDelegate {
// Supplied by the client for each hostlist request and returns a valid,
// 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;
// Makes a service call to retrieve a hostlist. The
......
......@@ -12,6 +12,7 @@
#import <Security/Security.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_list_fetcher.h"
#import "remoting/ios/facade/ios_client_runtime_delegate.h"
......@@ -142,7 +143,10 @@ RemotingAuthenticationStatus oauthStatusToRemotingAuthenticationStatus(
} else {
LOG(ERROR) << "Failed to fetch access token from authorization code. ("
<< 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 @@
#import <Security/Security.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/user_info.h"
#import "remoting/ios/facade/host_info.h"
......@@ -23,6 +24,7 @@
#include "base/i18n/time_formatting.h"
#include "base/logging.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 "remoting/base/oauth_token_getter.h"
#include "remoting/base/oauth_token_getter_impl.h"
......@@ -85,7 +87,15 @@ NSString* const kUserInfo = @"kUserInfo";
}
_hostListFetcher->RetrieveHostlist(
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 arrayWithCapacity:hostlist.size()];
std::string status;
......@@ -173,14 +183,17 @@ NSString* const kUserInfo = @"kUserInfo";
[self startHostListFetchWith:accessToken];
break;
case RemotingAuthenticationStatusNetworkError:
NSLog(
@"TODO(nicholss): implement this, "
@"RemotingAuthenticationStatusNetworkError.");
[MDCSnackbarManager
showMessage:
[MDCSnackbarMessage
messageWithText:@"[Network Error] Please try again."]];
break;
case RemotingAuthenticationStatusAuthError:
NSLog(
@"TODO(nicholss): implement this, "
@"RemotingAuthenticationStatusAuthError.");
[MDCSnackbarManager
showMessage:
[MDCSnackbarMessage
messageWithText:
@"[Authentication Failed] Please login again."]];
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