aboutsummaryrefslogtreecommitdiff
path: root/src/privet/auth_manager.cc
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2015-12-18 15:36:01 -0800
committerVitaly Buka <vitalybuka@google.com>2015-12-21 19:26:14 +0000
commit66f46b8468354ee964a150df05d08b31a2c7121a (patch)
treeb39fc3300c48f2f68020b85792bd988deb119e13 /src/privet/auth_manager.cc
parent0bc02ede1d7ac6b0ed264b8891844d15bdb4733e (diff)
downloadlibweave-66f46b8468354ee964a150df05d08b31a2c7121a.tar.gz
Change user_id into string
Cloud users are going to be represented by strings, probably email address. Integer prefix is used to avoid collisions between pairing/anonymous and local users. BUG=25768507 Change-Id: I27249c0b98f919e9527498be74ddaa82218b4041 Reviewed-on: https://weave-review.googlesource.com/2063 Reviewed-by: Alex Vakulenko <avakulenko@google.com>
Diffstat (limited to 'src/privet/auth_manager.cc')
-rw-r--r--src/privet/auth_manager.cc26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/privet/auth_manager.cc b/src/privet/auth_manager.cc
index 86a564d..4d0d2a3 100644
--- a/src/privet/auth_manager.cc
+++ b/src/privet/auth_manager.cc
@@ -33,36 +33,34 @@ void AppendToArray(T value, std::vector<uint8_t>* array) {
array->insert(array->end(), begin, begin + sizeof(value));
}
-// Returns "scope:id:time".
+// Returns "scope:time:id".
std::string CreateTokenData(const UserInfo& user_info, const base::Time& time) {
return base::IntToString(static_cast<int>(user_info.scope())) +
- kTokenDelimeter + base::Uint64ToString(user_info.user_id()) +
- kTokenDelimeter + base::Int64ToString(time.ToTimeT());
+ kTokenDelimeter + std::to_string(time.ToTimeT()) + kTokenDelimeter +
+ user_info.user_id();
}
-// Splits string of "scope:id:time" format.
+// Splits string of "scope:time:id" format.
UserInfo SplitTokenData(const std::string& token, base::Time* time) {
const UserInfo kNone;
- auto parts = Split(token, kTokenDelimeter, false, false);
- if (parts.size() != 3)
+ auto parts = SplitAtFirst(token, kTokenDelimeter, false);
+ if (parts.second.empty())
return kNone;
int scope = 0;
- if (!base::StringToInt(parts[0], &scope) ||
+ if (!base::StringToInt(parts.first, &scope) ||
scope < static_cast<int>(AuthScope::kNone) ||
scope > static_cast<int>(AuthScope::kOwner)) {
return kNone;
}
- uint64_t id{0};
- if (!base::StringToUint64(parts[1], &id))
- return kNone;
-
+ parts = SplitAtFirst(parts.second, kTokenDelimeter, false);
int64_t timestamp{0};
- if (!base::StringToInt64(parts[2], &timestamp))
+ if (parts.second.empty() || !base::StringToInt64(parts.first, &timestamp))
return kNone;
+
if (time)
*time = base::Time::FromTimeT(timestamp);
- return UserInfo{static_cast<AuthScope>(scope), id};
+ return UserInfo{static_cast<AuthScope>(scope), parts.second};
}
class Caveat {
@@ -140,7 +138,7 @@ void AuthManager::SetAuthSecret(const std::vector<uint8_t>& secret,
AuthManager::~AuthManager() {}
-// Returns "[hmac]scope:id:expiration_time".
+// Returns "[hmac]scope:expiration_time:id".
std::vector<uint8_t> AuthManager::CreateAccessToken(const UserInfo& user_info,
base::TimeDelta ttl) const {
std::string data_str{CreateTokenData(user_info, Now() + ttl)};