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

Side by Side Diff: chrome/common/net/gaia/oauth2_token_mint_fetcher.h

Issue 9549013: Add code to mint OAuth tokens from login-scoped OAuth token. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 CHROME_COMMON_NET_GAIA_OAUTH2_TOKEN_MINT_FETCHER_H_
6 #define CHROME_COMMON_NET_GAIA_OAUTH2_TOKEN_MINT_FETCHER_H_
7 #pragma once
8
9 #include <string>
10 #include <vector>
11
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/common/net/gaia/oauth2_token_mint_consumer.h"
15 #include "content/public/common/url_fetcher.h"
16 #include "content/public/common/url_fetcher_delegate.h"
17 #include "googleurl/src/gurl.h"
18
19 class OAuth2TokenMintFetcherTest;
20
21 namespace net {
22 class URLRequestContextGetter;
23 class URLRequestStatus;
24 }
25
26 // Abstracts the details to mint new OAuth2 tokens from OAuth2 login scoped
27 // token.
28 //
29 // This class should be used on a single thread, but it can be whichever thread
30 // that you like.
31 // Also, do not reuse the same instance. Once Start() is called, the instance
32 // should not be reused.
33 //
34 // Usage:
35 // * Create an instance with a consumer.
36 // * Call Start()
37 // * The consumer passed in the constructor will be called on the same
38 // thread Start was called with the results.
39 //
40 // This class can handle one request at a time. To parallelize requests,
41 // create multiple instances.
42 class OAuth2TokenMintFetcher : public content::URLFetcherDelegate {
jstritar 2012/03/02 13:40:23 Could this be OAuth2TokenMint to use the noun form
43 public:
44 OAuth2TokenMintFetcher(OAuth2TokenMintConsumer* consumer,
45 net::URLRequestContextGetter* getter,
46 const std::string& source);
47 virtual ~OAuth2TokenMintFetcher();
48
49 // Start the flow.
50 void Start(const std::string& oauth_login_access_token,
51 const std::string& client_id,
52 const std::vector<std::string>& scopes,
53 const std::string& origin);
54
55 void CancelRequest();
56
57 // Implementation of content::URLFetcherDelegate
58 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
59
60 private:
61 enum State {
62 INITIAL,
63 MINT_TOKEN_STARTED,
64 MINT_TOKEN_DONE,
65 ERROR_STATE,
66 };
67
68 // Helper methods for the flow.
69 void StartMintToken();
70 void EndMintToken(const content::URLFetcher* source);
71
72 // Helper mehtods for reporting back results.
73 void OnMintTokenSuccess(const std::string& access_token);
74 void OnMintTokenFailure(GoogleServiceAuthError error);
75
76 // Other helpers.
77 static GURL MakeMintTokenUrl();
asargent_no_longer_on_chrome 2012/03/01 00:53:36 Given that this is called "MakeMintTokenUrl" and w
Munjal (Google) 2012/03/01 18:38:52 Done.
jstritar 2012/03/02 13:40:23 Yeah the names are a bit confusing. What do you th
78 static std::string MakeMintTokenHeader(const std::string& access_token);
79 static std::string MakeMintTokenBody(const std::string& client_id,
80 const std::vector<std::string>& scopes,
81 const std::string& origin);
82 static bool ParseMintTokenResponse(const content::URLFetcher* source,
83 std::string* access_token);
84
85 // State that is set during construction.
86 OAuth2TokenMintConsumer* const consumer_;
87 net::URLRequestContextGetter* const getter_;
88 std::string source_;
89 State state_;
90
91 // While a fetch is in progress.
92 scoped_ptr<content::URLFetcher> fetcher_;
93 std::string oauth_login_access_token_;
94 std::string client_id_;
95 std::vector<std::string> scopes_;
96 std::string origin_;
97
98 friend class OAuth2TokenMintFetcherTest;
99 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenMintFetcherTest,
100 ParseMintTokenResponse);
101
102 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenMintFetcher);
103 };
104
105 #endif // CHROME_COMMON_NET_GAIA_OAUTH2_TOKEN_MINT_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698