Coder Social home page Coder Social logo

Comments (13)

maliming avatar maliming commented on June 26, 2024

hi

Can you share the code to reproduce?

There should be no userId in client_credentials flow.

from abp.

mrh520 avatar mrh520 commented on June 26, 2024

Thanks for reply.

I just rewrote this method

public class AppTokenController : TokenController
{
protected override async Task HandleClientCredentialsAsync(OpenIddictRequest request)
{
// Note: the client credentials are automatically validated by OpenIddict:
// if client_id or client_secret are invalid, this action won't be invoked.
var application = await ApplicationManager.FindByClientIdAsync(request.ClientId);
if (application == null)
{
throw new InvalidOperationException(L["TheApplicationDetailsCannotBeFound"]);
}

    // Create a new ClaimsIdentity containing the claims that
    // will be used to create an id_token, a token or a code.
    var identity = new ClaimsIdentity(
        TokenValidationParameters.DefaultAuthenticationType,
        OpenIddictConstants.Claims.PreferredUsername,
        OpenIddictConstants.Claims.Role);

    // The Subject and PreferredUsername will be removed by <see cref="RemoveClaimsFromClientCredentialsGrantType"/>.
    // Use the client_id as the subject identifier.
    identity.AddClaim(OpenIddictConstants.Claims.Subject, await ApplicationManager.GetClientIdAsync(application));
    identity.AddClaim(OpenIddictConstants.Claims.PreferredUsername, await ApplicationManager.GetDisplayNameAsync(application));
    identity.AddClaim(OpenIddictApplicationConstants.Claims.CustomerId, await ApplicationManager.GetCustomerIdAsync(application) ?? "");

    // Note: In the original OAuth 2.0 specification, the client credentials grant
    // doesn't return an identity token, which is an OpenID Connect concept.
    //
    // As a non-standardized extension, OpenIddict allows returning an id_token
    // to convey information about the client application when the "openid" scope
    // is granted (i.e specified when calling principal.SetScopes()). When the "openid"
    // scope is not explicitly set, no identity token is returned to the client application.

    // Set the list of scopes granted to the client application in access_token.
    var principal = new ClaimsPrincipal(identity);

    principal.SetScopes(request.GetScopes());
    principal.SetResources(await GetResourcesAsync(request.GetScopes()));

    await OpenIddictClaimsPrincipalManager.HandleAsync(request, principal);

    return SignIn(principal, OpenIddictServerAspNetCoreDefaults.AuthenticationScheme);
}

}

from abp.

maliming avatar maliming commented on June 26, 2024

Make sure there is no userId claim in your principal.

from abp.

mrh520 avatar mrh520 commented on June 26, 2024

I did not find userId in the rewrite method debugging

from abp.

maliming avatar maliming commented on June 26, 2024

Please share the full error stack or a simple test project.

from abp.

mrh520 avatar mrh520 commented on June 26, 2024

thinks.
this error cannot be replicated locally ,no error log was recorded for local debugging.
Can you determine whether to search user information according to granttype

from abp.

maliming avatar maliming commented on June 26, 2024

There is no user concept in the client_credentials flow.

from abp.

mrh520 avatar mrh520 commented on June 26, 2024

claim type sub mapTo userId ?

from abp.

mrh520 avatar mrh520 commented on June 26, 2024

Make sure there is no userId claim in your principal.

image

from abp.

maliming avatar maliming commented on June 26, 2024

This seems to be a problem. I will find a way to fix this.

from abp.

mrh520 avatar mrh520 commented on June 26, 2024

will this issue be resolved in the future?

from abp.

maliming avatar maliming commented on June 26, 2024

See #20045

from abp.

mrh520 avatar mrh520 commented on June 26, 2024

thank you

from abp.

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.