Skip to content

Commit d9a575f

Browse files
committed
Add authentication provider and usage docs
1 parent f395215 commit d9a575f

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

modules/ROOT/content-nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
** xref:aura-graphql-data-apis/prerequisites.adoc[]
6363
** xref:aura-graphql-data-apis/deploy-and-operate.adoc[]
6464
** xref:aura-graphql-data-apis/authentication-providers.adoc[]
65+
** xref:aura-graphql-data-apis/using-your-api.adoc[]
6566
6667
* xref:introspector.adoc[Introspector]
6768
Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,79 @@
11
[[auth-providers]]
2-
= Authentication Providers
2+
= Authentication Providers
3+
4+
GraphQL for Neo4j AuraDB allows you to use an API key, JWT token from an external identity provider or both for authentication and switch between them as needed. The authentication method is stored as an authentication provider.
5+
6+
There are advantages and disadvantages of both types. API keys are quick to start working with but do not allow for access controls. JWKS (JSON Web Key Sets) authentication providers require an external identity provider but do allow for fine grained rules around authentication/authorization.
7+
8+
[NOTE]
9+
====
10+
`--data-api-id` is used with the `aura-cli` when working with authentication providers rather than `--graphql-api-id` as you might have expected. Conceptually a graphql api is a type of data api and there may be other types in the future. Using `--data-api-id` allows for flexibility for potential future development work in this area.
11+
====
12+
13+
== Create a JWKS Authentication Provider
14+
15+
Before using JWKS, it is necessary to set up and configure an identity provider that manages users and their credentials securely, issues JWTs to authenticated users, and hosts a JWKS endpoint that is can be used to validate JWTs by the GraphQL API. There are several 3rd parties who provide this type of service, e.g Ping, Okta, Auth0 and any of the main cloud service providers. Configuration of identity providers is beyond the scope of this guide.
16+
17+
If you do use a JWKS authentication provider, then you can take advantage of fine-grained access controls using the ** xref:security/authentication.adoc[`@authentication`]/** xref:security/authorization.adoc[`@authorization`] directives of Graphql for Neo4j AuraDB.
18+
19+
[NOTE]
20+
====
21+
If you do make use of `@authentication`/`@authorization` rules, they will also be applied to requests made with API keys. We do not currently support adding claims to API keys so it is unlikely they will be able to meet the rules you specify.
22+
====
23+
24+
The aura-cli is used to create a new JWKS authentication provider. You will need the JWKS URL to do this along with the ID of the GraphQL API with it’s associated AuraDB ID.
25+
26+
At a command prompt, type the following, swapping out the UPPERCASE values for your own:
27+
28+
[source, bash, indent=0]
29+
----
30+
aura-cli data-api graphql auth-provider create --data-api-id YOUR_GRAPHQL_DATA_API_ID --instance-id YOUR_AURA_INSTANCE_ID --name AUTH_PROVIDER_FRIENDLY_NAME --type jwks --url JWKS_URL
31+
----
32+
33+
On success, the command will respond with details about the newly created JWKS provider.
34+
35+
== Create an API Key Authentication Provider
36+
37+
When a new GraphQL API is created via the aura-cli, an API Key authentication provider is the default. However, if you require a new one, this command allows you to create a new API Key.
38+
39+
At a command prompt, type the following, swapping out the UPPERCASE values for your own:
40+
41+
[source, bash, indent=0]
42+
----
43+
aura-cli data-api graphql auth-provider create --data-api-id YOUR_GRAPHQL_DATA_API_ID --instance-id YOUR_AURA_INSTANCE_ID --name AUTH_PROVIDER_FRIENDLY_NAME --type api-key
44+
----
45+
46+
On success, the command will respond with details about the newly created API Key.
47+
48+
[NOTE]
49+
====
50+
Make sure to record the API key shown in the response as it will not be displayed again.
51+
====
52+
53+
== List Authentication Providers
54+
55+
To see the list of authentication providers for a given GraphQL API use the following, exchanging UPPERCASE values for your own.
56+
57+
[source, bash, indent=0]
58+
----
59+
aura-cli data-api graphql auth-provider list --data-api-id YOUR_GRAPHQL_DATA_API_ID --instance-id YOUR_AURA_INSTANCE_ID
60+
----
61+
62+
== Delete an Authentication Provider
63+
64+
An authentication provider for a GraphQL API can be removed by deleting it. At least one enabled authentication provider is required for a GraphQL API.
65+
66+
. Find the API authentication provider ID
67+
+
68+
[source, bash, indent=0]
69+
----
70+
aura-cli data-api graphql auth-provider list --data-api-id YOUR_GRAPHQL_DATA_API_ID --instance-id YOUR_AURA_INSTANCE_ID --output table
71+
----
72+
+
73+
. From the table, locate ID for the authentication provider that you wish to delete
74+
. Delete the API key provider with this aura-cli statement
75+
+
76+
[source, bash, indent=0]
77+
----
78+
aura-cli data-api graphql auth-provider delete AUTH-PROVIDER-ID --data-api-id YOUR_GRAPHQL_DATA_API_ID --instance-id YOUR_AURA_INSTANCE_ID
79+
----
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
= Using your GraphQL API
2+
3+
Once the status for the GraphQL API is `ready` you can send GraphQL requests to it. As all requests are subject to authentication, you must include an API key or JWT token.
4+
5+
== With an API Key Authentication Provider
6+
7+
Add `x-api-key: YOUR_API_KEY` to the header of the request. For example, with curl replacing the UPPERCASE values with those of your own:
8+
9+
[source, bash, indent=0]
10+
----
11+
curl --location YOUR_GRAPHQL_API_URL --header 'Content-Type: application/json' --header 'x-api-key: YOUR_API_KEY' --data 'YOUR_GRAPHQL_QUERY'
12+
----
13+
14+
== With a JWKS Authentication Provider
15+
16+
Obtain a JWT from your identity provider. Using the JWT, add `Authorization: Bearer YOUR_JWT` to the headers of the request.
17+
18+
For example, with curl replacing the UPPERCASE values with those of your own:
19+
20+
[source, bash, indent=0]
21+
----
22+
curl --location YOUR_GRAPHQL_API_URL --header 'Authorization: Bearer YOUR_JWT'--header 'Content-Type: application/json --data 'YOUR_GRAPHQL_QUERY'
23+
----

0 commit comments

Comments
 (0)