aboutsummaryrefslogtreecommitdiff
path: root/src/privet/privet_handler.cc
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2015-12-17 20:34:29 -0800
committerVitaly Buka <vitalybuka@google.com>2015-12-21 18:23:23 +0000
commit29bd07079198a78c59f2d8964d66e98ca0613c68 (patch)
tree65ab6c5f545b91da36e580d40a45df7e534a7967 /src/privet/privet_handler.cc
parentf6a0fd9eb53f4ad0e8f9c8aade10fa4ec3e668d9 (diff)
downloadlibweave-29bd07079198a78c59f2d8964d66e98ca0613c68.tar.gz
Add AuthType enum with string mapping
BUG=25768507 Change-Id: I3d1b928407b3fa8e285b1c8bc1385e031f6abfba Reviewed-on: https://weave-review.googlesource.com/2048 Reviewed-by: Alex Vakulenko <avakulenko@google.com>
Diffstat (limited to 'src/privet/privet_handler.cc')
-rw-r--r--src/privet/privet_handler.cc47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/privet/privet_handler.cc b/src/privet/privet_handler.cc
index 0af431b..b55053d 100644
--- a/src/privet/privet_handler.cc
+++ b/src/privet/privet_handler.cc
@@ -79,9 +79,6 @@ const char kPairingClientCommitmentKey[] = "clientCommitment";
const char kPairingFingerprintKey[] = "certFingerprint";
const char kPairingSignatureKey[] = "certSignature";
-const char kAuthTypeAnonymousValue[] = "anonymous";
-const char kAuthTypePairingValue[] = "pairing";
-
const char kAuthModeKey[] = "mode";
const char kAuthCodeKey[] = "authCode";
const char kAuthRequestedScopeKey[] = "requestedScope";
@@ -266,8 +263,8 @@ std::unique_ptr<base::DictionaryValue> CreateInfoAuthSection(
auth->Set(kPairingKey, pairing_types.release());
std::unique_ptr<base::ListValue> auth_types(new base::ListValue());
- auth_types->AppendString(kAuthTypeAnonymousValue);
- auth_types->AppendString(kAuthTypePairingValue);
+ auth_types->AppendString(EnumToString(AuthType::kAnonymous));
+ auth_types->AppendString(EnumToString(AuthType::kPairing));
// TODO(vitalybuka): Implement cloud auth.
// if (cloud.GetConnectionState().IsStatusEqual(ConnectionState::kOnline)) {
@@ -513,7 +510,7 @@ void PrivetHandler::HandleRequest(const std::string& api,
return ReturnError(*error, callback);
}
UserInfo user_info;
- if (token != kAuthTypeAnonymousValue) {
+ if (token != EnumToString(AuthType::kAnonymous)) {
if (!security_->ParseAccessToken(token, &user_info, &error))
return ReturnError(*error, callback);
}
@@ -678,27 +675,37 @@ void PrivetHandler::HandleAuth(const base::DictionaryValue& input,
ErrorPtr error;
std::string auth_code_type;
- input.GetString(kAuthModeKey, &auth_code_type);
+ AuthType auth_type{};
+ if (!input.GetString(kAuthModeKey, &auth_code_type) ||
+ !StringToEnum(auth_code_type, &auth_type)) {
+ Error::AddToPrintf(&error, FROM_HERE, errors::kDomain,
+ errors::kInvalidAuthMode, kInvalidParamValueFormat,
+ kAuthModeKey, auth_code_type.c_str());
+ return ReturnError(*error, callback);
+ }
std::string auth_code;
input.GetString(kAuthCodeKey, &auth_code);
AuthScope max_auth_scope = AuthScope::kNone;
- if (auth_code_type == kAuthTypeAnonymousValue) {
- max_auth_scope = GetAnonymousMaxScope(*cloud_, wifi_);
- } else if (auth_code_type == kAuthTypePairingValue) {
- if (!security_->IsValidPairingCode(auth_code)) {
+ switch (auth_type) {
+ case AuthType::kAnonymous:
+ max_auth_scope = GetAnonymousMaxScope(*cloud_, wifi_);
+ break;
+ case AuthType::kPairing:
+ if (!security_->IsValidPairingCode(auth_code)) {
+ Error::AddToPrintf(&error, FROM_HERE, errors::kDomain,
+ errors::kInvalidAuthCode, kInvalidParamValueFormat,
+ kAuthCodeKey, auth_code.c_str());
+ return ReturnError(*error, callback);
+ }
+ max_auth_scope = AuthScope::kOwner;
+ break;
+ default:
Error::AddToPrintf(&error, FROM_HERE, errors::kDomain,
- errors::kInvalidAuthCode, kInvalidParamValueFormat,
- kAuthCodeKey, auth_code.c_str());
+ errors::kInvalidAuthMode, kInvalidParamValueFormat,
+ kAuthModeKey, auth_code_type.c_str());
return ReturnError(*error, callback);
- }
- max_auth_scope = AuthScope::kOwner;
- } else {
- Error::AddToPrintf(&error, FROM_HERE, errors::kDomain,
- errors::kInvalidAuthMode, kInvalidParamValueFormat,
- kAuthModeKey, auth_code_type.c_str());
- return ReturnError(*error, callback);
}
std::string requested_scope;