commit
8c8b55c7fd
|
@ -63,7 +63,7 @@ module AuthD
|
|||
})
|
||||
end
|
||||
|
||||
class Client < IPC::Client
|
||||
class Client < IPC::Connection
|
||||
property key : String
|
||||
|
||||
def initialize
|
||||
|
|
25
src/main.cr
25
src/main.cr
|
@ -11,9 +11,9 @@ require "./passwd.cr"
|
|||
|
||||
extend AuthD
|
||||
|
||||
class IPC::RemoteClient
|
||||
def send(type : ResponseTypes, payload : String)
|
||||
send type.value.to_u8, payload
|
||||
class IPC::Connection
|
||||
def send(type : AuthD::ResponseTypes, payload : String)
|
||||
send type.to_u8, payload
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -46,17 +46,24 @@ passwd = Passwd.new authd_passwd_file, authd_group_file
|
|||
##
|
||||
# Provides a JWT-based authentication scheme for service-specific users.
|
||||
IPC::Service.new "auth" do |event|
|
||||
client = event.client
|
||||
if event.is_a? IPC::Exception
|
||||
puts "oh no"
|
||||
pp! event
|
||||
next
|
||||
end
|
||||
|
||||
client = event.connection
|
||||
|
||||
case event
|
||||
when IPC::Event::Message
|
||||
message = event.message
|
||||
payload = message.payload
|
||||
pp message
|
||||
|
||||
case RequestTypes.new message.type.to_i
|
||||
when RequestTypes::GetToken
|
||||
begin
|
||||
request = GetTokenRequest.from_json payload
|
||||
request = GetTokenRequest.from_json String.new payload
|
||||
rescue e
|
||||
client.send ResponseTypes::MalformedRequest.value.to_u8, e.message || ""
|
||||
|
||||
|
@ -75,7 +82,7 @@ IPC::Service.new "auth" do |event|
|
|||
JWT.encode user.to_h, authd_jwt_key, "HS256"
|
||||
when RequestTypes::AddUser
|
||||
begin
|
||||
request = AddUserRequest.from_json payload
|
||||
request = AddUserRequest.from_json String.new payload
|
||||
rescue e
|
||||
client.send ResponseTypes::MalformedRequest.value.to_u8, e.message || ""
|
||||
|
||||
|
@ -93,7 +100,7 @@ IPC::Service.new "auth" do |event|
|
|||
client.send ResponseTypes::Ok, user.to_json
|
||||
when RequestTypes::GetUserByCredentials
|
||||
begin
|
||||
request = GetUserByCredentialsRequest.from_json payload
|
||||
request = GetUserByCredentialsRequest.from_json String.new payload
|
||||
rescue e
|
||||
client.send ResponseTypes::MalformedRequest, e.message || ""
|
||||
next
|
||||
|
@ -108,7 +115,7 @@ IPC::Service.new "auth" do |event|
|
|||
end
|
||||
when RequestTypes::GetUser
|
||||
begin
|
||||
request = GetUserRequest.from_json payload
|
||||
request = GetUserRequest.from_json String.new payload
|
||||
rescue e
|
||||
client.send ResponseTypes::MalformedRequest, e.message || ""
|
||||
next
|
||||
|
@ -123,7 +130,7 @@ IPC::Service.new "auth" do |event|
|
|||
end
|
||||
when RequestTypes::ModUser
|
||||
begin
|
||||
request = ModUserRequest.from_json payload
|
||||
request = ModUserRequest.from_json String.new payload
|
||||
rescue e
|
||||
client.send ResponseTypes::MalformedRequest, e.message || ""
|
||||
next
|
||||
|
|
|
@ -38,8 +38,6 @@ class Passwd
|
|||
if group.users.any? { |name| name == user.login }
|
||||
user.groups << group.name
|
||||
end
|
||||
|
||||
pp group
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -195,7 +193,7 @@ class Passwd
|
|||
end
|
||||
end
|
||||
|
||||
File.write @passwd, new_passwd.join
|
||||
File.write @passwd, new_passwd.join + "\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue