Comments (7)
It worked! I had missed: app.UseAuthentication();
and I was passing the Authorization header wrongly. Thank you!
from authorization.
@kmanev073 I'm getting same thing, I have added app.UseAuthentication(); didn't work, When I add
var result1 = await httpContext.AuthenticateAsync("Bearer"); in Validation rule then setting the prinicpal to current http context. then claims got populated
I'm not sure what is the best solution and I need it part of ValidationRule or some where global in The GraphQL middlware any help really appreciated
from authorization.
{ "roles", JsonConvert.SerializeObject(user.GetRolesByCompanyId(companyId)) }
My understanding is that would create a roles
claim with multiple values, assuming that serializes to an array. The example uses a singular role
claim.
Did you try matching the name of the claim to your roles
? At a minimum, the name of the claims have to match.
from authorization.
{ "roles", JsonConvert.SerializeObject(user.GetRolesByCompanyId(companyId)) }
My understanding is that would create a
roles
claim with multiple values, assuming that serializes to an array. The example uses a singularrole
claim.Did you try matching the name of the claim to your
roles
? At a minimum, the name of the claims have to match.
Yeah this just creates an array of strings (the role names) and places it inside the token. I should be able access my token claims with context.UserContext.Claims
from inside a mutation for example, however my roles aren't there.
from authorization.
Is it populated at all? Is any of the information there?
from authorization.
Is it populated at all? Is any of the information there?
Here is a screenshot of my context: https://i.imgur.com/lp6Noch.png
And here's how my JWT looks:
{
"sub": "3ced78d7-f611-4099-95e0-59e49279cf92",
"iss": "System",
"iat": 1542147174,
"exp": 1542190374,
"company": "8c7a1275-ba67-47a2-ad8f-d452416b98e9",
"roles": "[\"Administrator\"]"
}
And I this is my policy:
authSettings.AddPolicy("AdministratorPolicy", _ => _.RequireClaim("roles", "Administrator"));
from authorization.
If you look at that screenshot the Identity.IsAuthenticated
is false. That means the ClaimsPrincipal
is not getting populated. How have you configured your JwtBearer
authentication? Is it set to be enabled by default?
You're passing that in a http Authorization
header? You should see the ASP.NET Core JwtBearer middleware handling the request in logs.
Authorization Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IkY0NTI2Qj...
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(cfg =>
{
cfg.TokenValidationParameters = new TokenValidationParameters()
{
ValidateIssuer = true,
ValidIssuer = _config["Security:Tokens:Issuer"],
ValidateAudience = true,
ValidAudience = _config["Security:Tokens:Audience"],
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Security:Tokens:Key"])),
};
});
from authorization.
Related Issues (20)
- Checking for a valid JWT and integrating with a Refresh-Token-Workflow HOT 10
- UNAUTHENTICATED error code HOT 3
- In AuthorizationValidationRule.cs the method CheckAuth is called multiple times. Why? HOT 4
- ETA for v4? HOT 18
- IAuthorizationRequirement is not sent the same variable names as those in IResolveField context HOT 2
- ClaimsPrincipal not retrived trying to use AuthorizeWith in GraphQL queries HOT 6
- Any example for schema first auth example? HOT 2
- How to get a status code 401 when not authorized HOT 6
- Move GraphQLAuthExtensions from Harness into new package HOT 6
- Add docs about IAuthorizationSkipCondition and DI
- Method 'ValidateAsync' in type 'GraphQL.Authorization.AuthorizationValidationRule' from assembly 'GraphQL.Authorization, Version=4.0.0.0 HOT 7
- Question: AuthorizeWithPolicy is being ignored HOT 10
- GraphQL .net authorization with JWT token HOT 7
- AddGraphQLAuth no longer works after switching to Middleware HOT 1
- Return 401 and 403 status code HOT 5
- Is this library still relevant with GraphQL 7+ HOT 22
- Tag 2.1.29 Release? HOT 7
- Graphql Authorization not working HOT 4
- Faulty reference HOT 6
- How to login user and return token and id ? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from authorization.