{"id":15640363,"url":"https://github.com/nsweeting/authex","last_synced_at":"2025-05-08T21:27:45.530Z","repository":{"id":46185011,"uuid":"109330109","full_name":"nsweeting/authex","owner":"nsweeting","description":"Authex is an opinionated JWT authentication and authorization library for Elixir.","archived":false,"fork":false,"pushed_at":"2022-08-26T17:00:16.000Z","size":151,"stargazers_count":77,"open_issues_count":6,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-02T03:53:54.757Z","etag":null,"topics":["auth","authentication","authorization","elixir","jwt","phoenix","plug"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nsweeting.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-02T23:38:48.000Z","updated_at":"2024-09-21T17:49:04.000Z","dependencies_parsed_at":"2022-09-26T18:31:43.096Z","dependency_job_id":null,"html_url":"https://github.com/nsweeting/authex","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fauthex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fauthex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fauthex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fauthex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nsweeting","download_url":"https://codeload.github.com/nsweeting/authex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238044095,"owners_count":19407128,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth","authentication","authorization","elixir","jwt","phoenix","plug"],"created_at":"2024-10-03T11:34:53.050Z","updated_at":"2025-02-10T02:10:06.077Z","avatar_url":"https://github.com/nsweeting.png","language":"Elixir","readme":"# Authex\n\n[![Build Status](https://travis-ci.org/nsweeting/authex.svg?branch=master)](https://travis-ci.org/nsweeting/authex)\n[![Authex Version](https://img.shields.io/hexpm/v/authex.svg)](https://hex.pm/packages/authex)\n\nAuthex is a simple JWT authentication and authorization library for Elixir.\n\n## Installation\n\nThe package can be installed by adding `authex` to your list of dependencies in `mix.exs`.\n\nIn addition, we must also add a JSON encoder/decoder. [Jason](https://github.com/michalmuskala/jason) is recommended. But any of these will work: [jiffy](https://github.com/davisp/jiffy), [jsone](https://github.com/sile/jsone), [jsx](https://github.com/talentdeficit/jsx), [ojson](https://github.com/potatosalad/erlang-ojson), [Poison](https://github.com/devinus/poison).\n\nFinally, if you wish to use any of the plug functionality, make sure to add the plug dependency.\n\n```elixir\ndef deps do\n  [\n    {:authex, \"~\u003e 2.0\"},\n    {:jason, \"~\u003e 1.0\"},\n    {:plug, \"~\u003e 1.0\"}\n  ]\nend\n```\n\n## Documentation\n\nSee [HexDocs](https://hexdocs.pm/authex) for additional documentation.\n\n## Example\n\nTo get started, we must define our auth module:\n\n```elixir\ndefmodule MyApp.Auth do\n  use Authex\n\n  def start_link(opts \\\\\\\\ []) do\n    Authex.start_link(__MODULE__, opts, name: __MODULE__)\n  end\n\n  # Callbacks\n\n  @impl Authex\n  def init(opts) do\n    # Add any configuration listed in Authex.start_link/3\n\n    secret = System.get_env(\"AUTH_SECRET\") || \"foobar\"\n    opts = Keyword.put(opts, :secret, secret)\n\n    {:ok, opts}\n  end\n\n  @impl Authex\n  def handle_for_token(%MyApp.User{} = resource, opts) do\n    {:ok, [sub: resource.id, scopes: resource.scopes], opts}\n  end\n\n  def handle_for_token(_resource, _opts) do\n    {:error, :bad_resource}\n  end\n\n  @impl Authex\n  def handle_from_token(token, _opts) do\n    # You may want to perform a database lookup for your user instead\n    {:ok, %MyApp.User{id: token.sub, scopes: token.scopes}}\n  end\nend\n```\n\nAnd add it to your supervision tree:\n\n```elixir\nchildren = [\n  MyApp.Auth\n]\n```\n\nWe can then create, sign, and verify tokens:\n\n```elixir\ntoken = Authex.token(MyApp.Auth, sub: 1, scopes: [\"admin/read\"])\ncompact_token = Authex.sign(MyApp.Auth, token)\n{:ok, token} = Authex.verify(MyApp.Auth, compact_token)\n```\n\nWe can also convert resources to and from tokens.\n\n```elixir\ntoken = Authex.for_token(MyApp.Auth, user)\ncompact_token = Authex.sign(MyApp.Auth, token)\n{:ok, token} = Authex.verify(MyApp.Auth, compact_token)\n{:ok, user} = Authex.from_token(MyApp.Auth, token)\n```\n\nPlease check out the documentation for more advanced features.\n\n## Features\n\n- Easy to integrate with almost any app.\n- Handles both authentication + authorization.\n- Convert data to and from tokens.\n- Handle persistence for things like blacklists.\n- Batteries included for plug integration.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsweeting%2Fauthex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnsweeting%2Fauthex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsweeting%2Fauthex/lists"}