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

Side by Side 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: Created 4 years, 10 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 #include "services/authentication/auth_data.h"
6
7 #include <vector>
8
9 #include "base/logging.h"
10 #include "base/strings/string_split.h"
11
12 namespace authentication {
13
14 const char kAuthDataSeparator = ',';
qsr 2016/02/16 14:17:06 Why is it safe? Do we have guarantees that it will
ukode 2016/02/26 21:35:50 Got rid of this completely. Instead using a mojom
15
16 AuthData::AuthData() = default;
17
18 AuthData::~AuthData() = default;
19
20 // Serializes auth data as a string with auth components delimited by ",".
21 std::string GetAuthDataAsString(const AuthData& auth_data) {
22 std::string str;
23
24 str += auth_data.username;
25 str += kAuthDataSeparator + auth_data.auth_provider;
26 str += kAuthDataSeparator + auth_data.persistent_credential_type;
27 str += kAuthDataSeparator + auth_data.persistent_credential;
28 str += kAuthDataSeparator + auth_data.scopes;
29
30 return str;
31 }
32
33 // Deserializes auth data from an input string with the following pattern:
34 // "test@gmail.com,Google,RT,1/2345abcedef,profile email"
35 AuthData* GetAuthDataFromString(const std::string& auth_str) {
36 if (auth_str.empty()) {
37 return nullptr;
38 }
39
40 std::vector<std::string> auth_components;
41 base::SplitString(auth_str, kAuthDataSeparator, &auth_components);
42 if (auth_components.size() != 5) {
43 LOG(WARNING) << "Unexpected response: " + auth_str;
44 return nullptr;
45 }
46
47 AuthData* auth_data = new AuthData();
48 auth_data->username = auth_components[0];
49 auth_data->auth_provider = auth_components[1];
50 auth_data->persistent_credential_type = auth_components[2];
51 auth_data->persistent_credential = auth_components[3];
52 auth_data->scopes = auth_components[4];
53
54 return auth_data;
55 }
56
57 } // authentication namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698