blob: cd3ee5c7ba4a7d270cbb71c009aa3e33d1ff1a50 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GOOGLE_APIS_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_H_
#define GOOGLE_APIS_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_H_
#include <string>
#include <vector>
#include "google_apis/gaia/oauth2_access_token_consumer.h"
#include "net/url_request/url_fetcher_delegate.h"
class OAuth2AccessTokenConsumer;
// Interface of a OAuth2 access token fetcher.
//
// Usage:
// * Create an instance with a consumer.
// * Call Start()
// * The consumer passed in the constructor will be called on the same
// thread Start was called with the results.
//
// This class can handle one request at a time. To parallelize requests,
// create multiple instances.
class OAuth2AccessTokenFetcher {
public:
explicit OAuth2AccessTokenFetcher(OAuth2AccessTokenConsumer* consumer);
virtual ~OAuth2AccessTokenFetcher();
// Starts the flow with the given parameters.
// |scopes| can be empty. If it is empty then the access token will have the
// same scope as the refresh token. If not empty, then access token will have
// the scopes specified. In this case, the access token will successfully be
// generated only if refresh token has login scope of a list of scopes that is
// a super-set of the specified scopes.
virtual void Start(const std::string& client_id,
const std::string& client_secret,
const std::vector<std::string>& scopes) = 0;
// Cancels the current request and informs the consumer.
virtual void CancelRequest() = 0;
protected:
// Fires |OnGetTokenSuccess| on |consumer_|.
void FireOnGetTokenSuccess(const std::string& access_token,
const base::Time& expiration_time);
// Fires |OnGetTokenFailure| on |consumer_|.
void FireOnGetTokenFailure(const GoogleServiceAuthError& error);
private:
OAuth2AccessTokenConsumer* const consumer_;
DISALLOW_COPY_AND_ASSIGN(OAuth2AccessTokenFetcher);
};
#endif // GOOGLE_APIS_GAIA_OAUTH2_ACCESS_TOKEN_FETCHER_H_
|