Skip to content

Commit

Permalink
cherry-pick HttpAuthService from JadeKharats:issue-246-auth-backend
Browse files Browse the repository at this point in the history
Co-authored-by: JadeKharats
  • Loading branch information
kickster97 committed Nov 27, 2024
1 parent 73da640 commit ad938f1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/lavinmq/auth/http_service.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "http/client"
require "json"
require "./auth_service"

module LavinMQ
class HttpAuthService < AuthenticationService
def initialize(@method : String, @user_path : String, @whost_path : String, @resource_path : String, @topic_path : String)
end

def authorize?(username : String, password : String)

payload = {
"username" => username,
"password" => password
}.to_json

success = ::HTTP::Client.post(@user_path,
headers: ::HTTP::Headers{"Content-Type" => "application/json"},
body: payload).success?

if success
"allow"
else
try_next(username, password)
end
end
end
end

0 comments on commit ad938f1

Please sign in to comment.