google_account_access_token_fetch_delegate.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2021 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 WEBLAYER_PUBLIC_GOOGLE_ACCOUNT_ACCESS_TOKEN_FETCH_DELEGATE_H_
  5. #define WEBLAYER_PUBLIC_GOOGLE_ACCOUNT_ACCESS_TOKEN_FETCH_DELEGATE_H_
  6. #include <set>
  7. #include <string>
  8. #include "base/callback_forward.h"
  9. namespace weblayer {
  10. using OnTokenFetchedCallback =
  11. base::OnceCallback<void(const std::string& token)>;
  12. // An interface that allows clients to handle access token requests for Google
  13. // accounts originating in the browser.
  14. class GoogleAccountAccessTokenFetchDelegate {
  15. public:
  16. // Called when the WebLayer implementation wants to fetch an access token for
  17. // the embedder's current GAIA account (if any) and the given scopes. The
  18. // client should invoke |onTokenFetchedCallback| when its internal token fetch
  19. // is complete, passing either the fetched access token or the empty string in
  20. // the case of failure (e.g., if there is no current GAIA account or there was
  21. // an error in the token fetch).
  22. //
  23. // NOTE: WebLayer will not perform any caching of the returned token but will
  24. // instead make a new request each time that it needs to use an access token.
  25. // The expectation is that the client will use caching internally to minimize
  26. // latency of these requests.
  27. virtual void FetchAccessToken(const std::set<std::string>& scopes,
  28. OnTokenFetchedCallback callback) = 0;
  29. // Called when a token previously obtained via a call to
  30. // FetchAccessToken(|scopes|) is identified as invalid, so the embedder can
  31. // take appropriate action (e.g., dropping the token from its cache and/or
  32. // force-fetching a new token).
  33. virtual void OnAccessTokenIdentifiedAsInvalid(
  34. const std::set<std::string>& scopes,
  35. const std::string& token) = 0;
  36. protected:
  37. virtual ~GoogleAccountAccessTokenFetchDelegate() {}
  38. };
  39. } // namespace weblayer
  40. #endif // WEBLAYER_PUBLIC_GOOGLE_ACCOUNT_ACCESS_TOKEN_FETCH_DELEGATE_H_