Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added integration with OpenID Connect Authelia #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions app/models/oic_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,31 @@ def check_keycloak_role(role)
return true if kc_is_in_role
end

def check_authelia_role(role)
#authelia way...
authelia_is_in_role = false
if user["groups"].present?
authelia_is_in_role = user["groups"].include?(role)
end
return true if authelia_is_in_role
end

def authorized?
if client_config['group'].blank?
return true
end

return true if check_keycloak_role client_config['group']

return true if check_authelia_role client_config['group']

return false if !user["member_of"] && !user["roles"]

return true if self.admin?

if client_config['group'].present?
return true if user["member_of"].present? && user["member_of"].include?(client_config['group'])
return true if user["roles"].present? && user["roles"].include?(client_config['group']) || user["roles"].include?(client_config['admin_group'])
return true if user["roles"].present? && user["roles"].include?(client_config['group']) || user["roles"].include?(client_config['admin_group'])
end

return false
Expand All @@ -168,13 +179,16 @@ def admin?
end
# keycloak way...
return true if check_keycloak_role client_config['admin_group']

# authelia way...
return true if check_authelia_role client_config['admin_group']
end

return false
end

def user
if access_token? # keycloak way...
if (access_token? && access_token.exclude?('authelia')) # keycloak way...
@user = JSON::parse(Base64::decode64(access_token.split('.')[1]))
else
@user = JSON::parse(Base64::decode64(id_token.split('.')[1]))
Expand Down