Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Side by Side Diff: google_apis/gaia/gaia_oauth_client.h

Issue 17109006: Device robot refresh token integrity validation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Extend device_oauth2_token_service_unittest.cc to cover refresh token validation cases. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 GOOGLE_APIS_GAIA_GAIA_OAUTH_CLIENT_H_ 5 #ifndef GOOGLE_APIS_GAIA_GAIA_OAUTH_CLIENT_H_
6 #define GOOGLE_APIS_GAIA_GAIA_OAUTH_CLIENT_H_ 6 #define GOOGLE_APIS_GAIA_GAIA_OAUTH_CLIENT_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector>
9 10
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop_proxy.h" 13 #include "base/message_loop_proxy.h"
14 #include "base/values.h"
12 15
13 namespace net { 16 namespace net {
14 class URLRequestContextGetter; 17 class URLRequestContextGetter;
15 } 18 }
16 19
17 // A helper class to get and refresh OAuth tokens given an authorization code. 20 // A helper class to get and refresh OAuth tokens given an authorization code.
21 // Also exposes utility methods for fetching user email and token owner.
22 // Supports one request at a time; for parallel requests, create multiple
23 // instances.
18 namespace gaia { 24 namespace gaia {
19 25
20 struct OAuthClientInfo { 26 struct OAuthClientInfo {
21 std::string client_id; 27 std::string client_id;
22 std::string client_secret; 28 std::string client_secret;
23 std::string redirect_uri; 29 std::string redirect_uri;
24 }; 30 };
25 31
26 class GaiaOAuthClient { 32 class GaiaOAuthClient {
27 public: 33 public:
28 class Delegate { 34 class Delegate {
29 public: 35 public:
30 // Invoked on a successful response to the GetTokensFromAuthCode request. 36 // Invoked on a successful response to the GetTokensFromAuthCode request.
31 virtual void OnGetTokensResponse(const std::string& refresh_token, 37 virtual void OnGetTokensResponse(const std::string& refresh_token,
32 const std::string& access_token, 38 const std::string& access_token,
33 int expires_in_seconds) = 0; 39 int expires_in_seconds) {};
34 // Invoked on a successful response to the RefreshToken request. 40 // Invoked on a successful response to the RefreshToken request.
35 virtual void OnRefreshTokenResponse(const std::string& access_token, 41 virtual void OnRefreshTokenResponse(const std::string& access_token,
36 int expires_in_seconds) = 0; 42 int expires_in_seconds) {};
37 // Invoked on a successful response to the GetUserInfo request. 43 // Invoked on a successful response to the GetUserInfo request.
38 virtual void OnGetUserInfoResponse(const std::string& user_email) {}; 44 virtual void OnGetUserInfoResponse(const std::string& user_email) {};
45 // Invoked on a successful response to the GetTokenInfo request.
46 virtual void OnGetTokenInfoResponse(
47 scoped_ptr<DictionaryValue> token_info) {};
39 // Invoked when there is an OAuth error with one of the requests. 48 // Invoked when there is an OAuth error with one of the requests.
40 virtual void OnOAuthError() = 0; 49 virtual void OnOAuthError() = 0;
41 // Invoked when there is a network error or upon receiving an invalid 50 // Invoked when there is a network error or upon receiving an invalid
42 // response. This is invoked when the maximum number of retries have been 51 // response. This is invoked when the maximum number of retries have been
43 // exhausted. If max_retries is -1, this is never invoked. 52 // exhausted. If max_retries is -1, this is never invoked.
44 virtual void OnNetworkError(int response_code) = 0; 53 virtual void OnNetworkError(int response_code) = 0;
45 54
46 protected: 55 protected:
47 virtual ~Delegate() {} 56 virtual ~Delegate() {}
48 }; 57 };
49 GaiaOAuthClient(const std::string& gaia_url, 58
50 net::URLRequestContextGetter* context_getter); 59 GaiaOAuthClient(net::URLRequestContextGetter* context_getter);
51 ~GaiaOAuthClient(); 60 ~GaiaOAuthClient();
52 61
53 // In the below methods, |max_retries| specifies the maximum number of times 62 // In the below methods, |max_retries| specifies the maximum number of times
54 // we should retry on a network error in invalid response. This does not 63 // we should retry on a network error in invalid response. This does not
55 // apply in the case of an OAuth error (i.e. there was something wrong with 64 // apply in the case of an OAuth error (i.e. there was something wrong with
56 // the input arguments). Setting |max_retries| to -1 implies infinite retries. 65 // the input arguments). Setting |max_retries| to -1 implies infinite retries.
57 void GetTokensFromAuthCode(const OAuthClientInfo& oauth_client_info, 66 void GetTokensFromAuthCode(const OAuthClientInfo& oauth_client_info,
58 const std::string& auth_code, 67 const std::string& auth_code,
59 int max_retries, 68 int max_retries,
60 Delegate* delegate); 69 Delegate* delegate);
61 void RefreshToken(const OAuthClientInfo& oauth_client_info, 70 void RefreshToken(const OAuthClientInfo& oauth_client_info,
62 const std::string& refresh_token, 71 const std::string& refresh_token,
72 const std::vector<std::string>& scopes,
63 int max_retries, 73 int max_retries,
64 Delegate* delegate); 74 Delegate* delegate);
65 void GetUserInfo(const std::string& oauth_access_token, 75 void GetUserInfo(const std::string& oauth_access_token,
66 int max_retries, 76 int max_retries,
67 Delegate* delegate); 77 Delegate* delegate);
78 void GetTokenInfo(const std::string& oauth_access_token,
79 int max_retries,
80 Delegate* delegate);
68 81
69 private: 82 private:
70 // The guts of the implementation live in this class. 83 // The guts of the implementation live in this class.
71 class Core; 84 class Core;
72 scoped_refptr<Core> core_; 85 scoped_refptr<Core> core_;
73 DISALLOW_COPY_AND_ASSIGN(GaiaOAuthClient); 86 DISALLOW_COPY_AND_ASSIGN(GaiaOAuthClient);
74 }; 87 };
75 } 88 }
76 89
77 #endif // GOOGLE_APIS_GAIA_GAIA_OAUTH_CLIENT_H_ 90 #endif // GOOGLE_APIS_GAIA_GAIA_OAUTH_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698