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

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: 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 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 = ',';
15
16 AuthData::AuthData() = default;
17
18 AuthData::~AuthData() = default;
19
20 std::string GetAuthDataAsString(const AuthData& auth_data) {
21 std::string str;
22
23 str += auth_data.username;
24 str += kAuthDataSeparator + auth_data.auth_provider;
25 str += kAuthDataSeparator + auth_data.persistent_credential_type;
26 str += kAuthDataSeparator + auth_data.persistent_credential;
27 str += kAuthDataSeparator + auth_data.scopes;
28
29 return str;
30 }
31
32 AuthData* GetAuthDataFromString(const std::string& auth_str) {
33 if (auth_str.empty()) {
34 return nullptr;
35 }
36
37 std::vector<std::string> auth_components;
38 base::SplitString(auth_str, kAuthDataSeparator, &auth_components);
39 if (auth_components.size() != 5) {
40 LOG(WARNING) << "Unexpected response: " + auth_str;
41 return nullptr;
42 }
43
44 AuthData* auth_data = new AuthData();
45 auth_data->username = auth_components[0];
46 auth_data->auth_provider = auth_components[1];
47 auth_data->persistent_credential_type = auth_components[2];
48 auth_data->persistent_credential = auth_components[3];
49 auth_data->scopes = auth_components[4];
50
51 return auth_data;
52 }
53
54 } // authentication namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698