Skip to content

Commit 5ddefe4

Browse files
committed
some changes to the configuration page
1 parent b34ea6a commit 5ddefe4

File tree

2 files changed

+91
-62
lines changed

2 files changed

+91
-62
lines changed

modules/ROOT/pages/directives/index.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ a| Required to differentiate interfaces that are used for relationship propertie
4040
| xref::/security/authorization.adoc[`@authorization`]
4141
| Specifies authorization rules for queries and mutations on the type.
4242

43-
| xref::/security/configuration.adoc#authentication-and-authorization-jwt[`@jwt`]
43+
| xref::/security/configuration.adoc#_the_jwt_directive[`@jwt`]
4444
| Configures the JWT authentication and authorization filters to include additional JWT claims.
4545

46-
| xref::/security/configuration.adoc#_nested_claims[`@jwtClaim`]
46+
| xref::/security/configuration.adoc#_the_jwtclaim_directive[`@jwtClaim`]
4747
| Used in combination with `@jwt`.
4848
Configures the JWT authentication and authorization filters to include an additional JWT claim which is either nested or using special characters not supported by GraphQL.
4949

modules/ROOT/pages/security/configuration.adoc

Lines changed: 89 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
= Configuration
22
:description: This page describes how to configure authentication and authorization features in the Neo4j GraphQL Library.
33

4+
The Neo4j GraphQL Library uses JSON Web Token (JWT) authentication.
5+
JWTs are tokens containing claims or statements about the user or client making the request.
6+
These claims can include information such as the user's ID or roles.
7+
8+
When a user or client logs in to the API, the API generates a JWT and returns it to the client.
9+
The client then includes the JWT with each subsequent request to the API.
10+
The API verifies the JWT and returns the requested data if the JWT is valid.
11+
12+
// ^ is this paragraph accurate?
13+
414
== Instantiation
515

6-
The Neo4j GraphQL Library can accept JSON Web Tokens via two mechanisms:
16+
The Neo4j GraphQL Library can accept two types of JWTs:
717

818
* Encoded JWTs in the `token` field of the request context.
919
* Decoded JWTs in the `jwt` field of the request context.
1020

11-
If using the former, the library will need to be configured with a key to decode and verify the token.
21+
=== Encoded JWTs
1222

13-
The following code block demonstrates using Apollo Server, extracting the `Authorization` header from the request, and putting it into the appropriate context field:
23+
To use encoded JWTs, the library must to be configured with a key to decode and verify the tokens.
24+
25+
The following code block uses Apollo Server, extracts the `Authorization` header from the request and puts it in the appropriate context field:
1426

1527
[source, typescript, indent=0]
1628
----
@@ -28,10 +40,14 @@ const { url } = await startStandaloneServer(server, {
2840

2941
Optionally, if a custom decoding mechanism is required, that same header can be decoded and the resulting JWT payload put into the `jwt` field of the context.
3042

31-
=== Symmetric secret
43+
// ^ Can we show the above in a code listing?
44+
45+
==== Symmetric secret
3246

3347
To configure the library with a symmetric secret (e.g. "secret"), the following instantiation is required:
3448

49+
// ^ What is a symmetric secret? What is its purpose?
50+
3551
[source, typescript, indent=0]
3652
----
3753
new Neo4jGraphQL({
@@ -44,9 +60,11 @@ new Neo4jGraphQL({
4460
});
4561
----
4662

47-
=== JWKS endpoint
63+
==== JWKS endpoint
4864

49-
To configure the library to verify tokens against a JWKS endpoint, "https://www.myapplication.com/.well-known/jwks.json", the following instantiation is required:
65+
To configure the library to verify tokens against a JWKS endpoint, for example "https://www.myapplication.com/.well-known/jwks.json", the following instantiation is required:
66+
67+
// ^ What is the purpose?
5068

5169
[source, typescript, indent=0]
5270
----
@@ -62,14 +80,66 @@ new Neo4jGraphQL({
6280
});
6381
----
6482

65-
[[authentication-and-authorization-jwt]]
66-
== JWT
83+
==== Passing in encoded JWTs
84+
85+
// This was at the end of the file, I thought it could be moved here instead. What about decoded JWTs?
86+
87+
To pass in an encoded JWT, use the token field of the context.
88+
When using Apollo Server, extract the authorization header into the token property of the context:
89+
90+
[source, javascript, indent=0]
91+
----
92+
const server = new ApolloServer({
93+
schema,
94+
});
95+
96+
await startStandaloneServer(server, {
97+
context: async ({ req }) => ({ token: req.headers.authorization }),
98+
});
99+
----
100+
101+
For example, a HTTP request with the following `authorization` header should look like this:
102+
103+
[source]
104+
----
105+
POST / HTTP/1.1
106+
authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJyb2xlcyI6WyJ1c2VyX2FkbWluIiwicG9zdF9hZG1pbiIsImdyb3VwX2FkbWluIl19.IY0LWqgHcjEtOsOw60mqKazhuRFKroSXFQkpCtWpgQI
107+
content-type: application/json
108+
----
109+
110+
Alternatively, you can pass a key `jwt` of type `JwtPayload` into the context, which has the following definition:
111+
112+
[source, typescript, indent=0]
113+
----
114+
// standard claims https://datatracker.ietf.org/doc/html/rfc7519#section-4.1
115+
interface JwtPayload {
116+
[key: string]: any;
117+
iss?: string | undefined;
118+
sub?: string | undefined;
119+
aud?: string | string[] | undefined;
120+
exp?: number | undefined;
121+
nbf?: number | undefined;
122+
iat?: number | undefined;
123+
jti?: string | undefined;
124+
}
125+
----
126+
127+
[WARNING]
128+
Do not pass in the header or the signature.
129+
130+
=== Decoded JWTs
131+
132+
// What could be added here?
133+
134+
== Adding JWT claims
67135

68136
By default, filtering is available on https://www.rfc-editor.org/rfc/rfc7519#section-4.1[the registered claim names] in the JWT specification.
69137

70138
Filtering can be configured for additional JWT claims using the `@jwt` directive and, in some circumstances, the `@jwtClaim` directive.
71139

72-
If you configure an additional `roles` claim, which is an array of strings located at the root of the JWT payload, the following must be added to the type definitions:
140+
=== The `@jwt` directive
141+
142+
If you configure an additional `roles` claim, which is an array of strings located at the root of the JWT payload, add the following to the type definitions:
73143

74144
[source, graphql, indent=0]
75145
----
@@ -78,11 +148,12 @@ type JWT @jwt {
78148
}
79149
----
80150

81-
Note that the type name here, `JWT`, is not required, and this can have any name as long as it is decorated with the `@jwt` directive.
151+
Note that the type name `JWT` is not required.
152+
You can use any name as long as it is decorated with the `@jwt` directive.
82153

83-
=== Nested claims
154+
=== The `@jwtClaim` directive
84155

85-
If the previous `roles` claim is not located at the JWT payload root, but instead in a nested location, for example:
156+
A `roles` claim is not necessarily located at the JWT payload root, but can instead be in a nested location, for example:
86157

87158
[source, json, indent=0]
88159
----
@@ -94,7 +165,9 @@ If the previous `roles` claim is not located at the JWT payload root, but instea
94165
}
95166
----
96167

97-
This needs to be configured using the `@jwtClaim` directive:
168+
// ^ why is this a nested location? can we show the nesting?
169+
170+
In this case, use the `@jwtClaim` directive:
98171

99172
[source, graphql, indent=0]
100173
----
@@ -103,7 +176,7 @@ type JWT @jwt {
103176
}
104177
----
105178

106-
Additionally, if this nested location contains any `.` characters in the path, for example:
179+
Additionally, the nested location may contain `.` characters in the path, for example:
107180

108181
[source, json, indent=0]
109182
----
@@ -115,7 +188,7 @@ Additionally, if this nested location contains any `.` characters in the path, f
115188
}
116189
----
117190

118-
These characters need to be escaped:
191+
Escape these characters:
119192

120193
[source, graphql, indent=0]
121194
----
@@ -126,50 +199,6 @@ type JWT @jwt {
126199

127200
[NOTE]
128201
====
129-
The seemingly excessive escaping is required to doubly escape: once for GraphQL and once for `dot-prop`, which is used under the hood to resolve the path.
202+
This way of escaping is necessary to escape twice: once for GraphQL and once for `dot-prop`, which is used under the hood to resolve the path.
130203
====
131204

132-
== Passing in JWTs
133-
134-
To pass in an encoded JWT, you must use the token field of the context.
135-
When using Apollo Server, extract the authorization header into the token property of the context as follows:
136-
137-
[source, javascript, indent=0]
138-
----
139-
const server = new ApolloServer({
140-
schema,
141-
});
142-
143-
await startStandaloneServer(server, {
144-
context: async ({ req }) => ({ token: req.headers.authorization }),
145-
});
146-
----
147-
148-
For example, a HTTP request with the following `authorization` header should look like this:
149-
150-
[source]
151-
----
152-
POST / HTTP/1.1
153-
authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJyb2xlcyI6WyJ1c2VyX2FkbWluIiwicG9zdF9hZG1pbiIsImdyb3VwX2FkbWluIl19.IY0LWqgHcjEtOsOw60mqKazhuRFKroSXFQkpCtWpgQI
154-
content-type: application/json
155-
----
156-
157-
Alternatively, you can pass a key `jwt` of type `JwtPayload` into the context, which has the following definition:
158-
159-
[source, typescript, indent=0]
160-
----
161-
// standard claims https://datatracker.ietf.org/doc/html/rfc7519#section-4.1
162-
interface JwtPayload {
163-
[key: string]: any;
164-
iss?: string | undefined;
165-
sub?: string | undefined;
166-
aud?: string | string[] | undefined;
167-
exp?: number | undefined;
168-
nbf?: number | undefined;
169-
iat?: number | undefined;
170-
jti?: string | undefined;
171-
}
172-
----
173-
174-
[WARNING]
175-
_Do not_ pass in the header or the signature.

0 commit comments

Comments
 (0)