https://github.com/superfly/macaroon-elixir
Elixir library for attenuating Fly.io macaroons
https://github.com/superfly/macaroon-elixir
Last synced: about 1 month ago
JSON representation
Elixir library for attenuating Fly.io macaroons
- Host: GitHub
- URL: https://github.com/superfly/macaroon-elixir
- Owner: superfly
- License: apache-2.0
- Created: 2023-09-22T18:50:12.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-14T15:17:17.000Z (8 months ago)
- Last Synced: 2024-10-29T05:20:50.534Z (7 months ago)
- Language: Elixir
- Size: 93.8 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Macfly
This library handles Fly.io Macaroon encoding, decoding, attentuation, etc..
[Hex Docs](https://hexdocs.pm/macfly/)
## Installation
The package can be installed by adding `macfly` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:macfly, "~> 0.2.16"}
]
end
```## Usage
### Encoding and Decoding
Tokens separated by commas:
```elixir
# for example tokens, see the tests or test/vectors.json file
token = "FlyV1 fm2_lJPE...,...,"# supports single token or tokens that are seprated by commas
{:ok, [%Macfly.Macaroon{}] = macaroons} = Macfly.decode(token)token = Macfly.encode(macaroons)
```Single macaroon:
```elixir
# decode a single token (note: token without prefix FlyV1)
{:ok, %Macfly.Macaroon{} = macaroon} = Macfly.Macaroon.decide("fm2_lJPE...")# encode a single token (note: token without prefix FlyV1)
token = Macfly.Macaroon.encode(macaroon)
```### Attenuating a Macaroon
Tokens separated by commas:
```elixir
# for example tokens, see the tests or test/vectors.json file
token = "FlyV1o fm2_lJPE..,..., ..."
{:ok, [%Macfly.Macaroon{}] = macaroons} = Macfly.decode(token)caveats = [
%Macfly.Caveat.Organization{
id: 1234,
permission: Macfly.Action.read()
}
]options = %Macfly.Options{location: "29745b8fbe60e62fe8359198aea82643"}
|> Macfly.Options.with_caveats([Macfly.Caveat.Organization])new_macaroons = Macfly.attenuate(macaroons, caveats, options)
new_token = Macfly.encode(new_macaroons)
```Single macaroon:
```elixir
{:ok, %Macfly.Macaroon{} = macaroon} = Macfly.Macaroon.decode("fm2_lJPE...")caveats = [
%Macfly.Caveat.Organization{
id: 1234,
permission: Macfly.Action.read()
}
]macaroon = Macfly.Macaroon.attenuate(macaroon, caveats)
token = Macfly.Macaroon.encode(macaroon)
```## Documentation
To generate documentation locally run `mix docs` and open `doc/index.html` in your browser.