Git Product home page Git Product logo

Comments (12)

leastprivilege avatar leastprivilege commented on May 31, 2024

They should - all roles that don't start with "IdentityServer" should go in the token.

from identityserver2.

benfoster avatar benfoster commented on May 31, 2024

Looks like a bug, it is actually including roles that do start with "identityServer" :)

    public IEnumerable<string> GetRoles(string userName)
    {
        var returnedRoles = new List<string>();

        if (Roles.Enabled)
        {
            var roles = Roles.GetRolesForUser(userName);
            returnedRoles = roles.Where(role => role.StartsWith(Constants.Roles.InternalRolesPrefix)).ToList();    
        }

        return returnedRoles;
    }

from identityserver2.

leastprivilege avatar leastprivilege commented on May 31, 2024

This is the right code:

protected virtual IEnumerable GetRolesForToken(string userName)
{
var returnedRoles = new List();

if (Roles.Enabled)
{
    var roles = Roles.GetRolesForUser(userName);
    returnedRoles = roles.Where(role => !(role.StartsWith(Constants.Roles.InternalRolesPrefix))).ToList();
}

return returnedRoles;

}

in ProviderClaimsRepository.cs

from identityserver2.

benfoster avatar benfoster commented on May 31, 2024

Yes, was going to send a pull request but then you said to not bother until the beta :)

from identityserver2.

leastprivilege avatar leastprivilege commented on May 31, 2024

So I double checked the code - it is working fine here.

from identityserver2.

benfoster avatar benfoster commented on May 31, 2024

Perhaps it hasn't updated on GitHub? The code here is incorrect https://github.com/thinktecture/Thinktecture.IdentityServer.v2/blob/master/src/Libraries/Thinktecture.IdentityServer.Core.Repositories/ProviderUserRepository.cs

from identityserver2.

leastprivilege avatar leastprivilege commented on May 31, 2024

And you are looking at the wrong code.

This is the right file:
https://github.com/thinktecture/Thinktecture.IdentityServer.v2/blob/master/src/Libraries/Thinktecture.IdentityServer.Core.Repositories/ProviderClaimsRepository.cs

from identityserver2.

benfoster avatar benfoster commented on May 31, 2024

Yes that file is correct.

However, the instance of IUserRepository injected into ClaimsTransformer for me is of type ProviderUserRepository when requesting an OAuth2 token, not ProviderClaimsRepository.

from identityserver2.

leastprivilege avatar leastprivilege commented on May 31, 2024

The OAuth controller calls into sts.TryIssueToken. This ultimately invokes the logic in TokenService.cs - and this uses the claims repository. Put some breakpoints into TokenService.cs

from identityserver2.

benfoster avatar benfoster commented on May 31, 2024

You're right, it does call the ProviderClaimsRepository after calling ProviderUserRepository, I just hadn't stepped in that far. Why does it call Roles.GetRolesForUser twice?

from identityserver2.

leastprivilege avatar leastprivilege commented on May 31, 2024

There are two types of roles - the ones that start with IdentityServer are for internal use (authZ in the UI) - all the others are "for tokens".

from identityserver2.

benfoster avatar benfoster commented on May 31, 2024

Okay, thanks for clarifying, and your patience. I'll close the issue.

from identityserver2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.