https://github.com/ueberauth/guardian_jwe
https://github.com/ueberauth/guardian_jwe
guardian jwe
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ueberauth/guardian_jwe
- Owner: ueberauth
- License: mit
- Created: 2018-03-01T06:30:09.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-10-17T18:06:05.000Z (almost 4 years ago)
- Last Synced: 2025-06-27T07:40:27.023Z (3 months ago)
- Topics: guardian, jwe
- Language: Elixir
- Size: 22.5 KB
- Stars: 6
- Watchers: 7
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Guardian.Token.Jwe [](https://hex.pm/packages/guardian_jwe)
This package is a plugin for [Guardian](https://hex.pm/packages/guardian).
## Documentation
API documentation is available at [https://hexdocs.pm/guardian_jwe](https://hexdocs.pm/guardian_jwe)
## Installation
To install `Guardian.Token.Jwe`, first add it to your `mix.exs` file:
```elixir
def deps do
[
{:guardian_jwe, "~> 0.2.0"}
]
end
```To use JWEs, you'll need to configure the `token_module` parameter in your Guardian implementation module.
```elixir
defmodule GuardianTest.Auth do
use Guardian,
otp_app: :guardian_test,
token_module: Guardian.Token.Jwedef subject_for_token(resource, _claims) do
sub = to_string(resource.id){:ok, sub}
enddef resource_from_claims(claims) do
{:ok, claims}
end
end
```To change the default algorithm used to encrypt JWEs, set the `allowed_algos` in your Guardian configuration:
```elixir
config :guardian_test, GuardianTest.Auth,
issuer: "guardian_test",
allowed_algos: ["A128GCMKW"],
secret_key: "aaaaaaaaaaaaaaaa"
```The JWE module uses the same claims and validations as JWT for verification. With this configuration, your application should work without additional changes to your Guardian configuration.
## Implemented algorithms
Currently, this package supports the following algorithms for encrypting JWT tokens.
```
A128GCMKW
A192GCMKW
A256GCMKWPBES2-HS256+A128KW
PBES2-HS384+A192KW
PBES2-HS512+A256KW
```Each of the `AxxxGCMKW` require keys of specific bit sizes where the `xxx` corresponds to the required size of the key.
The `PBES2-HSxxx+AxxxKW` secret can be generated using `mix guardian.gen.secret`.
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/guardian_jwe](https://hexdocs.pm/guardian_jwe).