https://github.com/ueberauth/guardian_pemfile_config_example
Example of a guardian configuration using a private and public pem file
https://github.com/ueberauth/guardian_pemfile_config_example
Last synced: 5 months ago
JSON representation
Example of a guardian configuration using a private and public pem file
- Host: GitHub
- URL: https://github.com/ueberauth/guardian_pemfile_config_example
- Owner: ueberauth
- Created: 2019-05-20T13:48:52.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-06-21T17:25:03.000Z (about 5 years ago)
- Last Synced: 2025-06-27T07:40:32.066Z (about 1 year ago)
- Language: Elixir
- Homepage:
- Size: 8.79 KB
- Stars: 7
- Watchers: 6
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Example of a guardian configuration using a private and public pem file
*This is just an example of how to get up and running and should not be used in production*
### Highlights
Pem files are put in the priv folder and fetched with the secret handler which is configured in the config file.
```elixir
config :pem_guardian, PemGuardian.Guardian,
issuer: "pem_guardian",
allowed_algos: ["RS512"],
secret_fetcher: PemGuardian.SecretFetcher
```
``` elixir
def fetch_signing_secret(_module, _opts) do
secret =
"rsa-2048.pem"
|> fetch()
{:ok, secret}
end
def fetch_verifying_secret(_module, _headers, _opts) do
secret =
"rsa-2048.pub"
|> fetch()
{:ok, secret}
end
defp fetch(relative_path) do
:code.priv_dir(:debug_guardian)
|> Path.join(relative_path)
|> JOSE.JWK.from_pem_file()
end
```
Example can be verified with the following commands
``` elixir
{:ok,token,_} = PemGuardian.Guardian.encode_and_sign(%{id: "1"})
PemGuardian.Guardian.decode_and_verify(token)
```