Skip to main content
Version: v3.x beta

AuthConfig

Introduction

The AuthConfig object is used to define the authentication configuration used by the API. With Hasura, you can utilize either webhooks or JWTs for authentication. Your AuthConfig object belongs to the supergraph and, as such, lives in the /supergraph subdirectory of a project.

By default, all projects are created with an AuthConfig object that utilizes Hasura DDN's webhook for authentication. However, in production, you will want to use your own custom webhook or JWT service for authentication. The metadata examples below can help you configure your AuthConfig object to use your own custom webhook or JWT service.

You can learn more about Hasura's approach to using existing authentication systems in the authentication section.

LSP-assisted authoring

Authentication options can be complex. As your AuthConfig object is written in an HML file, if you're using a compatible editor (such as VS Code with the Hasura extension), LSP-assisted authoring will help you write AuthConfig more efficiently. LSP will provide you with auto-completion, syntax highlighting, and error checking as you create this object.

Metadata structure

AuthConfig

Definition of the authentication configuration used by the API server.

KeyValueRequiredDescription
kindAuthConfigtrue
versionv1true
definitionAuthConfigV1trueDefinition of the authentication configuration used by the API server.

AuthConfigV1

Definition of the authentication configuration used by the API server.

KeyValueRequiredDescription
allowRoleEmulationByRole / nullfalse
modeAuthModeConfigtrueThe configuration for the authentication mode to use - webhook or JWT.

AuthModeConfig

The configuration for the authentication mode to use - webhook or JWT.

Must have exactly one of the following fields:

KeyValueRequiredDescription
webhookAuthHookConfigfalseThe configuration of the authentication webhook.
jwtJWTConfigfalseJWT config according to which the incoming JWT will be verified and decoded to extract the session variable claims.

JWTConfig

JWT config according to which the incoming JWT will be verified and decoded to extract the session variable claims.

KeyValueRequiredDescription
audience[string] / nullfalseOptional validation to check that the aud field is a member of the audience received, otherwise will throw error.
issuerstring / nullfalseOptional validation to check that the iss field is a member of the iss received, otherwise will throw error.
allowedSkewinteger / nullfalseAllowed leeway (in seconds) to the exp validation to account for clock skew.
claimsConfigJWTClaimsConfigtrueClaims config. Either specified via claims_mappings or claims_namespace_path
tokenLocationJWTTokenLocationtrueSource of the JWT authentication token.
keyJWTKeytrueMode according to which the JWT auth is configured.

Example:

audience: null
issuer: null
allowedSkew: null
claimsConfig:
namespace:
claimsFormat: Json
location: /https:~1~1hasura.io~1jwt~1claims
tokenLocation:
type: BearerAuthorization
key:
fixed:
algorithm: HS256
key:
value: token

JWTKey

JWT key configuration according to which the incoming JWT will be decoded.

Must have exactly one of the following fields:

KeyValueRequiredDescription
fixedJWTKeyConfigfalseJWT Secret config according to which the incoming JWT will be decoded.
jwkFromUrlstringfalse

JWTKeyConfig

JWT Secret config according to which the incoming JWT will be decoded.

KeyValueRequiredDescription
algorithmJWTAlgorithmtrueThe algorithm used to decode the JWT.
keyEnvironmentValuetrueThe key to use for decoding the JWT.

EnvironmentValue

Either a literal string or a reference to a Hasura secret

Must have exactly one of the following fields:

KeyValueRequiredDescription
valuestringfalse
valueFromEnvstringfalse

JWTAlgorithm

The algorithm used to decode the JWT.

One of the following values:

ValueDescription
HS256HMAC using SHA-256
HS384HMAC using SHA-384
HS512HMAC using SHA-512
ES256ECDSA using SHA-256
ES384ECDSA using SHA-384
RS256RSASSA-PKCS1-v1_5 using SHA-256
RS384RSASSA-PKCS1-v1_5 using SHA-384
RS512RSASSA-PKCS1-v1_5 using SHA-512
PS256RSASSA-PSS using SHA-256
PS384RSASSA-PSS using SHA-384
PS512RSASSA-PSS using SHA-512
EdDSAEdwards-curve Digital Signature Algorithm (EdDSA)

JWTTokenLocation

Source of the Authorization token

One of the following values:

ValueDescription
JWTBearerAuthorizationLocationGet the bearer token from the Authorization header.
JWTCookieLocationGet the token from the Cookie header under the specified cookie name.
JWTHeaderLocationCustom header from where the header should be parsed from.

JWTHeaderLocation

Custom header from where the header should be parsed from.

KeyValueRequiredDescription
typeHeadertrue
namestringtrue

JWTCookieLocation

Get the token from the Cookie header under the specified cookie name.

KeyValueRequiredDescription
typeCookietrue
namestringtrue

JWTBearerAuthorizationLocation

Get the bearer token from the Authorization header.

KeyValueRequiredDescription
typeBearerAuthorizationtrue

JWTClaimsConfig

Config to describe how/where the engine should look for the claims within the decoded token.

Must have exactly one of the following fields:

KeyValueRequiredDescription
locationsJWTClaimsMapfalseCan be used when Hasura claims are not all present in the single object, but individual claims are provided a JSON pointer within the decoded JWT and optionally a default value.
namespaceJWTClaimsNamespacefalseUsed when all of the Hasura claims are present in a single object within the decoded JWT.

JWTClaimsNamespace

Used when all of the Hasura claims are present in a single object within the decoded JWT.

KeyValueRequiredDescription
claimsFormatJWTClaimsFormattrueFormat in which the Hasura claims will be present.
locationstringtruePointer to lookup the Hasura claims within the decoded claims.

JWTClaimsFormat

Format in which the Hasura claims will be present.

One of the following values:

ValueDescription
JsonClaims will be in the JSON format.
StringifiedJsonClaims will be in the Stringified JSON format.

JWTClaimsMap

Can be used when Hasura claims are not all present in the single object, but individual claims are provided a JSON pointer within the decoded JWT and optionally a default value.

KeyValueRequiredDescription
x-hasura-default-roleJWTClaimsMappingEntrytrueJSON pointer to lookup the default role within the decoded JWT.
x-hasura-allowed-rolesJWTClaimsMappingEntrytrueJSON pointer to lookup the allowed roles within the decoded JWT.

JWTClaimsMappingEntry

JSON pointer to lookup the default role within the decoded JWT.

Must have exactly one of the following fields:

KeyValueRequiredDescription
literalstringfalse
pathJWTClaimsMappingPathEntryfalse

JWTClaimsMappingPathEntry

KeyValueRequiredDescription
pathstringtrueJSON pointer to find the particular claim in the decoded JWT token.
defaultstring / nullfalseDefault value to be used when no value is found when looking up the value using the path.

AuthHookConfig

The configuration of the authentication webhook.

KeyValueRequiredDescription
urlstringtrueThe URL of the authentication webhook.
methodAuthHookMethodtrueThe HTTP method to be used to make the request to the auth hook.

Example:

url: http://auth_hook:3050/validate-request
method: Post

AuthHookMethod

The HTTP method to be used to make the request to the auth hook.

Value: Get / Post

Role

Value: string

Loading...