OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 | |
5 #ifndef REMOTING_HOST_OAUTH_TOKEN_GETTER_H_ | |
6 #define REMOTING_HOST_OAUTH_TOKEN_GETTER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/macros.h" | |
12 | |
13 namespace remoting { | |
14 | |
15 // OAuthTokenGetter caches OAuth access tokens and refreshes them as needed. | |
16 class OAuthTokenGetter { | |
17 public: | |
18 // Status of the refresh token attempt. | |
19 enum Status { | |
20 // Success, credentials in user_email/access_token. | |
21 SUCCESS, | |
22 // Network failure (caller may retry). | |
23 NETWORK_ERROR, | |
24 // Authentication failure (permanent). | |
25 AUTH_ERROR, | |
26 }; | |
27 | |
28 typedef base::Callback<void(Status status, | |
29 const std::string& user_email, | |
30 const std::string& access_token)> TokenCallback; | |
31 | |
32 // This structure contains information required to perform | |
33 // authentication to OAuth2. | |
34 struct OAuthCredentials { | |
35 // |is_service_account| should be True if the OAuth refresh token is for a | |
36 // service account, False for a user account, to allow the correct client-ID | |
37 // to be used. | |
38 OAuthCredentials(const std::string& login, | |
39 const std::string& refresh_token, | |
40 bool is_service_account); | |
41 | |
42 // The user's account name (i.e. their email address). | |
43 std::string login; | |
44 | |
45 // Token delegating authority to us to act as the user. | |
46 std::string refresh_token; | |
47 | |
48 // Whether these credentials belong to a service account. | |
49 bool is_service_account; | |
50 }; | |
51 | |
52 OAuthTokenGetter() {} | |
53 virtual ~OAuthTokenGetter() {} | |
54 | |
55 // Call |on_access_token| with an access token, or the failure status. | |
56 virtual void CallWithToken( | |
57 const OAuthTokenGetter::TokenCallback& on_access_token) = 0; | |
58 | |
59 // Invalidates the cache, so the next CallWithToken() will get a fresh access | |
60 // token. | |
61 virtual void InvalidateCache() = 0; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(OAuthTokenGetter); | |
64 }; | |
65 | |
66 } // namespace remoting | |
67 | |
68 #endif // REMOTING_HOST_OAUTH_TOKEN_GETTER_H_ | |
OLD | NEW |