在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:garyf/json_web_token_ex开源软件地址:https://github.com/garyf/json_web_token_ex开源编程语言:Elixir 100.0%开源软件介绍:JSON Web TokenA JSON Web Token (JWT) implementation for ElixirDescriptionAn Elixir implementation of the JSON Web Token (JWT) standard RFC 7519 Philosophy & design goals
UsageAdd JsonWebToken as a dependency in your defp deps do
[{:json_web_token, "~> 0.2"}]
end JsonWebToken.sign(claims, options)Returns a JSON Web Token string
Include any JWS JOSE header parameters (RFC 7515) in the options map Example # sign with default algorithm, HMAC SHA256
jwt = JsonWebToken.sign(%{foo: "bar"}, %{key: "gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C"})
# sign with RSA SHA256 algorithm
private_key = JsonWebToken.Algorithm.RsaUtil.private_key("path/to/", "key.pem")
opts = %{
alg: "RS256",
key: private_key
}
jwt = JsonWebToken.sign(%{foo: "bar"}, opts)
# unsecured token (algorithm is "none")
jwt = JsonWebToken.sign(%{foo: "bar"}, %{alg: "none"}) JsonWebToken.verify(jwt, options)Returns a tuple, either:
Example secure_jwt_example = "eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt.cGxlLmNvbS9pc19yb290Ijp0cnVlfQ.dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"
# verify with default algorithm, HMAC SHA256
{:ok, claims} = JsonWebToken.verify(secure_jwt_example, %{key: "gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C"})
# verify with RSA SHA256 algorithm
opts = %{
alg: "RS256",
key: < RSA public key >
}
{:ok, claims} = JsonWebToken.verify(jwt, opts)
# unsecured token (algorithm is "none")
unsecured_jwt_example = "eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt."
{:ok, claims} = JsonWebToken.verify(unsecured_jwt_example, %{alg: "none"}) Supported encryption algorithms
Registered claim namesA companion Hex package, JWT Claims, provides support for verifying these optional, registered claim names:
Supported Elixir versionsElixir 1.4 and up LimitationsFuture implementation may include these features:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论