auth_service_interface.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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_COMMON_AUTH_SERVICE_INTERFACE_H_
  5. #define GOOGLE_APIS_COMMON_AUTH_SERVICE_INTERFACE_H_
  6. #include <string>
  7. #include "base/callback.h"
  8. #include "google_apis/common/api_error_codes.h"
  9. namespace google_apis {
  10. class AuthServiceObserver;
  11. // Called when fetching of access token is complete.
  12. typedef base::OnceCallback<void(ApiErrorCode error,
  13. const std::string& access_token)>
  14. AuthStatusCallback;
  15. // This defines an interface for the authentication service which is required
  16. // by authenticated requests (AuthenticatedRequestInterface).
  17. // All functions must be called on UI thread.
  18. class AuthServiceInterface {
  19. public:
  20. virtual ~AuthServiceInterface() {}
  21. // Adds and removes the observer.
  22. virtual void AddObserver(AuthServiceObserver* observer) = 0;
  23. virtual void RemoveObserver(AuthServiceObserver* observer) = 0;
  24. // Starts fetching OAuth2 access token from the refresh token.
  25. // |callback| must not be null.
  26. virtual void StartAuthentication(AuthStatusCallback callback) = 0;
  27. // True if an OAuth2 access token is retrieved and believed to be fresh.
  28. // The access token is used to access the Google API server.
  29. virtual bool HasAccessToken() const = 0;
  30. // True if an OAuth2 refresh token is present. Its absence means that user
  31. // is not properly authenticated.
  32. // The refresh token is used to get the access token.
  33. virtual bool HasRefreshToken() const = 0;
  34. // Returns OAuth2 access token.
  35. virtual const std::string& access_token() const = 0;
  36. // Clears OAuth2 access token.
  37. virtual void ClearAccessToken() = 0;
  38. // Clears OAuth2 refresh token.
  39. virtual void ClearRefreshToken() = 0;
  40. };
  41. } // namespace google_apis
  42. #endif // GOOGLE_APIS_COMMON_AUTH_SERVICE_INTERFACE_H_