WIP: remove "shared keys logic" and use logged user hash.

This commit is contained in:
Philippe Pittoli 2023-06-10 18:27:50 +02:00
parent 2a267ea7a2
commit 4989218a79
3 changed files with 20 additions and 40 deletions

View File

@ -242,12 +242,8 @@ module AuthD
end end
end end
def delete(user : Int32 | String, key : String) def delete(user : Int32 | String)
send_now Request::Delete.new user, key send_now Request::Delete.new user
delete_
end
def delete(user : Int32 | String, login : String, pass : String)
send_now Request::Delete.new user, login, pass
delete_ delete_
end end
def delete_ def delete_

View File

@ -80,6 +80,8 @@ class Actions
password = Actions.ask_password password = Actions.ask_password
exit 1 unless password exit 1 unless password
# TODO: login.
# By default: no phone, not admin. # By default: no phone, not admin.
pp! authd.add_user login, password.not_nil!, false, email, nil, profile: profile pp! authd.add_user login, password.not_nil!, false, email, nil, profile: profile
rescue e : AuthD::Exception rescue e : AuthD::Exception
@ -120,6 +122,8 @@ class Actions
email = Context.email email = Context.email
phone = Context.phone phone = Context.phone
# TODO: login.
Baguette::Log.error "This function shouldn't be used for now." Baguette::Log.error "This function shouldn't be used for now."
Baguette::Log.error "It is way too cumbersome." Baguette::Log.error "It is way too cumbersome."
@ -131,12 +135,10 @@ class Actions
args = Context.args.not_nil! args = Context.args.not_nil!
userid = args[0].to_i userid = args[0].to_i
# Check if the request comes from an admin or the user. # Context.authd_login, Context.authd_pass
res = if Context.shared_key.nil? # TODO: login.
authd.delete userid, Context.authd_login, Context.authd_pass
else res = authd.delete userid
authd.delete userid, Context.shared_key
end
puts res puts res
end end
@ -159,6 +161,7 @@ class Actions
def user_recovery def user_recovery
args = Context.args.not_nil! args = Context.args.not_nil!
login, email = args[0..1] login, email = args[0..1]
# TODO: login.
pp! authd.ask_password_recovery login, email pp! authd.ask_password_recovery login, email
end end
@ -167,6 +170,7 @@ class Actions
user, application, resource = args[0..2] user, application, resource = args[0..2]
# pp! user, application, resource # pp! user, application, resource
# TODO: login.
res = @authd.check_permission user.to_i, application, resource res = @authd.check_permission user.to_i, application, resource
puts res puts res
end end
@ -176,6 +180,7 @@ class Actions
user, application, resource, permission = args[0..3] user, application, resource, permission = args[0..3]
# pp! user, application, resource, permission # pp! user, application, resource, permission
# TODO: login.
perm = AuthD::User::PermissionLevel.parse(permission) perm = AuthD::User::PermissionLevel.parse(permission)
res = @authd.set_permission user.to_i, application, resource, perm res = @authd.set_permission user.to_i, application, resource, perm
puts res puts res

View File

@ -1,42 +1,21 @@
class AuthD::Request class AuthD::Request
IPC::JSON.message CheckPermission, 9 do IPC::JSON.message CheckPermission, 9 do
property shared_key : String? = nil
property token : String? = nil
property user : Int32 | String property user : Int32 | String
property service : String property service : String
property resource : String property resource : String
def initialize(@shared_key, @user, @service, @resource) def initialize(@user, @service, @resource)
end end
def handle(authd : AuthD::Service, fd : Int32) def handle(authd : AuthD::Service, fd : Int32)
authorized = false # Get currently logged user.
logged_user = authd.get_logged_user? fd
if key = @shared_key if logged_user.nil?
if key == authd.configuration.shared_key return Response::Error.new "you must be logged"
authorized = true
else
return Response::Error.new "invalid key provided"
end
end end
if token = @token unless logged_user.admin
user = authd.get_user_from_token token return Response::Error.new "unauthorized (not admin)"
if user.nil?
return Response::Error.new "token does not match user"
end
if user.login != @user && user.uid != @user
return Response::Error.new "token does not match user"
end
authorized = true
end
unless authorized
return Response::Error.new "unauthorized"
end end
user = case u = @user user = case u = @user