All Projects → nsweeting → Authex

nsweeting / Authex

Licence: mit
Authex is an opinionated JWT authentication and authorization library for Elixir.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Authex

Guardian
Elixir Authentication
Stars: ✭ 3,150 (+4215.07%)
Mutual labels:  phoenix, plug, authentication, jwt
Awesome Auth
📊 Software and Libraries for Authentication & Authorization
Stars: ✭ 520 (+612.33%)
Mutual labels:  authentication, authorization, auth
Next Authentication
Authentication & Authorization library for the Next.js framework
Stars: ✭ 55 (-24.66%)
Mutual labels:  authentication, authorization, auth
Aws Serverless Auth Reference App
Serverless reference app and backend API, showcasing authentication and authorization patterns using Amazon Cognito, Amazon API Gateway, AWS Lambda, and AWS IAM.
Stars: ✭ 724 (+891.78%)
Mutual labels:  authentication, authorization, auth
Laravel5.7 Vue Cli3 Boilerplate
Boilerplate / Starter kit. Laravel 5.7, Vue CLI 3 — Authentication with Email Verification. REST API.
Stars: ✭ 52 (-28.77%)
Mutual labels:  authentication, authorization, auth
Cloudfront Auth
An AWS CloudFront [email protected] function to authenticate requests using Google Apps, Microsoft, Auth0, OKTA, and GitHub login
Stars: ✭ 471 (+545.21%)
Mutual labels:  authentication, jwt, authorization
Php Auth
Authentication for PHP. Simple, lightweight and secure.
Stars: ✭ 713 (+876.71%)
Mutual labels:  authentication, authorization, auth
Annon.api
Configurable API gateway that acts as a reverse proxy with a plugin system.
Stars: ✭ 306 (+319.18%)
Mutual labels:  authentication, authorization, auth
Fastify Esso
The easiest authentication plugin for Fastify, with built-in support for Single sign-on
Stars: ✭ 20 (-72.6%)
Mutual labels:  authentication, jwt, auth
Rbac
Hierarchical Role Based Access Control for NodeJS
Stars: ✭ 857 (+1073.97%)
Mutual labels:  authentication, authorization, auth
Spring Boot Webflux Jjwt
Example Spring Boot and WebFlux (Reactive Web) with Spring Security and JWT for token Authentication and Authorization
Stars: ✭ 71 (-2.74%)
Mutual labels:  authentication, jwt, authorization
Paseto
Platform-Agnostic Security Tokens implementation in GO (Golang)
Stars: ✭ 461 (+531.51%)
Mutual labels:  authentication, jwt, auth
Buji Pac4j
pac4j security library for Shiro: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 444 (+508.22%)
Mutual labels:  authentication, jwt, authorization
Cerberus
A demonstration of a completely stateless and RESTful token-based authorization system using JSON Web Tokens (JWT) and Spring Security.
Stars: ✭ 482 (+560.27%)
Mutual labels:  authentication, jwt, authorization
Play Pac4j
Security library for Play framework 2 in Java and Scala: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 375 (+413.7%)
Mutual labels:  authentication, jwt, authorization
Social Core
Python Social Auth - Core
Stars: ✭ 618 (+746.58%)
Mutual labels:  authentication, authorization, auth
Hapi Auth Keycloak
JSON Web Token based Authentication powered by Keycloak
Stars: ✭ 29 (-60.27%)
Mutual labels:  authentication, jwt, auth
Securing Restful Apis With Jwt
How to secure a Nodejs RESTful CRUD API using JSON web tokens?
Stars: ✭ 301 (+312.33%)
Mutual labels:  authentication, jwt, authorization
Auth0.js
Auth0 headless browser sdk
Stars: ✭ 755 (+934.25%)
Mutual labels:  authentication, jwt, authorization
Access
Ponzu Addon to manage API access grants and tokens for authentication
Stars: ✭ 13 (-82.19%)
Mutual labels:  authentication, jwt, authorization

Authex

Build Status Authex Version

Authex is a simple JWT authentication and authorization library for Elixir.

Installation

The package can be installed by adding authex to your list of dependencies in mix.exs.

In addition, we must also add a JSON encoder/decoder. Jason is recommended. But any of these will work: jiffy, jsone, jsx, ojson, Poison.

Finally, if you wish to use any of the plug functionality, make sure to add the plug dependency.

def deps do
  [
    {:authex, "~> 2.0"},
    {:jason, "~> 1.0"},
    {:plug, "~> 1.0"}
  ]
end

Documentation

See HexDocs for additional documentation.

Example

To get started, we must define our auth module:

defmodule MyApp.Auth do
  use Authex

  def start_link(opts \\\\ []) do
    Authex.start_link(__MODULE__, opts, name: __MODULE__)
  end

  # Callbacks

  @impl Authex
  def init(opts) do
    # Add any configuration listed in Authex.start_link/3

    secret = System.get_env("AUTH_SECRET") || "foobar"
    opts = Keyword.put(opts, :secret, secret)

    {:ok, opts}
  end

  @impl Authex
  def handle_for_token(%MyApp.User{} = resource, opts) do
    {:ok, [sub: resource.id, scopes: resource.scopes], opts}
  end

  def handle_for_token(_resource, _opts) do
    {:error, :bad_resource}
  end

  @impl Authex
  def handle_from_token(token, _opts) do
    # You may want to perform a database lookup for your user instead
    {:ok, %MyApp.User{id: token.sub, scopes: token.scopes}}
  end
end

And add it to your supervision tree:

children = [
  MyApp.Auth
]

We can then create, sign, and verify tokens:

token = Authex.token(MyApp.Auth, sub: 1, scopes: ["admin/read"])
compact_token = Authex.sign(MyApp.Auth, token)
{:ok, token} = Authex.verify(MyApp.Auth, compact_token)

We can also convert resources to and from tokens.

token = Authex.for_token(MyApp.Auth, user)
compact_token = Authex.sign(MyApp.Auth, token)
{:ok, token} = Authex.verify(MyApp.Auth, compact_token)
{:ok, user} = Authex.from_token(MyApp.Auth, token)

Please check out the documentation for more advanced features.

Features

  • Easy to integrate with almost any app.
  • Handles both authentication + authorization.
  • Convert data to and from tokens.
  • Handle persistence for things like blacklists.
  • Batteries included for plug integration.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].