Improve spark login token (i.e. Dont' hard code it)
This commit is contained in:
1 parent
c09485affc
commit
f24ac03034
3 files changed
+49
-10
No files matched your search
@@ -0,0 +1,33 @@
|
||||
#include "AuthToken.h"
|
||||
#include "lib/utils/base64.hpp"
|
||||
#include "datetime.h"
|
||||
#include "base64.hpp"
|
||||
|
||||
namespace bts {
|
||||
namespace api {
|
||||
namespace auth {
|
||||
|
||||
user::AuthToken generate_token(const admin::BTSUser& user) {
|
||||
api::user::TokenPayload payload;
|
||||
payload.set_date(datetime::ll_now());
|
||||
payload.set_id(user.id());
|
||||
auto token = websocketpp::base64_encode(payload.SerializeAsString());
|
||||
user::AuthToken result;
|
||||
result.set_token(token);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool decode_token(const std::string& token, user::TokenPayload* payload) {
|
||||
std::string temp = websocketpp::base64_decode(token);
|
||||
if (payload) {
|
||||
return payload->ParseFromString(temp);
|
||||
}
|
||||
else {
|
||||
// validate the token but don't return it
|
||||
user::TokenPayload payload;
|
||||
return payload.ParseFromString(temp);
|
||||
}
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
Reference in new issue
Block a user