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

Unified 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: Removed data_unittest.py 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 side-by-side diff with in-line comments
Download patch
Index: services/authentication/google_authentication_impl.h
diff --git a/services/authentication/google_authentication_impl.h b/services/authentication/google_authentication_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..8508e8d49f2fb61c3b7aa0e58ad4ff8326d326f3
--- /dev/null
+++ b/services/authentication/google_authentication_impl.h
@@ -0,0 +1,111 @@
+// Copyright 2016 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 SERVICES_AUTHENTICATION_GOOGLE_AUTHENTICATION_IMPL_H_
+#define SERVICES_AUTHENTICATION_GOOGLE_AUTHENTICATION_IMPL_H_
+
+#include "mojo/common/binding_set.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
+#include "mojo/public/cpp/system/macros.h"
+#include "mojo/services/authentication/interfaces/authentication.mojom.h"
+#include "mojo/services/network/interfaces/network_service.mojom.h"
+#include "services/authentication/accounts_db_manager.h"
+
+namespace authentication {
+
+// Implementation of AuthenticationService from
+// services/authentication/authentication.mojom for Google users.
+class GoogleAuthenticationServiceImpl
+ : public authentication::AuthenticationService {
+ public:
+ GoogleAuthenticationServiceImpl(
+ mojo::InterfaceRequest<AuthenticationService> request,
+ const mojo::String app_url,
+ mojo::NetworkServicePtr& network_service,
+ mojo::files::DirectoryPtr& directory);
+
+ ~GoogleAuthenticationServiceImpl() override;
+
+ void GetOAuth2Token(const mojo::String& username,
+ mojo::Array<mojo::String> scopes,
+ const GetOAuth2TokenCallback& callback) override;
+
+ void SelectAccount(bool returnLastSelected,
+ const SelectAccountCallback& callback) override;
+
+ void ClearOAuth2Token(const mojo::String& token) override;
+
+ void GetOAuth2DeviceCode(
+ mojo::Array<mojo::String> scopes,
+ const GetOAuth2DeviceCodeCallback& callback) override;
+
+ void AddAccount(const mojo::String& device_code,
+ const AddAccountCallback& callback) override;
+
+ private:
+ // Polls recursively for user grant authorized on secondary device and
+ // on success, adds the user account to the credentials database and returns
+ // the username. On error, an error description is returned.
+ void AddAccountInternal(const mojo::String& device_code,
+ const uint32_t num_poll_attempts,
+ const AddAccountCallback& callback);
+
+ void OnGetOAuth2Token(const GetOAuth2TokenCallback& callback,
+ const std::string& response,
+ const std::string& error);
+
+ void OnGetOAuth2DeviceCode(const GetOAuth2DeviceCodeCallback& callback,
+ const std::string& response,
+ const std::string& error);
+
+ void OnAddAccount(const AddAccountCallback& callback,
+ const mojo::String& device_code,
+ const uint32_t num_poll_attempts,
+ const std::string& response,
+ const std::string& error);
+
+ // Fetches token info from access token.
+ void GetTokenInfo(const std::string& access_token);
+
+ void OnGetTokenInfo(const std::string& response, const std::string& error);
+
+ // Fetches user info from id token.
+ void GetUserInfo(const std::string& id_token);
+
+ void OnGetUserInfo(const std::string& response, const std::string& error);
+
+ // Makes a Http request to the server endpoint
+ void Request(const std::string& url,
+ const std::string& method,
+ const std::string& message,
+ const mojo::Callback<void(std::string, std::string)>& callback);
+
+ void Request(const std::string& url,
+ const std::string& method,
+ const std::string& message,
+ const mojo::Callback<void(std::string, std::string)>& callback,
+ const mojo::String& device_code,
+ const uint32_t num_poll_attempts);
+
+ // Handles Http response from the server
+ void HandleServerResponse(
+ const mojo::Callback<void(std::string, std::string)>& callback,
+ const mojo::String& device_code,
+ const uint32_t num_poll_attempts,
+ mojo::URLResponsePtr response);
+
+ std::string user_id_;
+ std::string email_;
+ std::string scope_;
+ mojo::StrongBinding<AuthenticationService> binding_;
+ std::string app_url_;
+ mojo::NetworkServicePtr& network_service_;
+ AccountsDbManager* accounts_db_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(GoogleAuthenticationServiceImpl);
+};
+
+} // namespace authentication
+
+#endif // SERVICES_AUTHENTICATION_GOOGLE_AUTHENTICATION_IMPL_H_
« no previous file with comments | « services/authentication/dummy_authentication_app.cc ('k') | services/authentication/google_authentication_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698