| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_IOS_FACADE_REMOTING_AUTHENTICATION_H_ | 5 #ifndef REMOTING_IOS_FACADE_REMOTING_AUTHENTICATION_H_ |
| 6 #define REMOTING_IOS_FACADE_REMOTING_AUTHENTICATION_H_ | 6 #define REMOTING_IOS_FACADE_REMOTING_AUTHENTICATION_H_ |
| 7 | 7 |
| 8 #import "remoting/client/chromoting_client_runtime.h" | |
| 9 #import "remoting/ios/domain/user_info.h" | 8 #import "remoting/ios/domain/user_info.h" |
| 10 | 9 |
| 11 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 12 #include "remoting/base/oauth_token_getter.h" | 11 |
| 12 typedef NS_ENUM(NSInteger, RemotingAuthenticationStatus) { |
| 13 RemotingAuthenticationStatusSuccess, |
| 14 RemotingAuthenticationStatusNetworkError, |
| 15 RemotingAuthenticationStatusAuthError |
| 16 }; |
| 17 |
| 18 typedef void (^AccessTokenCallback)(RemotingAuthenticationStatus status, |
| 19 NSString* userEmail, |
| 20 NSString* accessToken); |
| 13 | 21 |
| 14 // |RemotingAuthenticationDelegate|s are interested in authentication related | 22 // |RemotingAuthenticationDelegate|s are interested in authentication related |
| 15 // notifications. | 23 // notifications. |
| 16 @protocol RemotingAuthenticationDelegate<NSObject> | 24 @protocol RemotingAuthenticationDelegate<NSObject> |
| 17 | 25 |
| 18 // Notifies the delegate that the user has been updated. | 26 // Notifies the delegate that the user has been updated. |
| 19 - (void)userDidUpdate:(UserInfo*)user; | 27 - (void)userDidUpdate:(UserInfo*)user; |
| 20 | 28 |
| 21 @end | 29 @end |
| 22 | 30 |
| 23 // This is the class that will manage the details around authentication | 31 // This is the interface that will manage the details around authentication |
| 24 // management and currently active user. It will make sure the user object is | 32 // management and currently active user. It will make sure the user object is |
| 25 // saved to the keychain correctly and loaded on startup. It also is the entry | 33 // saved to the keychain correctly and loaded on startup. It also is the entry |
| 26 // point for gaining access to an auth token for authrized calls. | 34 // point for gaining access to an auth token for authrized calls. |
| 27 @interface RemotingAuthentication : NSObject | 35 @protocol RemotingAuthentication<NSObject> |
| 28 | 36 |
| 29 // Provide an |authorizationCode| to authenticate a user as the first time user | 37 // Fetches an Access Token and passes it back to the callback if the user is |
| 30 // of the application or OAuth Flow. | 38 // authenticated. Otherwise does nothing. |
| 31 - (void)authenticateWithAuthorizationCode:(NSString*)authorizationCode; | |
| 32 | |
| 33 // Fetches an OAuth Access Token and passes it back to the callback if | |
| 34 // the user is authenticated. Otherwise does nothing. | |
| 35 // TODO(nicholss): We might want to throw an error or add error message to | 39 // TODO(nicholss): We might want to throw an error or add error message to |
| 36 // the callback sig to be able to react to the un-authed case. | 40 // the callback sig to be able to react to the un-authed case. |
| 37 - (void)callbackWithAccessToken: | 41 - (void)callbackWithAccessToken:(AccessTokenCallback)onAccessToken; |
| 38 (const remoting::OAuthTokenGetter::TokenCallback&)onAccessToken; | |
| 39 | 42 |
| 40 // Forget the current user. | 43 // Forget the current user. |
| 41 - (void)logout; | 44 - (void)logout; |
| 42 | 45 |
| 43 // Returns the currently logged in user or nil. | 46 // Returns the currently logged in user or nil. |
| 44 @property(strong, nonatomic) UserInfo* user; | 47 @property(strong, nonatomic, readonly) UserInfo* user; |
| 45 | 48 |
| 46 // Delegate recieves updates on user changes. | 49 // Delegate recieves updates on user changes. |
| 47 @property(weak, nonatomic) id<RemotingAuthenticationDelegate> delegate; | 50 @property(weak, nonatomic) id<RemotingAuthenticationDelegate> delegate; |
| 48 | 51 |
| 49 @end | 52 @end |
| 50 | 53 |
| 51 #endif // REMOTING_IOS_FACADE_REMOTING_AUTHENTICATION_H_ | 54 #endif // REMOTING_IOS_FACADE_REMOTING_AUTHENTICATION_H_ |
| OLD | NEW |