OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_HOST_GAIA_OAUTH_CLIENT_H_ | 5 #ifndef REMOTING_HOST_GAIA_OAUTH_CLIENT_H_ |
6 #define REMOTING_HOST_GAIA_OAUTH_CLIENT_H_ | 6 #define REMOTING_HOST_GAIA_OAUTH_CLIENT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 class URLRequestContextGetter; | 14 class URLRequestContextGetter; |
15 } // namespace net | 15 } // namespace net |
16 | 16 |
17 // A helper class to get and refresh OAuth tokens given an authorization code. | 17 // A helper class to get and refresh OAuth tokens given an authorization code. |
18 // | 18 // |
19 // TODO(jamiewalch): This is copied from chrome/common/net to avoid a dependency | 19 // TODO(jamiewalch): This is copied from chrome/common/net to avoid a dependency |
20 // on chrome. It would be better for this class to be moved into net to avoid | 20 // on chrome. It would be better for this class to be moved into net to avoid |
21 // this duplication. | 21 // this duplication. |
22 namespace remoting { | 22 namespace remoting { |
23 | 23 |
24 // TODO(jamiewalch): Make this configurable if we ever support other providers. | |
25 static const char kGaiaOAuth2Url[] = | |
26 "https://accounts.google.com/o/oauth2/token"; | |
27 | |
28 struct OAuthClientInfo { | 24 struct OAuthClientInfo { |
29 std::string client_id; | 25 std::string client_id; |
30 std::string client_secret; | 26 std::string client_secret; |
31 }; | 27 }; |
32 | 28 |
| 29 struct OAuthProviderInfo { |
| 30 static OAuthProviderInfo GetDefault(); |
| 31 |
| 32 std::string access_token_url; |
| 33 std::string user_info_url; |
| 34 }; |
| 35 |
33 class GaiaOAuthClient { | 36 class GaiaOAuthClient { |
34 public: | 37 public: |
35 class Delegate { | 38 class Delegate { |
36 public: | 39 public: |
37 virtual ~Delegate() { } | 40 virtual ~Delegate() { } |
38 | 41 |
39 // Invoked on a successful response to the RefreshToken request. | 42 // Invoked on a successful response to the RefreshToken request. |
40 virtual void OnRefreshTokenResponse(const std::string& access_token, | 43 virtual void OnRefreshTokenResponse(const std::string& user_email, |
| 44 const std::string& access_token, |
41 int expires_in_seconds) = 0; | 45 int expires_in_seconds) = 0; |
42 // Invoked when there is an OAuth error with one of the requests. | 46 // Invoked when there is an OAuth error with one of the requests. |
43 virtual void OnOAuthError() = 0; | 47 virtual void OnOAuthError() = 0; |
44 // Invoked when there is a network error or upon receiving an | 48 // Invoked when there is a network error or upon receiving an |
45 // invalid response. | 49 // invalid response. |
46 virtual void OnNetworkError(int response_code) = 0; | 50 virtual void OnNetworkError(int response_code) = 0; |
47 }; | 51 }; |
48 GaiaOAuthClient(const std::string& gaia_url, | 52 |
| 53 GaiaOAuthClient(const OAuthProviderInfo& provider_info, |
49 net::URLRequestContextGetter* context_getter); | 54 net::URLRequestContextGetter* context_getter); |
50 ~GaiaOAuthClient(); | 55 ~GaiaOAuthClient(); |
51 | 56 |
52 void RefreshToken(const OAuthClientInfo& oauth_client_info, | 57 void RefreshToken(const OAuthClientInfo& oauth_client_info, |
53 const std::string& refresh_token, | 58 const std::string& refresh_token, |
54 Delegate* delegate); | 59 Delegate* delegate); |
55 | 60 |
56 private: | 61 private: |
57 // The guts of the implementation live in this class. | 62 // The guts of the implementation live in this class. |
58 class Core; | 63 class Core; |
59 scoped_refptr<Core> core_; | 64 scoped_refptr<Core> core_; |
60 DISALLOW_COPY_AND_ASSIGN(GaiaOAuthClient); | 65 DISALLOW_COPY_AND_ASSIGN(GaiaOAuthClient); |
61 }; | 66 }; |
62 | 67 |
63 } // namespace remoting | 68 } // namespace remoting |
64 | 69 |
65 #endif // CHROME_COMMON_NET_GAIA_GAIA_OAUTH_CLIENT_H_ | 70 #endif // CHROME_COMMON_NET_GAIA_GAIA_OAUTH_CLIENT_H_ |
OLD | NEW |