Skip to main content

@rtorcato/cf-common

Interfaces​

AccessIdentity​

Defined in: index.ts:10

Claims Cloudflare Access puts in the assertion. Other claims pass through.

Indexable​

[claim: string]: unknown

Properties​

aud​

aud: string[]

Defined in: index.ts:12

The Access application AUD tag(s) the token was issued for.

email?​

optional email?: string

Defined in: index.ts:14

The authenticated user's email (absent for service tokens).

iss​

iss: string

Defined in: index.ts:16

Issuer, https://<team>.cloudflareaccess.com.

sub​

sub: string

Defined in: index.ts:18

Stable user id.

iat​

iat: number

Defined in: index.ts:19

exp​

exp: number

Defined in: index.ts:20

nbf?​

optional nbf?: number

Defined in: index.ts:21

type?​

optional type?: string

Defined in: index.ts:23

app for a user, service-token for a service token.

country?​

optional country?: string

Defined in: index.ts:24


VerifyAccessJwtOptions​

Defined in: index.ts:28

Properties​

teamDomain​

teamDomain: string

Defined in: index.ts:30

Your Access team domain, e.g. myteam.cloudflareaccess.com.

aud​

aud: string

Defined in: index.ts:32

The application's AUD tag, from the Access application's settings.

Functions​

accessJwt()​

accessJwt(request): string | null

Defined in: index.ts:55

Read the Access assertion from a request. null when the header is missing, i.e. the request didn't come through Access.

Example​

const token = accessJwt(request)

Parameters​

request​

Request

Returns​

string | null


verifyAccessJwt()​

verifyAccessJwt(token, __namedParameters): Promise<AccessIdentity>

Defined in: index.ts:70

Verify an Access JWT and return its claims. Checks the RS256 signature against the team JWKS, the issuer, the aud tag, exp and nbf. Throws a 401 CloudflareError (ACCESS_JWT_INVALID) for any bad token, and a non-exposed 502 (ACCESS_JWKS_HTTP_ERROR) if the JWKS can't be fetched.

Example​

const token = accessJwt(request)
if (!token) throw new CloudflareError('Unauthorized', { status: 401 })
const { email } = await verifyAccessJwt(token, { teamDomain: env.TEAM_DOMAIN, aud: env.POLICY_AUD })

Parameters​

token​

string

__namedParameters​

VerifyAccessJwtOptions

Returns​

Promise<AccessIdentity>