I need help in figuring out how I can get a user's assigned groups via OpenID Connect over ADFS (Windows Server 2016). I am currently able to authenticate a user and get the user info including the access_token. When I inspect the JWT-token I can see all of the default claims in there. What I want is to add all of the users' assigned system groups to the claims as an array of strings, but I have no idea of how to accomplish this. ADFS and Windows Server is a beast and all of the search results from Google is not leading me in the right direction. All of the articles I find is kinda useless since they're either incomplete in the steps or hard to follow if you're not educated in the whole ADFS-shebang.
I have been stuck at this problem for a couple of days now and need some help, hopefully there's someone out there with knowledge about this.
What I've done so far:
- I have added an application group to ADFS which contains a "Server Application" and a "Web API".
- I have added a user group called Admin and assigned that to a user called max.
- I can login through OpenID Connect over ADFS and get the user info from the userinfo-endpoint.
- I have been able to decode the access_token to access the claims.
I'm currently authenticating with the scopes "openid", "email" and "profile".
We just got everything working so I just thought I'd share what we did if anyone else wants to do what we did.
Prerequisites
To be able to follow the steps below you'll need to have Windows Server 2016 or later with the "Active Directory Federation Services (ADFS)" feature enabled.
Add a OpenID Connect configuration to ADFS
- Open the "AD FS Management" tool located under the "Tools" menu at the top right of the Server Manager.
- Select the "Application Groups" folder item in the left sidebar.
- Click on "Add Application Group..." in the sidebar to the right.
- Give the application group a name, for example "OpenID Connect"
- Select the "Server application accessing a web API" list item and click next.
- Copy and paste the Client Identifier to a text file for later use.
- Enter the your authentication "Redirect URI" and Click next.
- Tick the "Generate a shared secret" box. Copy and paste the Secret to a text for use with your application. Click next.
- Paste and add the Client Identifier (from step 6) as the "Identifier". Click next.
- Select the access control policy you'd like to use and click next.
- Make sure the box next to "openid" is ticked.
- Click the "New scope..." button in the bottom and and give it the name "allatclaims", click OK. This scope is needed to provide additional information as claims, such as the the user's groups.
- Finish the wizard.
Configure OpenID Connect to provide user groups as claims
- Open the "AD FS Management" tool located under the "Tools" menu at the top right of the Server Manager.
- Select the "Application Groups" folder item in the left sidebar.
- Double click on the group added earlier, then double click on the "Web API" application.
- Select the tab named "Issuance Transform Rules".
- Click the "Add Rule..." button at the bottom.
- Select "Send LDAP Attributes as Claims" and click next.
- Give the rule a name, for example "Roles".
- Select "Active Directory" as the "Attribute Store".
- In the table below, select "Token-Groups Unqualified Names" in the first column and type "roles" into the second column.
Configure OpenID Connect to provide specific user groups as claims
- Open the "AD FS Management" tool located under the "Tools" menu at the top right of the Server Manager.
- Select the "Application Groups" folder item in the left sidebar.
- Double click on the group added earlier, then double click on the "Web API" application.
- Select the tab named "Issuance Transform Rules".
- Remove any rules you may have already added.
- Click the "Add Rule..." button at the bottom.
- Select "Send Claims Using a Custom Rule" and click next.
- Give the rule the name "StoreRoles" and paste the following into the "Custom rule" field:
- c:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname", Issuer == "AD AUTHORITY"] => add(store = "Active Directory", types = ("roles"), query = ";tokenGroups;{0}", param = c.Value);
- Click finish and add yet another rule.
- Again, select "Send Claims Using a Custom Rule" and click next.
- Give this rule the name "IssueRoles" and paste the following into the "Custom rule" field:
- c:[Type == "roles", Value =~ "^Prefix.+"] => issue(claim = c);
- The part containing //"^Prefix.+"// is a regex expression used to filter the windows groups sent as part of the claims. In this case we only accept the windows groups starting with "Prefix". Adjust this to meet your needs.
- Click finish.