From deacd0dfc195bca41af631114804d29937337cd8 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 17 Jan 2024 02:11:31 +0900 Subject: . --- services/app/src/Auth/AuthProviderInterface.php | 10 +++++ services/app/src/Auth/AuthenticationResult.php | 13 +++++++ services/app/src/Auth/ForteeAuth.php | 50 +++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 services/app/src/Auth/AuthProviderInterface.php create mode 100644 services/app/src/Auth/AuthenticationResult.php create mode 100644 services/app/src/Auth/ForteeAuth.php (limited to 'services/app/src/Auth') diff --git a/services/app/src/Auth/AuthProviderInterface.php b/services/app/src/Auth/AuthProviderInterface.php new file mode 100644 index 0000000..19122f6 --- /dev/null +++ b/services/app/src/Auth/AuthProviderInterface.php @@ -0,0 +1,10 @@ + $username, + 'password' => $password, + ]; + $context = stream_context_create([ + 'http' => [ + 'method' => 'POST', + 'follow_location' => 0, + 'header' => [ + 'Content-type: application/x-www-form-urlencoded', + 'Accept: application/json', + ], + 'timeout' => 5.0, + 'content' => http_build_query($query_params), + ], + ]); + $result = file_get_contents( + $this->apiEndpoint . '/api/user/login', + context: $context, + ); + if ($result === false) { + return AuthenticationResult::UnknownError; + } + $result = json_decode($result, true); + if (!is_array($result)) { + return AuthenticationResult::InvalidJson; + } + $ok = ($result['loggedIn'] ?? null) === true; + if ($ok) { + return AuthenticationResult::Success; + } else { + return AuthenticationResult::InvalidCredentials; + } + } +} -- cgit v1.2.3-70-g09d2