simpleidserver / SimpleIdServer

OpenID, OAuth 2.0, SCIM2.0, UMA2.0, FAPI, CIBA & OPENBANKING Framework for ASP.NET Core
https://simpleidserver.com/
Apache License 2.0
708 stars 92 forks source link

How can I get the roles associated with a user? #525

Closed lechediaz closed 1 year ago

lechediaz commented 1 year ago

Hello friend,

I have created a role in my client, added it to a group and then associated it to a user, but I can't get the role.

I created a scope of type Identity Resource and added it to my client, but it does not work neither in singular or plural.

image

image

In the access_token it doesn't come, so I supposed I could look it up in the userinfo_endpoint but it doesn't come up either.

image

In the discovery enpoint there is no endpoint where to get this data.

lechediaz commented 1 year ago

I tried to save the scopes as API Resource type and it didn't work either.

lechediaz commented 1 year ago

I found that in the UserInfo controller there is a call to the ClaimsExtractor.ExtractClaims method and I think the problem is in getting the FullPath of the group, because it is splitting by dot "." instead of slash "/".

image

Tomorrow I will try to validate, if I find anything I will let you know.

simpleidserver commented 1 year ago

Hello,

There is no role in the claims because you probably didn't assign roles to the group.

A client can have one or more roles, they are used to define the permissions of your application, for example : administrator, guest etc... They can be added in the Client \ Roles screen. In your use case, the roles must be added to the condominiums client.

image

Once the roles are created, navigate to the group and assigned one or more roles.

image

You can can check the roles of a user by clicking on the checkbox Resolve roles. Resolved roles are highlighted in green

image

lechediaz commented 1 year ago

My client has two roles:

image

I'v assigned role to the group:

image

I assigned this group to my user:

image

That action created three claims:

image

Previously I had not checked the Resolve roles box, now I did and saved, then it created another claim.

image

Yet all this does not bring me the role in User Info endpoint.

image

simpleidserver commented 1 year ago

The issue about duplicate roles have been fixed (Ticket #526).

Fetch the latest changes from the branch origin/master and remove all the roles of the user. In the role scope, add a mapping rule. Click on the Add mapper button. In the popup window, select Attribute and click on next :

image

Complete the form like this and click on Save :

image

Now, the role scope should be configured.

lechediaz commented 1 year ago

Okay friend, I'll try it and let you know.

lechediaz commented 1 year ago

Hello,

After I got the changes and did what you told me to do, I assigned the group (with the previously associated role) to the user:

image

Then checked the Resolve roles box and saved:

image

Now, the UserInfo endpoint already brings me the role! :D but it does it twice

image

Then what I did was deleted the "role" claim at user:

image

image

Then when access_token is created, apparently creates the claim again, maybe that is what produces twice "role" key in UserInfo endpoint.

image

image

Still, it was a breakthrough and I could continue working on my project.

Thank you very much

simpleidserver commented 1 year ago

First thank you for your feedback :) Roles are duplicated when you're trying to get an access token because the EF Change Tracker Detects changes on the user and save the result.

The issue is fixed in the master branch & it is linked to this problem #526.

Can-you please fetch the latest changes made on the master branch ?

lechediaz commented 1 year ago

OK, I'll try it and let you know.

lechediaz commented 1 year ago

Hello,

Okay, I got the changes but unfortunately the problem persists.

image

Then I deleted my user's claims:

image

image

Then, I requested a new token and called the UserInfo endpoint and the role appears twice:

image

I checked and indeed re-created the Claim to the user.

image

If I request another token it creates another claim and a third role in the UserInfo:

image

simpleidserver commented 1 year ago

Strange, with the latest changes, the issue cannot be reproduced on my local machine. Did-you rebuild the Docker Image and deploy the latest version to your Server ? When auth code is used to get an access token and the userinfo is called, there is no duplicate role in the [dbo].[UserClaims] table.

lechediaz commented 1 year ago

mmm I'll check it again.

lechediaz commented 1 year ago

Oh, I'm so sorry, you were right I missed to load the correct image.tar file. It's working good.

I also noticed that it is not necessary to check the Resolve roles checkbox, with the attribute mapping it is enough and that is great (I don't know if the functionality of this checkbox is deprecated then).

image

Thank you!