SimpleTokenAuthentication
Usage
Phoenix Integration
-
Inside
web/router.exfile, add plug to your pipeline like so:
defmodule MyApp.Router
use Phoenix.Router
pipeline :api do
plug SimpleTokenAuthentication
end
scope "/", MyApp do
pipe_through :api
get "/hello", HelloController, :hello
end
endInstallation
-
Add
simple_token_authenticationto your list of dependencies inmix.exs:
def deps do
[{:simple_token_authentication, "~> 0.1.0"}]
end-
Ensure
simple_token_authenticationis started before your application:
def application do
[applications: [:simple_token_authentication]]
endConfigure your token in
config.exs:config :simple_token_authentication, token: "your-token-here", service_tokens: [ service_a: "service-a-token", service_b: "service-b-token" ]Configure your connecting application to pass a token in the
authorizationheader, e.g.:put_header("authorization", "your-token-here")
Notes
- token value can be a comma-separated list of tokens
-
specifying
service_tokensis optional -
auth will succeed if token exists in either list (
tokenorservice_tokens) -
Use of a service token will add "service_name" to
Logging.metadata