Skip to content

Commit

Permalink
Always use ?. with 'jwt' in argument injection (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
AleF83 authored Jan 5, 2021
1 parent 6f42ba8 commit 74ce7a8
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/arguments_injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ query {
```graphql
# Schema
type Query {
foo: String! @localResolver(value: "{jwt.roles}") # foo field will be resolved to roles claim of the request JWT.
foo: String! @localResolver(value: "{jwt?.roles}") # foo field will be resolved to roles claim of the request JWT.
}

#Query
Expand Down
2 changes: 1 addition & 1 deletion docs/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ code: |
args:
aud:
type: String!
default: '{jwt.aud}'
default: '{jwt?.aud}'
allowedAudience:
type: String!
```
Expand Down
4 changes: 2 additions & 2 deletions docs/authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ code: |
args:
userRoles:
type: [String!]
default: '{jwt.roles}'
default: '{jwt?.roles}'
```
Explanation:
Expand Down Expand Up @@ -148,7 +148,7 @@ So if in type `User` there is field `phone` that should be accessible for user w
type User {
id: ID!
name: String!
phone: String @policy(namespace: "billing", name: "adminOnly", args: { userRoles: "{jwt.roles}" })
phone: String @policy(namespace: "billing", name: "adminOnly", args: { userRoles: "{jwt?.roles}" })
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ For example this plugin adds a base policy if one does not exist:
namespace: 'ns',
name: 'base',
args: {
user: '{jwt.sub}',
user: '{jwt?.sub}',
},
}};
}
Expand Down
8 changes: 4 additions & 4 deletions docs/specs/authorization_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ Spec:
args:
issuer:
type: String!
default: "{jwt.issuer}"
default: "{jwt?.issuer}"
```
The `args` are available to use on the input object.
`jwt` is available for parameter injection in args using `issuer: "{jwt.issuer}"`
`jwt` is available for parameter injection in args using `issuer: "{jwt?.iss}"`
### Policy that allows access only if the subject matches the provided userId argument:
Expand Down Expand Up @@ -163,7 +163,7 @@ type User {
ID: ID!
Picture: String @policy-some-ns-public
Friends: [User] @policy-some-ns-abc-user
Email: String @policy-some-ns-my-user(userId: "{source.UserId}", sub: "{jwt.sub}")
Email: String @policy-some-ns-my-user(userId: "{source.UserId}", sub: "{jwt?.sub}")
NickName: @policy-some-ns-my-user-family(userId: "{source.UserId}")
}
```
Expand Down Expand Up @@ -297,6 +297,6 @@ Usage:
```gql
type User {
ID: ID!
Picture: String @policy-some-ns-has-claims(claims:["issuer", "sub"], values: ["soluto.com", "{source.UserId}"], jwtClaims: "{jwt.claims}")
Picture: String @policy-some-ns-has-claims(claims:["issuer", "sub"], values: ["soluto.com", "{source.UserId}"], jwtClaims: "{jwt?.claims}")
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { inject } from './arguments-injection';

interface TestCase {
input: unknown;
params: GraphQLFieldResolverParams<unknown, Pick<RequestContext, 'request' | 'exports' | 'request'>>
params: GraphQLFieldResolverParams<unknown, Pick<RequestContext, 'request' | 'exports' | 'request'>>;
expected: unknown;
}

Expand Down Expand Up @@ -62,7 +62,7 @@ const testCases: [string, TestCase][] = [
[
'From JWT',
{
input: '{jwt.email}',
input: '{jwt?.email}',
params: {
source: null,
args: {},
Expand Down

0 comments on commit 74ce7a8

Please sign in to comment.