remoting_authentication.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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
  3. // found in the LICENSE file.
  4. #ifndef REMOTING_IOS_FACADE_REMOTING_AUTHENTICATION_H_
  5. #define REMOTING_IOS_FACADE_REMOTING_AUTHENTICATION_H_
  6. #import "remoting/ios/domain/user_info.h"
  7. #include "base/memory/weak_ptr.h"
  8. typedef NS_ENUM(NSInteger, RemotingAuthenticationStatus) {
  9. RemotingAuthenticationStatusSuccess,
  10. RemotingAuthenticationStatusNetworkError,
  11. RemotingAuthenticationStatusAuthError
  12. };
  13. typedef void (^AccessTokenCallback)(RemotingAuthenticationStatus status,
  14. NSString* userEmail,
  15. NSString* accessToken);
  16. // |RemotingAuthenticationDelegate|s are interested in authentication related
  17. // notifications.
  18. @protocol RemotingAuthenticationDelegate<NSObject>
  19. // Notifies the delegate that the user has been updated.
  20. - (void)userDidUpdate:(UserInfo*)user;
  21. @end
  22. // This is the interface that will manage the details around authentication
  23. // management and currently active user. It will make sure the user object is
  24. // saved to the keychain correctly and loaded on startup. It also is the entry
  25. // point for gaining access to an auth token for authorized calls.
  26. // TODO(yuweih): Refactor and rewrite this class in C++.
  27. @protocol RemotingAuthentication<NSObject>
  28. // Fetches an Access Token and passes it back to the callback if the user is
  29. // authenticated. Otherwise does nothing.
  30. // TODO(nicholss): We might want to throw an error or add error message to
  31. // the callback sig to be able to react to the un-authed case.
  32. - (void)callbackWithAccessToken:(AccessTokenCallback)onAccessToken;
  33. // Forget the current user.
  34. - (void)logout;
  35. // Invalidates the cached access token.
  36. - (void)invalidateCache;
  37. // Returns the currently logged in user or nil.
  38. @property(strong, nonatomic, readonly) UserInfo* user;
  39. // Delegate receives updates on user changes.
  40. @property(weak, nonatomic) id<RemotingAuthenticationDelegate> delegate;
  41. @end
  42. #endif // REMOTING_IOS_FACADE_REMOTING_AUTHENTICATION_H_