Skip to content

Commit 0c0e0de

Browse files
committed
Assign any valid roles that we get from Azure
1 parent d5310f6 commit 0c0e0de

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

app/controllers/impact_omniauth_callbacks_controller.rb

+26
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,30 @@ class ImpactOmniauthCallbacksController < DeviseTokenAuth::OmniauthCallbacksCont
44
def auth_hash
55
@_auth_hash ||= request.env["omniauth.auth"] ||= session.delete("dta.omniauth.auth")
66
end
7+
8+
def get_resource_from_auth_hash
9+
super
10+
11+
@resource.roles = Role.where(name: azure_role_names) || []
12+
end
13+
14+
private
15+
16+
def auth_hash_groups
17+
auth_hash.dig("extra", "raw_info", "groups") || []
18+
end
19+
20+
def azure_groups
21+
{
22+
admin: ENV["AZURE_GROUP_ADMIN"],
23+
contributor: ENV["AZURE_GROUP_CONTRIBUTOR"],
24+
manager: ENV["AZURE_GROUP_MANAGER"]
25+
}
26+
end
27+
28+
def azure_role_names
29+
azure_groups
30+
.select { |role, uuid| auth_hash_groups.include?(uuid) }
31+
.keys
32+
end
733
end

0 commit comments

Comments
 (0)