Skip to content

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

License

Notifications You must be signed in to change notification settings

rohanpujaris/access_token_extractor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages