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