New DecodeToken request.

master
Philippe Pittoli 2023-06-14 18:39:23 +02:00
parent a441431e05
commit 00c202a63a
1 changed files with 22 additions and 0 deletions

View File

@ -83,4 +83,26 @@ class AuthD::Request
end end
end end
AuthD.requests << BootstrapFirstAdmin AuthD.requests << BootstrapFirstAdmin
IPC::JSON.message DecodeToken, 14 do
property token : String
def initialize(@token)
end
def handle(authd : AuthD::Service, fd : Int32)
logged_user = authd.get_logged_user_full? fd
return Response::ErrorMustBeAuthenticated.new if logged_user.nil?
logged_user.assert_permission("authd", "*", User::PermissionLevel::Read)
token_payload = AuthD::Token.from_s authd.configuration.secret_key, token
user = authd.users_per_uid.get? token_payload.uid.to_s
if user
Response::User.new user.to_public
else
Response::ErrorUserNotFound.new
end
end
end
AuthD.requests << DecodeToken
end end