Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
kickster97 committed Nov 26, 2024
1 parent 9b580bd commit cb9080a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/lavinmq/auth/auth_handler.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module LavinMQ
abstract class AuthHandler

@successor : AuthHandler?

def initialize(successor : AuthHandler? = nil)
Expand Down
9 changes: 4 additions & 5 deletions src/lavinmq/auth/basic_auth.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ require "../server"

module LavinMQ
class BasicAuthHandler < LavinMQ::AuthHandler

def authenticate(username : String, password : String, users : UserStore, remote_address : Socket::Address)
user = users[username]
# TODO: do not do authentication check if the user is not in the userstore, instead pass directly to the next handler
return user if user && user.password && user.password.not_nil!.verify(password) &&
guest_only_loopback?(remote_address, user)
guest_only_loopback?(remote_address, user)
puts "Basic authentication failed"
@successor ? @successor.try &.authenticate(username, password) : nil
end

private def guest_only_loopback?(remote_address, user) : Bool
return true unless user.name == "guest"
return true unless Config.instance.guest_only_loopback?
remote_address.loopback?
return true unless user.name == "guest"
return true unless Config.instance.guest_only_loopback?
remote_address.loopback?
end
end
end
1 change: 0 additions & 1 deletion src/lavinmq/auth/oauth2.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module LavinMQ
class OAuth2Handler < LavinMQ::AuthHandler
def authenticate(username : String, password : String)

# TODO: implement the OAuth2 authentication logic and permissions parser here
if password.starts_with?("oauth")
puts "OAuth2 authentication successful"
Expand Down

0 comments on commit cb9080a

Please sign in to comment.