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

Unified Diff: services/authentication/auth_data.cc

Issue 1466733002: Google OAuth Device Flow support for FNL (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: updated demo namespaces Created 5 years 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/auth_data.cc
diff --git a/services/authentication/auth_data.cc b/services/authentication/auth_data.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8ae7f9d1dcaafe51ae5ae7a8866e2aeb9427f938
--- /dev/null
+++ b/services/authentication/auth_data.cc
@@ -0,0 +1,54 @@
+// Copyright 2015 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.
+
+#include "services/authentication/auth_data.h"
+
+#include <vector>
+
+#include "base/logging.h"
+#include "base/strings/string_split.h"
+
+namespace authentication {
+
+const char kAuthDataSeparator = ',';
+
+AuthData::AuthData() = default;
+
+AuthData::~AuthData() = default;
+
+std::string GetAuthDataAsString(const AuthData& auth_data) {
+ std::string str;
+
+ str += auth_data.username;
+ str += kAuthDataSeparator + auth_data.auth_provider;
+ str += kAuthDataSeparator + auth_data.persistent_credential_type;
+ str += kAuthDataSeparator + auth_data.persistent_credential;
+ str += kAuthDataSeparator + auth_data.scopes;
+
+ return str;
+}
+
+AuthData* GetAuthDataFromString(const std::string& auth_str) {
+ if (auth_str.empty()) {
+ return nullptr;
+ }
+
+ std::vector<std::string> auth_components;
+ base::SplitString(auth_str, kAuthDataSeparator, &auth_components);
+ if (auth_components.size() != 5) {
+ LOG(WARNING) << "Unexpected response: " + auth_str;
+ return nullptr;
+ }
+
+ AuthData* auth_data = new AuthData();
+ auth_data->username = auth_components[0];
+ auth_data->auth_provider = auth_components[1];
+ auth_data->persistent_credential_type = auth_components[2];
+ auth_data->persistent_credential = auth_components[3];
+ auth_data->scopes = auth_components[4];
+
+ return auth_data;
+}
+
+} // authentication namespace

Powered by Google App Engine
This is Rietveld 408576698