|
1 | 1 | [[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 | +---- |
0 commit comments