| 
 | 1 | +[[auth-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.  | 
 | 5 | +The authentication method is stored as an authentication provider.  | 
 | 6 | + | 
 | 7 | +There are advantages and disadvantages to both types.  | 
 | 8 | +API keys are quickly set up but do not allow for access control and should not be used within a user-facing client application.  | 
 | 9 | +JWKS (JSON Web Key Sets) authentication providers require an external identity provider but do allow for fine-grained rules around authentication/authorization.  | 
 | 10 | + | 
 | 11 | +[NOTE]  | 
 | 12 | +====  | 
 | 13 | +`--data-api-id` is used with the `aura-cli` when working with authentication providers rather than `--graphql-api-id` as you might have expected.  | 
 | 14 | +Conceptually a GraphQL API is a type of data API and there may be other types in the future.  | 
 | 15 | +Using `--data-api-id` allows for flexibility for potential future development work in this area.  | 
 | 16 | +====  | 
 | 17 | + | 
 | 18 | +== Creating a JWKS authentication provider  | 
 | 19 | + | 
 | 20 | +Before using JWKS authentication providers, you must set up and configure an identity provider that:  | 
 | 21 | + | 
 | 22 | + * manages users and their credentials securely,  | 
 | 23 | + * issues JWTs to authenticated users  | 
 | 24 | + * hosts a JWKS endpoint that can be used to validate JWTs by the GraphQL API.  | 
 | 25 | +   | 
 | 26 | + There are several 3rd parties who provide this type of service, e.g. Ping, Okta, Auth0 and any of the main cloud service providers.  | 
 | 27 | + Configuration of identity providers is beyond the scope of this guide.  | 
 | 28 | + | 
 | 29 | +If you do use a JWKS authentication provider, you can take advantage of fine-grained access controls using the xref:security/authentication.adoc[`@authentication`] and xref:security/authorization.adoc[`@authorization`] directives of GraphQL for Neo4j AuraDB.  | 
 | 30 | + | 
 | 31 | +[NOTE]  | 
 | 32 | +====  | 
 | 33 | +If you make use of `@authentication` or `@authorization` rules, they are also applied to requests made with API keys.  | 
 | 34 | +We do not currently support adding claims to API keys so it is unlikely they are able to meet the rules you specify.  | 
 | 35 | +====  | 
 | 36 | + | 
 | 37 | +The aura-cli is used to create a new JWKS authentication provider.  | 
 | 38 | +You will need the JWKS URL to do this along with the ID of the GraphQL API with its associated AuraDB ID.  | 
 | 39 | + | 
 | 40 | +At a command prompt, type the following, swapping out the UPPERCASE values for your own:  | 
 | 41 | + | 
 | 42 | +[source, bash, indent=0]  | 
 | 43 | +----  | 
 | 44 | +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  | 
 | 45 | +----  | 
 | 46 | + | 
 | 47 | +On success, the command responds with details about the newly created JWKS provider.  | 
 | 48 | + | 
 | 49 | +== Creating an API Key Authentication Provider  | 
 | 50 | + | 
 | 51 | +[WARNING]  | 
 | 52 | +====  | 
 | 53 | +If you use an API key authentication provider in a user-facing client application, you risk leaking the API key to your users.  | 
 | 54 | +This can give them full access to your GraphQL API.  | 
 | 55 | +We recommend you to use JWKS authentication providers in user-facing client applications.  | 
 | 56 | +====  | 
 | 57 | + | 
 | 58 | +When a new GraphQL API is created via the aura-cli, an API key authentication provider is the default.  | 
 | 59 | +However, if you require a new one, the following command allows you to create a new API Key.  | 
 | 60 | + | 
 | 61 | +At a command prompt, type the following, swapping out the UPPERCASE values for your own:  | 
 | 62 | + | 
 | 63 | +[source, bash, indent=0]  | 
 | 64 | +----  | 
 | 65 | +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  | 
 | 66 | +----  | 
 | 67 | + | 
 | 68 | +On success, the command will respond with details about the newly created API Key.  | 
 | 69 | + | 
 | 70 | +[NOTE]  | 
 | 71 | +====  | 
 | 72 | +Make sure to record the API key shown in the response as it will not be displayed again.  | 
 | 73 | +====  | 
 | 74 | + | 
 | 75 | +== Listing authentication providers  | 
 | 76 | + | 
 | 77 | +To see the list of authentication providers for a given GraphQL API use the following, exchanging UPPERCASE values for your own.  | 
 | 78 | + | 
 | 79 | +[source, bash, indent=0]  | 
 | 80 | +----  | 
 | 81 | +aura-cli data-api graphql auth-provider list --data-api-id YOUR_GRAPHQL_DATA_API_ID --instance-id YOUR_AURA_INSTANCE_ID  | 
 | 82 | +----  | 
 | 83 | + | 
 | 84 | +== Deleting an authentication provider  | 
 | 85 | + | 
 | 86 | +An authentication provider for a GraphQL API can be removed by deleting it.  | 
 | 87 | +At least one enabled authentication provider is required for a GraphQL API.  | 
 | 88 | + | 
 | 89 | +. Find the API authentication provider ID.  | 
 | 90 | ++  | 
 | 91 | +[source, bash, indent=0]  | 
 | 92 | +----  | 
 | 93 | +aura-cli data-api graphql auth-provider list --data-api-id YOUR_GRAPHQL_DATA_API_ID --instance-id YOUR_AURA_INSTANCE_ID --output table  | 
 | 94 | +----  | 
 | 95 | ++  | 
 | 96 | +. From the table, locate the ID for the authentication provider that you wish to delete.  | 
 | 97 | +. Delete the API key provider with the following aura-cli statement.  | 
 | 98 | ++  | 
 | 99 | +[source, bash, indent=0]  | 
 | 100 | +----  | 
 | 101 | +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  | 
 | 102 | +----  | 
0 commit comments