LIFE
LIFE
KKinde
Created by LIFE on 5/8/2024 in #💻┃support
Unable to retrieve claims & identity from token
Thank you! Yeah it was Microsoft.AspNetCore.Authentication.JwtBearer which was causing the issue. Sorry to drag you in this, automatically assumed it was a kinde related problem. Really appreciate the help
16 replies
KKinde
Created by LIFE on 5/8/2024 in #💻┃support
Unable to retrieve claims & identity from token
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
<PackageReference Include="Swashbuckle.Core" Version="5.6.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.SpaProxy">
<Version>8.*-*</Version>
</PackageReference>
<PackageReference Include="Microsoft.OpenApi" Version="1.6.14" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Twilio" Version="7.0.4" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
<PackageReference Include="Swashbuckle.Core" Version="5.6.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.SpaProxy">
<Version>8.*-*</Version>
</PackageReference>
<PackageReference Include="Microsoft.OpenApi" Version="1.6.14" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Twilio" Version="7.0.4" />
</ItemGroup>
16 replies
KKinde
Created by LIFE on 5/8/2024 in #💻┃support
Unable to retrieve claims & identity from token
could it be related to: https://stackoverflow.com/a/78063798/3712531
What should happen next is that your .NET API calls the discovery endpoint at the path .well-known/openid-configuration. Then the jwks_uri value is stored.
And that the .NET API is unable to find the jwks?
16 replies
KKinde
Created by LIFE on 5/8/2024 in #💻┃support
Unable to retrieve claims & identity from token
No description
16 replies
KKinde
Created by LIFE on 5/8/2024 in #💻┃support
Unable to retrieve claims & identity from token
No description
16 replies
KKinde
Created by LIFE on 5/8/2024 in #💻┃support
Unable to retrieve claims & identity from token
Not a problem :)
16 replies
KKinde
Created by LIFE on 5/8/2024 in #💻┃support
Unable to retrieve claims & identity from token
I see, thanks for the update!
16 replies
KKinde
Created by LIFE on 5/8/2024 in #💻┃support
Unable to retrieve claims & identity from token
yes, no hurry. Thank you Oli!
16 replies
KKinde
Created by LIFE on 5/8/2024 in #💻┃support
Unable to retrieve claims & identity from token
i failed to mention that it currently works in production, but not locally. But it has worked locally too
16 replies
KKinde
Created by LIFE on 3/23/2024 in #💻┃support
How to get organization name in React SDK
oops, my last message wasn't sent: Figured it out, you have to customize your access_token
4 replies
KKinde
Created by LIFE on 3/5/2024 in #💻┃support
error: getuser is not a function
20 replies
KKinde
Created by LIFE on 3/5/2024 in #💻┃support
error: getuser is not a function
Of course! I totally forgot about
const {user} = useKindeAuth();
const {user} = useKindeAuth();
Went to the docs and found getUser()... Thanks for the help!
20 replies
KKinde
Created by LIFE on 12/18/2023 in #💻┃support
Automatically set token in header
That is great, isLoading was the missing key! Appreciate the explanation of the authentication flow🫶
5 replies
KKinde
Created by LIFE on 12/6/2023 in #💻┃support
Resolving auth in back-end (.NET) with token retrieved from front-end (React)
was able to "solve" it with this, but i'm uncertain if there are better solutions to the problem: GitHub Copilot: To authorize based on the "name" value in the "roles" claim, you would need to parse the claim value as JSON and check the "name" field. However, the built-in RequireClaim method doesn't support this kind of complex claim value checking. You will need to create a custom IAuthorizationRequirement and AuthorizationHandler to handle this. Here's an example of how you can do it:
public class RolesRequirement : IAuthorizationRequirement
{
public string RoleName { get; }

public RolesRequirement(string roleName)
{
RoleName = roleName;
}
}

public class RolesHandler : AuthorizationHandler<RolesRequirement>
{
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, RolesRequirement requirement)
{
var rolesClaim = context.User.Claims.FirstOrDefault(c => c.Type == "roles");
if (rolesClaim != null)
{
var roles = JsonSerializer.Deserialize<Dictionary<string, string>>(rolesClaim.Value);
if (roles != null && roles.TryGetValue("name", out var roleName) && roleName == requirement.RoleName)
{
context.Succeed(requirement);
}
}

return Task.CompletedTask;
}
}
public class RolesRequirement : IAuthorizationRequirement
{
public string RoleName { get; }

public RolesRequirement(string roleName)
{
RoleName = roleName;
}
}

public class RolesHandler : AuthorizationHandler<RolesRequirement>
{
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, RolesRequirement requirement)
{
var rolesClaim = context.User.Claims.FirstOrDefault(c => c.Type == "roles");
if (rolesClaim != null)
{
var roles = JsonSerializer.Deserialize<Dictionary<string, string>>(rolesClaim.Value);
if (roles != null && roles.TryGetValue("name", out var roleName) && roleName == requirement.RoleName)
{
context.Succeed(requirement);
}
}

return Task.CompletedTask;
}
}
Then, you can add the requirement and handler to your services and use them in your policy:
builder.Services.AddSingleton<IAuthorizationHandler, RolesHandler>();
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("admin", policy => policy.Requirements.Add(new RolesRequirement("admin")));
});
builder.Services.AddSingleton<IAuthorizationHandler, RolesHandler>();
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("admin", policy => policy.Requirements.Add(new RolesRequirement("admin")));
});
This will create a policy named "admin" that requires the "roles" claim to have a "name" field with the value "admin".
49 replies
KKinde
Created by LIFE on 12/6/2023 in #💻┃support
Resolving auth in back-end (.NET) with token retrieved from front-end (React)
No description
49 replies
KKinde
Created by LIFE on 12/6/2023 in #💻┃support
Resolving auth in back-end (.NET) with token retrieved from front-end (React)
No description
49 replies
KKinde
Created by LIFE on 12/6/2023 in #💻┃support
Resolving auth in back-end (.NET) with token retrieved from front-end (React)
No description
49 replies
KKinde
Created by LIFE on 12/6/2023 in #💻┃support
Resolving auth in back-end (.NET) with token retrieved from front-end (React)
Thought that was handled by kinde?
49 replies
KKinde
Created by LIFE on 12/6/2023 in #💻┃support
Resolving auth in back-end (.NET) with token retrieved from front-end (React)
No description
49 replies
KKinde
Created by LIFE on 12/6/2023 in #💻┃support
Resolving auth in back-end (.NET) with token retrieved from front-end (React)
Seems like audience is empty in the token
49 replies