gaia_auth_consumer.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Copyright (c) 2012 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 GOOGLE_APIS_GAIA_GAIA_AUTH_CONSUMER_H_
  5. #define GOOGLE_APIS_GAIA_GAIA_AUTH_CONSUMER_H_
  6. #include <map>
  7. #include <string>
  8. #include <vector>
  9. class GoogleServiceAuthError;
  10. class OAuthMultiloginResult;
  11. // An interface that defines the callbacks for objects that
  12. // GaiaAuthFetcher can return data to.
  13. class GaiaAuthConsumer {
  14. public:
  15. struct ClientLoginResult {
  16. ClientLoginResult();
  17. ClientLoginResult(const std::string& new_sid,
  18. const std::string& new_lsid,
  19. const std::string& new_token,
  20. const std::string& new_data);
  21. ClientLoginResult(const ClientLoginResult& other);
  22. ~ClientLoginResult();
  23. bool operator==(const ClientLoginResult &b) const;
  24. std::string sid;
  25. std::string lsid;
  26. std::string token;
  27. // TODO(chron): Remove the data field later. Don't use it if possible.
  28. std::string data; // Full contents of ClientLogin return.
  29. };
  30. struct ClientOAuthResult {
  31. ClientOAuthResult(const std::string& new_refresh_token,
  32. const std::string& new_access_token,
  33. int new_expires_in_secs,
  34. bool is_child_account,
  35. bool is_under_advanced_protection);
  36. ClientOAuthResult(const ClientOAuthResult& other);
  37. ~ClientOAuthResult();
  38. bool operator==(const ClientOAuthResult &b) const;
  39. // OAuth2 refresh token. Used to mint new access tokens when needed.
  40. std::string refresh_token;
  41. // OAuth2 access token. Token to pass to endpoints that require oauth2
  42. // authentication.
  43. std::string access_token;
  44. // The lifespan of |access_token| in seconds.
  45. int expires_in_secs;
  46. // Whether the authenticated user is a child account.
  47. bool is_child_account;
  48. // Whether the authenticated user is in advanced protection program.
  49. bool is_under_advanced_protection;
  50. };
  51. // Possible server responses to a token revocation request.
  52. enum class TokenRevocationStatus {
  53. // Token revocation succeeded.
  54. kSuccess,
  55. // Network connection was canceled, no response was received.
  56. kConnectionCanceled,
  57. // Network connection failed, no response was received.
  58. kConnectionFailed,
  59. // Network connection timed out, no response was received.
  60. kConnectionTimeout,
  61. // The token is unknown or invalid.
  62. kInvalidToken,
  63. // The request was malformed.
  64. kInvalidRequest,
  65. // Internal server error.
  66. kServerError,
  67. // Other error.
  68. kUnknownError,
  69. };
  70. enum class ReAuthProofTokenStatus : int {
  71. // Successful request: used only to control FakeGaia response.
  72. kSuccess = 0,
  73. // Request had invalid format.
  74. kInvalidRequest = 1,
  75. // Password was incorrect.
  76. kInvalidGrant = 2,
  77. // Unauthorized OAuth client.
  78. kUnauthorizedClient = 3,
  79. // Scope of OAuth token was insufficient.
  80. kInsufficientScope = 4,
  81. // No credential specified.
  82. kCredentialNotSet = 5,
  83. // A network error.
  84. kNetworkError = 6,
  85. // Other error.
  86. kUnknownError = 7
  87. };
  88. virtual ~GaiaAuthConsumer() {}
  89. virtual void OnClientLoginSuccess(const ClientLoginResult& result) {}
  90. virtual void OnClientLoginFailure(const GoogleServiceAuthError& error) {}
  91. virtual void OnClientOAuthCode(const std::string& auth_code) {}
  92. virtual void OnClientOAuthSuccess(const ClientOAuthResult& result) {}
  93. virtual void OnClientOAuthFailure(const GoogleServiceAuthError& error) {}
  94. virtual void OnOAuth2RevokeTokenCompleted(TokenRevocationStatus status) {}
  95. virtual void OnUberAuthTokenSuccess(const std::string& token) {}
  96. virtual void OnUberAuthTokenFailure(const GoogleServiceAuthError& error) {}
  97. virtual void OnMergeSessionSuccess(const std::string& data) {}
  98. virtual void OnMergeSessionFailure(const GoogleServiceAuthError& error) {}
  99. virtual void OnListAccountsSuccess(const std::string& data) {}
  100. virtual void OnListAccountsFailure(const GoogleServiceAuthError& error) {}
  101. virtual void OnOAuthMultiloginFinished(const OAuthMultiloginResult& result) {}
  102. virtual void OnLogOutSuccess() {}
  103. virtual void OnLogOutFailure(const GoogleServiceAuthError& error) {}
  104. virtual void OnGetCheckConnectionInfoSuccess(const std::string& data) {}
  105. virtual void OnGetCheckConnectionInfoError(
  106. const GoogleServiceAuthError& error) {}
  107. virtual void OnReAuthProofTokenSuccess(
  108. const std::string& reauth_proof_token) {}
  109. virtual void OnReAuthProofTokenFailure(const ReAuthProofTokenStatus error) {}
  110. };
  111. #endif // GOOGLE_APIS_GAIA_GAIA_AUTH_CONSUMER_H_