View Source JwtArmor (jwt_armor v0.1.0)

Documentation for JwtArmor.

JwtArmor wraps the Joken package to make it simpler to use with the security best practices.

Summary

Functions

Generate the token for a given config and any extra info you need.

Validate the token by a given signer.

Verify the token by a given signer.

Verify and validate the token by a given config.

Functions

Link to this function

generate(config, extras \\ %{})

View Source

Generate the token for a given config and any extra info you need.

config = %JwtArmor.Config{
  signer: %JwtArmor.Config.Signer{
    algorithm: "HS256",
    secret: "my secret key"
  },
  claims: %JwtArmor.Config.Claims{
    exp: 60 * 60, # 1 hour
    aud: "the-audience",
    iss: "the-issuser"
  }
}

{ok, token, claims} = JwtArmor.generate(config, %{"extra_id" => "any id"})
Link to this function

validate(claims_config, verified_claims)

View Source

Validate the token by a given signer.

token = "a token example"

claims = %JwtArmor.Config.Claims{
  exp: 60 * 60, # 1 hour
  aud: "the-audience",
  iss: "the-issuser"
}

{ok, claim_maps} = JwtArmor.validate(token, claims)
# if "ok" is an :error the "claim_maps" contains the error message
Link to this function

verify(token, signer_config)

View Source

Verify the token by a given signer.

token = "a token example"

signer = %JwtArmor.Config.Signer{
  algorithm: "HS256",
  secret: "my secret key"
}

{ok, claims} = JwtArmor.verify(token, signer)
# if "ok" is an :error the "claims" contains the error message
Link to this function

verify_and_validate(token, config)

View Source

Verify and validate the token by a given config.

token = "a token example"

config = %JwtArmor.Config{
  signer: %JwtArmor.Config.Signer{
    algorithm: "HS256",
    secret: "my secret key"
  },
  claims: %JwtArmor.Config.Claims{
    exp: 60 * 60, # 1 hour
    aud: "the-audience",
    iss: "the-issuser"
  }
}

{ok, claims} = JwtArmor.verify_and_validate(token, config)
# if "ok" is an :error the "claims" contains the error message