diff options
| author | Stefan Boberg <[email protected]> | 2023-05-02 12:31:53 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-02 12:31:53 +0200 |
| commit | e3086573d2244def22ecbe1e6b4b3da8b47e0f14 (patch) | |
| tree | 627066debdddf7474783893f6b9b6631bb9a4833 /src/zenserver/auth/authservice.cpp | |
| parent | moved source directories into `/src` (#264) (diff) | |
| download | zen-e3086573d2244def22ecbe1e6b4b3da8b47e0f14.tar.xz zen-e3086573d2244def22ecbe1e6b4b3da8b47e0f14.zip | |
move auth code from zenserver into zenhttp (#265)
this code should be usable outside of zenserver, so this moves it out into zenhttp where it can be used from lower level components
Diffstat (limited to 'src/zenserver/auth/authservice.cpp')
| -rw-r--r-- | src/zenserver/auth/authservice.cpp | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/src/zenserver/auth/authservice.cpp b/src/zenserver/auth/authservice.cpp deleted file mode 100644 index 1cc679540..000000000 --- a/src/zenserver/auth/authservice.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#include <auth/authservice.h> - -#include <auth/authmgr.h> - -#include <zencore/compactbinarybuilder.h> -#include <zencore/string.h> - -ZEN_THIRD_PARTY_INCLUDES_START -#include <json11.hpp> -ZEN_THIRD_PARTY_INCLUDES_END - -namespace zen { - -using namespace std::literals; - -HttpAuthService::HttpAuthService(AuthMgr& AuthMgr) : m_AuthMgr(AuthMgr) -{ - m_Router.RegisterRoute( - "oidc/refreshtoken", - [this](HttpRouterRequest& RouterRequest) { - HttpServerRequest& ServerRequest = RouterRequest.ServerRequest(); - - const HttpContentType ContentType = ServerRequest.RequestContentType(); - - if ((ContentType == HttpContentType::kUnknownContentType || ContentType == HttpContentType::kJSON) == false) - { - return ServerRequest.WriteResponse(HttpResponseCode::BadRequest); - } - - const IoBuffer Body = ServerRequest.ReadPayload(); - - std::string JsonText(reinterpret_cast<const char*>(Body.GetData()), Body.GetSize()); - std::string JsonError; - json11::Json TokenInfo = json11::Json::parse(JsonText, JsonError); - - if (!JsonError.empty()) - { - CbObjectWriter Response; - Response << "Result"sv << false; - Response << "Error"sv << JsonError; - - return ServerRequest.WriteResponse(HttpResponseCode::BadRequest, Response.Save()); - } - - const std::string RefreshToken = TokenInfo["RefreshToken"].string_value(); - std::string ProviderName = TokenInfo["ProviderName"].string_value(); - - if (ProviderName.empty()) - { - ProviderName = "Default"sv; - } - - const bool Ok = - m_AuthMgr.AddOpenIdToken(AuthMgr::AddOpenIdTokenParams{.ProviderName = ProviderName, .RefreshToken = RefreshToken}); - - if (Ok) - { - ServerRequest.WriteResponse(Ok ? HttpResponseCode::OK : HttpResponseCode::BadRequest); - } - else - { - CbObjectWriter Response; - Response << "Result"sv << false; - Response << "Error"sv - << "Invalid token"sv; - - ServerRequest.WriteResponse(HttpResponseCode::BadRequest, Response.Save()); - } - }, - HttpVerb::kPost); -} - -HttpAuthService::~HttpAuthService() -{ -} - -const char* -HttpAuthService::BaseUri() const -{ - return "/auth/"; -} - -void -HttpAuthService::HandleRequest(zen::HttpServerRequest& Request) -{ - m_Router.HandleRequest(Request); -} - -} // namespace zen |