rohanpujaris / access_token_extractor

Simple Plug to extract access_token from request and add it to private map in Plug.Conn struct

Home Page:https://hex.pm/packages/access_token_extractor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AccessTokenExtractor

Simple Plug to extract access_token from request and add it to private map in Plug.Conn struct. Access token must be provided as query param named access_token or should be provided as authorization header

SETUP

Add following dependency to mix.exs

    defp deps do
      # Add the dependency
      [{:access_token_extractor , "~> 0.1.0"}]
    end

How to provide access token

http://some_url.com?access_token=abc

OR in authorization headers as follows

authorization: Token token=abc

This plug will extract token provided in any of above ways as assign it to private map in Plug.Conn struct

You can access it using conn.private.access_token

Example:

def MyModule
  import Plug.Builder, only: [plug: 1]
  import AccessTokenExtractor

  # second argument is optional. By default key is access_token
  plug :AccessTokenExtractor, key: :token
end

In above example access token can be retrived as conn.private.token where conn is Plug.Conn struct

About

Simple Plug to extract access_token from request and add it to private map in Plug.Conn struct

https://hex.pm/packages/access_token_extractor

License:MIT License


Languages

Language:Elixir 100.0%