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

Side by Side Diff: services/authentication/google_authentication_impl.h

Issue 1466733002: Google OAuth Device Flow support for FNL (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebased to master Created 4 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
OLDNEW
(Empty)
1 // Copyright 2015 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 SERVICES_AUTHENTICATION_GOOGLE_AUTHENTICATION_IMPL_H_
6 #define SERVICES_AUTHENTICATION_GOOGLE_AUTHENTICATION_IMPL_H_
7
8 #include "base/memory/weak_ptr.h"
9 #include "mojo/common/binding_set.h"
10 #include "mojo/public/cpp/bindings/strong_binding.h"
11 #include "mojo/public/cpp/system/macros.h"
12 #include "mojo/services/authentication/interfaces/authentication.mojom.h"
13 #include "mojo/services/network/interfaces/network_service.mojom.h"
14 #include "services/authentication/accounts_db_manager.h"
15
16 namespace authentication {
17
18 // Implementation of AuthenticationService from
19 // services/authentication/authentication.mojom for Google users.
20 class GoogleAuthenticationServiceImpl
21 : public authentication::AuthenticationService {
22 public:
23 GoogleAuthenticationServiceImpl(
24 mojo::InterfaceRequest<AuthenticationService> request,
25 const mojo::String app_url,
26 mojo::NetworkServicePtr& network_service,
27 mojo::files::DirectoryPtr& directory);
28
29 ~GoogleAuthenticationServiceImpl() override;
30
31 void GetOAuth2Token(const mojo::String& username,
32 mojo::Array<mojo::String> scopes,
33 const GetOAuth2TokenCallback& callback) override;
34
35 void SelectAccount(bool returnLastSelected,
36 const SelectAccountCallback& callback) override;
37
38 void ClearOAuth2Token(const mojo::String& token) override;
39
40 void GetOAuth2DeviceCode(
41 mojo::Array<mojo::String> scopes,
42 const GetOAuth2DeviceCodeCallback& callback) override;
43
44 void AddAccount(const mojo::String& device_code,
45 const AddAccountCallback& callback) override;
46
47 private:
48 // Polls recursively for user grant authorized on secondary device and
49 // on success, adds the user account to the credentials database and returns
50 // the username. On error, an error description is returned.
51 void AddAccount(const mojo::String& device_code,
52 const uint32_t num_poll_attempts,
53 const AddAccountCallback& callback);
54
55 void OnGetOAuth2Token(const GetOAuth2TokenCallback& callback,
56 const std::string& response,
57 const std::string& error);
58
59 void OnGetOAuth2DeviceCode(const GetOAuth2DeviceCodeCallback& callback,
60 const std::string& response,
61 const std::string& error);
62
63 // Fetches token info from access token.
64 void GetTokenInfo(const std::string& access_token);
65
66 void OnGetTokenInfo(const std::string& response, const std::string& error);
67
68 // Fetches user info from id token.
69 void GetUserInfo(const std::string& id_token);
70
71 void OnGetUserInfo(const std::string& response, const std::string& error);
72
73 void OnAddAccount(const AddAccountCallback& callback,
74 const mojo::String& device_code,
75 const uint32_t num_poll_attempts,
76 const std::string& response,
77 const std::string& error);
78
79 void Request(const std::string& url,
80 const std::string& method,
81 const std::string& message,
82 const GetOAuth2TokenCallback& callback);
83
84 void Request(const std::string& url,
85 const std::string& method,
86 const std::string& message,
87 const GetOAuth2TokenCallback& callback,
88 const mojo::String& device_code,
89 const uint32_t num_poll_attempts);
90
91 void HandleServerResponse(const GetOAuth2TokenCallback& callback,
92 const mojo::String& device_code,
93 const uint32_t num_poll_attempts,
94 mojo::URLResponsePtr response);
95
96 std::string user_id_;
97 std::string email_;
98 std::string scope_;
99 mojo::StrongBinding<AuthenticationService> binding_;
100 std::string app_url_;
101 mojo::NetworkServicePtr& network_service_;
102 base::WeakPtr<AccountsDbManager> accounts_db_manager_;
103
104 DISALLOW_COPY_AND_ASSIGN(GoogleAuthenticationServiceImpl);
105 };
106
107 } // namespace authentication
108
109 #endif // SERVICES_AUTHENTICATION_GOOGLE_AUTHENTICATION_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698