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