Skip to content


Pode has inbuilt JWT parsing for either Bearer or API Key authentications. Pode will attempt to validate and parse the token/key as a JWT, and if successful the JWT's payload will be passed as the parameter to Add-PodeAuth, instead of the token/key.

For more information on JWTs, see the official website.


To start using JWT authentication, you can supply the -AsJWT switch with either the -Bearer or -ApiKey switch on New-PodeAuthScheme. You can also supply an optional -Secret that the JWT signature uses so Pode can validate the JWT:

# jwt with no signature:
New-PodeAuthScheme -Bearer -AsJWT | Add-PodeAuth -Name 'Example' -Sessionless -ScriptBlock {

# jwt with signature, signed with secret "abc":
New-PodeAuthScheme -ApiKey -AsJWT -Secret 'abc' | Add-PodeAuth -Name 'Example' -Sessionless -ScriptBlock {

The $payload will be a PSCustomObject of the converted JSON payload. For example, sending the following unsigned JWT in a request:


would produce a payload of:

sub:        123
username:   morty


Pode supports the following algorithms for JWT signatures:

  • None
  • HS256
  • HS384
  • HS512

For none, Pode expects there to be no signature with the JWT. For other algorithms, a -Secret is required, and a signature must be supplied with the JWT in requests.


If the payload of the JWT contains a expiry (exp) or a not before (nbf) timestamp, Pode will validate it and return a 400 if the JWT is expired/not started.


To send the JWT in a request, the JWT should be sent in place of where the usual bearer token/API key would have been. For example, for bearer it would be in the Authorization header:

Authorization: Bearer <jwt>

and for API keys, it would be in the location defined (header, cookie, or query string). For example, in the X-API-KEY header:

X-API-KEY: <jwt>

Create JWT

Pode has a simple ConvertTo-PodeJwt that will build a JWT for you. It accepts a hashtable for -Header and -Payload, as well as an optional -Secret.

The function will run some simple validation, and them build the JWT for you.

For example:

$header = @{
    alg = 'hs256'
    typ = 'JWT'

$payload = @{
    sub = '123'
    name = 'John Doe'
    exp = ([System.DateTimeOffset]::Now.AddDays(1).ToUnixTimeSeconds())

ConvertTo-PodeJwt -Header $header -Payload $payload -Secret 'abc'

This return the following JWT: