SPARK-1030 Make authentication real
This commit is contained in:
1 parent
7a329522bb
commit
2408c8dcc7
2 files changed
+27
-13
No files matched your search
@@ -61,6 +61,7 @@ public:
|
||||
}
|
||||
|
||||
bool success() const { return _code == ApiError::SUCCESS; }
|
||||
operator bool() const { return success(); }
|
||||
ApiError code() const { return _code; }
|
||||
const char* error_message() const { return error_string(_code); }
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/api/public/ApiUtils.h"
|
||||
#include "lib/api/core/ApiClientInterop.h"
|
||||
#include "lib/api/services/UserService.client.pb.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
@@ -17,6 +18,8 @@ namespace http {
|
||||
struct ApiGatewayImpl {
|
||||
std::mutex _m;
|
||||
const api::ServiceContext& _sc;
|
||||
api::user::UserService _logon;
|
||||
|
||||
std::unordered_map<std::string, api::ApiClient*> _apiclient;
|
||||
std::vector<api::TableSubscription> _subscriptions;
|
||||
|
||||
@@ -24,24 +27,34 @@ struct ApiGatewayImpl {
|
||||
ApiGatewayImpl(const api::ServiceContext& ctx) :
|
||||
_m(),
|
||||
_sc(ctx),
|
||||
_logon(ctx.locate<api::user::UserService>()),
|
||||
_apiclient(),
|
||||
_subscriptions()
|
||||
{ }
|
||||
|
||||
void handle_login(const GatewayLogin& login, const Responder& r) {
|
||||
void handle_login(const GatewayLogin& login, const Responder& respond) {
|
||||
LOG(Api,Info, "Logon request for {}", login.username());
|
||||
GatewayResponse result;
|
||||
//todo: UserService authenticate_login_async
|
||||
if (login.username() == "bts") {
|
||||
result.mutable_logon()->set_is_valid(true);
|
||||
result.mutable_logon()->set_token("SuperSecretToken");
|
||||
r(result);
|
||||
}
|
||||
else {
|
||||
result.mutable_logon()->set_is_valid(false);
|
||||
result.mutable_logon()->set_reason("Your mother is a hamster and your father smelt of elderberries.");
|
||||
r(result);
|
||||
}
|
||||
|
||||
api::user::AuthenticateLoginRequest alr;
|
||||
alr.set_login(login.username());
|
||||
alr.set_password(login.password());
|
||||
_logon.authenticate_login(alr, [respond](const api::Result<api::user::AuthenticateLoginResponse>& logon_response) {
|
||||
GatewayResponse resp;
|
||||
resp.mutable_logon()->set_is_valid(false);
|
||||
if (logon_response) {
|
||||
if (logon_response.result()->is_valid()) {
|
||||
resp.mutable_logon()->set_is_valid(true);
|
||||
resp.mutable_logon()->set_token(logon_response.result()->token().token());
|
||||
}
|
||||
else {
|
||||
resp.mutable_logon()->set_reason(logon_response.result()->reason());
|
||||
}
|
||||
}
|
||||
else {
|
||||
resp.mutable_logon()->set_reason(logon_response.error_message());
|
||||
}
|
||||
respond(resp);
|
||||
});
|
||||
}
|
||||
|
||||
void error(const Responder& r, const std::string msg) {
|
||||
|
||||
Reference in new issue
Block a user