0
services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddRoles<ApplicationRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>();
        services.AddIdentityServer()
            .AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
        services.AddAuthentication()
            .AddIdentityServerJwt();
        services.Configure<JwtBearerOptions>(
IdentityServerJwtConstants.IdentityServerJwtBearerScheme,
options =>
{
    var onTokenValidated = options.Events.OnTokenValidated;
    options.Events.OnTokenValidated = async context =>
    {
        await onTokenValidated(context);
    };
});
        services.ConfigureApplicationCookie(o => {
            o.ExpireTimeSpan = TimeSpan.FromDays(5);
            o.SlidingExpiration = true;
        });
        services.Configure<DataProtectionTokenProviderOptions>(o =>
   o.TokenLifespan = TimeSpan.FromHours(3));

can please someone show to me how to get current logged in user /token? Any help will be appreciated

hiolk ygj
  • 1
  • 1
  • 1
    Did you try this https://stackoverflow.com/questions/21404935/mvc-5-access-claims-identity-user-data – SelvaS Jun 16 '20 at 22:27
  • it doesn t work – hiolk ygj Jun 17 '20 at 14:30
  • 1
    You'll probably only find the `sub` claim which contains the User Id. For user name you need to make sure to request to 'profile' scope and include the claims in the access token. For certain clients you can use `options.GetClaimsFromUserInfoEndpoint = true`, you can include claims with configuration (ApiClaims) or otherwise implement the IProfileService to add the claim. Perhaps this [question](https://stackoverflow.com/questions/53976553/identityserver4-role-based-authorization-for-web-api-with-asp-net-core-identity) is helpful. –  Jun 17 '20 at 20:47

0 Answers0