Coder Social home page Coder Social logo

auth0_tesla's Introduction

Tesla Auth0 Middleware

Used to add middleware to Tesla client that will fetch an access token from Auth0 and add it to the Authorization header of the request as a Bearer token.

Token is saved between requests until a request returns a 401 status code at which point a new token will be retrieved.

Intended for use by Machine-to-Machine clients with a client_credentials grant type.

Installation

Add auth0_tesla to your list of dependencies in mix.exs:

def deps do
  [
    {:auth0_tesla, git: "https://github.com/ReelCoaches/auth0_tesla.git"}
  ]
end

Example Usage

defmodule MyClient do
  use Tesla

  # static configuration
  plug Auth0Tesla.Middleware, base_url: "https://my-auth0-tenant.auth0.com", client_id: "ABCD1234", client_secret: "some-secret", audience: "https://my-auth0-tenant.auth0.com/", grant_type: "client_credentials"

  # dynamic configuration
  def new(client_id, client_secret, audience, grant_type) do
    opts = [
      client_id: client_id,
      client_secret: client_secret,
      audience: audience,
      grant_type: grant_type
    ]

    Tesla.client [
      {Auth0Tesla.Middleware, opts}
    ]
  end
end

Options

  • :base_url - URL of Auth0 API to request token for (defaults to "https://api.auth0.com")
  • :client_id - Auth0 Client ID (defaults to "")
  • :client_secret - Auth0 Client Secret (defaults to "")
  • :audience - Audience identifier of Auth0 API to request token for (defaults to "")
  • :grant_type - Grant type (defaults to "client_credentials")
  • :adapter - Tesla adapter that will be used to make the request to Auth0. Useful for setting adapter to Tesla.Mock when writing tests (defaults to Tesla.Adapter.Httpc)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.