graphql-engine-1.0.0: GraphQL API over Postgres
CopyrightHasura
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hasura.Server.Auth.JWT

Description

This module implements the bulk of Hasura's JWT capabilities and interactions. Its main point of non-testing invocation is Auth.

It exports both processJwt and processJwt_ with processJwt_ being the majority of the implementation with the JWT Token processing function passed in as an argument in order to enable mocking in test-code.

In processJwt_, prior to validation of the token, first the token locations and issuers are reconciled. Locations are either specified as auth or cookie (with cookie name) or assumed to be auth. Issuers can be omitted or specified, where an omitted configured issuer can match any issuer specified by a request.

If none match, then this is considered an no-auth request, if one matches, then normal token auth is performed, and if multiple match, then this is considered an ambiguity error.

Synopsis

Documentation

data JWTClaimsFormat Source #

Instances

Instances details
FromJSON JWTClaimsFormat Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

ToJSON JWTClaimsFormat Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Generic JWTClaimsFormat Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Associated Types

type Rep JWTClaimsFormat :: Type -> Type #

Show JWTClaimsFormat Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Eq JWTClaimsFormat Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

type Rep JWTClaimsFormat Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

type Rep JWTClaimsFormat = D1 ('MetaData "JWTClaimsFormat" "Hasura.Server.Auth.JWT" "graphql-engine-1.0.0-inplace" 'False) (C1 ('MetaCons "JCFJson" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "JCFStringifiedJson" 'PrefixI 'False) (U1 :: Type -> Type))

data JWTHeader Source #

Instances

Instances details
FromJSON JWTHeader Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

ToJSON JWTHeader Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Generic JWTHeader Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Associated Types

type Rep JWTHeader :: Type -> Type #

Show JWTHeader Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Eq JWTHeader Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Hashable JWTHeader Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

type Rep JWTHeader Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

type Rep JWTHeader = D1 ('MetaData "JWTHeader" "Hasura.Server.Auth.JWT" "graphql-engine-1.0.0-inplace" 'False) (C1 ('MetaCons "JHAuthorization" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "JHCookie" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 Text)))

data JWTCustomClaimsMapValueG v Source #

JWTCustomClaimsMapValueG is used to represent a single value of the JWTCustomClaimsMap. A JWTCustomClaimsMapValueG can either be an JSON object or the literal value of the claim. If the value is an JSON object, then it should contain a key path, which is the JSON path to the claim value in the JWT token. There's also an option to specify a default value in the map via the 'default' key, which will be used when a peek at the JWT token using the JSON path fails (key does not exist).

Constructors

JWTCustomClaimsMapJSONPath !JSONPath !(Maybe v)

JSONPath to the key in the claims map, in case the key doesn't exist in the claims map then the default value will be used (if provided)

JWTCustomClaimsMapStatic !v 

Instances

Instances details
Foldable JWTCustomClaimsMapValueG Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Methods

fold :: Monoid m => JWTCustomClaimsMapValueG m -> m #

foldMap :: Monoid m => (a -> m) -> JWTCustomClaimsMapValueG a -> m #

foldMap' :: Monoid m => (a -> m) -> JWTCustomClaimsMapValueG a -> m #

foldr :: (a -> b -> b) -> b -> JWTCustomClaimsMapValueG a -> b #

foldr' :: (a -> b -> b) -> b -> JWTCustomClaimsMapValueG a -> b #

foldl :: (b -> a -> b) -> b -> JWTCustomClaimsMapValueG a -> b #

foldl' :: (b -> a -> b) -> b -> JWTCustomClaimsMapValueG a -> b #

foldr1 :: (a -> a -> a) -> JWTCustomClaimsMapValueG a -> a #

foldl1 :: (a -> a -> a) -> JWTCustomClaimsMapValueG a -> a #

toList :: JWTCustomClaimsMapValueG a -> [a] #

null :: JWTCustomClaimsMapValueG a -> Bool #

length :: JWTCustomClaimsMapValueG a -> Int #

elem :: Eq a => a -> JWTCustomClaimsMapValueG a -> Bool #

maximum :: Ord a => JWTCustomClaimsMapValueG a -> a #

minimum :: Ord a => JWTCustomClaimsMapValueG a -> a #

sum :: Num a => JWTCustomClaimsMapValueG a -> a #

product :: Num a => JWTCustomClaimsMapValueG a -> a #

Traversable JWTCustomClaimsMapValueG Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Functor JWTCustomClaimsMapValueG Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

FromJSON v => FromJSON (JWTCustomClaimsMapValueG v) Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

ToJSON v => ToJSON (JWTCustomClaimsMapValueG v) Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Show v => Show (JWTCustomClaimsMapValueG v) Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Eq v => Eq (JWTCustomClaimsMapValueG v) Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

data JWTCustomClaimsMap Source #

JWTClaimsMap is an option to provide a custom JWT claims map. The JWTClaimsMap should be specified in the HASURA_GRAPHQL_JWT_SECRET in the claims_map. The JWTClaimsMap, if specified, requires two mandatory fields, namely, `x-hasura-allowed-roles` and the `x-hasura-default-role`, other claims may also be provided in the claims map.

data JWTNamespace Source #

JWTNamespace is used to locate the claims map within the JWT token. The location can be either provided via a JSON path or the name of the key in the JWT token.

data JWTClaims Source #

Instances

Instances details
Show JWTClaims Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Eq JWTClaims Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

newtype StringOrURI Source #

Hashable Wrapper for constructing a HashMap of JWTConfigs

Constructors

StringOrURI 

Instances

Instances details
FromJSON StringOrURI Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

FromJSONKey StringOrURI Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

ToJSON StringOrURI Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

ToJSONKey StringOrURI Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Show StringOrURI Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Eq StringOrURI Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Hashable StringOrURI Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

FromJSONKey (Maybe StringOrURI) Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

ToJSONKey (Maybe StringOrURI) Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

data JWTConfig Source #

The JWT configuration we got from the user.

Instances

Instances details
FromJSON JWTConfig Source #

Parse from a json string like: | `{"type": RS256, "key": "PEM-encoded-public-key-or-X509-cert"}` | to JWTConfig

Instance details

Defined in Hasura.Server.Auth.JWT

ToJSON JWTConfig Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Show JWTConfig Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Eq JWTConfig Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

FromEnv JWTConfig Source # 
Instance details

Defined in Hasura.Server.Init.Env

FromEnv [JWTConfig] Source # 
Instance details

Defined in Hasura.Server.Init.Env

data JWTCtx Source #

The validated runtime JWT configuration returned by mkJwtCtx in setupAuthMode.

Constructors

JWTCtx 

Fields

Instances

Instances details
Show JWTCtx Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Eq JWTCtx Source # 
Instance details

Defined in Hasura.Server.Auth.JWT

Methods

(==) :: JWTCtx -> JWTCtx -> Bool #

(/=) :: JWTCtx -> JWTCtx -> Bool #

fetchAndUpdateJWKs :: (MonadIO m, MonadBaseControl IO m) => Logger Hasura -> Manager -> URI -> IORef (JWKSet, Maybe UTCTime) -> m () Source #

An action that fetches the JWKs and updates the expiry time and JWKs in the IORef

fetchJwk :: (MonadIO m, MonadBaseControl IO m, MonadError JwkFetchError m) => Logger Hasura -> Manager -> URI -> m (JWKSet, ResponseHeaders) Source #

Given a JWK url, fetch JWK from it

determineJwkExpiryLifetime :: forall m. (MonadIO m, MonadError JwkFetchError m) => m UTCTime -> Logger Hasura -> ResponseHeaders -> m (Maybe UTCTime) Source #

First check for Cache-Control header, if not found, look for Expires header

tokenIssuer :: RawJWT -> Maybe StringOrURI Source #

Extract the issuer from a bearer tokena _without_ verifying it.

processJwt :: (MonadIO m, MonadError QErr m) => [JWTCtx] -> RequestHeaders -> Maybe RoleName -> m (UserInfo, Maybe UTCTime, [Header], Maybe JWTCtx) Source #

Process the request headers to verify the JWT and extract UserInfo from it From the JWT config, we check which header to expect, it can be the Authorization or Cookie header

If no Authorization/Cookie header was passed, we will fall back to the unauthenticated user role [1], if one was configured at server start.

When no 'x-hasura-user-role' is specified in the request, the mandatory 'x-hasura-default-role' [2] from the JWT claims will be used.

processJwt_ Source #

Arguments

:: MonadError QErr m 
=> (JWTCtx -> ByteString -> m (ClaimsMap, Maybe UTCTime))

mock processAuthZOrCookieHeader

-> (RawJWT -> Maybe StringOrURI) 
-> (JWTCtx -> JWTHeader) 
-> [JWTCtx] 
-> RequestHeaders 
-> Maybe RoleName 
-> m (UserInfo, Maybe UTCTime, [Header], Maybe JWTCtx) 

parseClaimsMap Source #

Arguments

:: MonadError QErr m 
=> ClaimsSet

Unregistered JWT claims

-> JWTClaims

Claims config

-> m ClaimsMap

Hasura claims and other claims

parse the claims map from the JWT token or custom claims from the JWT config