Überauth FreeAgent
FreeAgent OAuth2 strategy for Überauth.
Installation
Setup your application at the FreeAgent Developer site.
Add :ueberauth_freeagent
to your list of dependencies in mix.exs
:
def deps do
[{:ueberauth_freeagent, "~> 0.1"}]
end
If using Elixir < 1.4, make sure to add the strategy to your applications:
def application do
[applications: [:ueberauth_freeagent]]
end
Configuration
Add freeagent
to your Überauth configuration:
config :ueberauth, Ueberauth,
providers: [
freeagent: {Ueberauth.Strategy.FreeAgent, []}
]
Update your provider configuration, setting your client_id
and client_secret
:
config :ueberauth, Ueberauth.Strategy.FreeAgent.OAuth,
client_id: System.get_env("FREEAGENT_CLIENT_ID"),
client_secret: System.get_env("FREEAGENT_CLIENT_SECRET")
IMPORTANT: To use the FreeAgent sandbox API, set sandbox
to true
for the :ueberauth_freeagent
application:
config :ueberauth_freeagent,
sandbox: true
This will automatically configure the correct URLs.
OAuth2 Flow
Create a controller to implement callbacks to deal with Ueberauth.Auth
and
Ueberauth.Failure
responses. For an example implementation see the Überauth
Example application.
Make sure you include the Überauth plug in your router:
pipeline :auth do
plug Ueberauth
end
Configure the request and callback routes, making sure to use the pipeline that includes the plug:
scope "/auth", MyApp do
pipe_through [:auth, :browser]
get "/:provider", AuthController, :request
get "/:provider/callback", AuthController, :callback
end
Calling
Depending on the configured url you can initial the request through:
/auth/freeagent
Authentication State
You may want to look at Guardian (or something like it) to manage serializing authentication information across requests.
Using the Client
You can use the OAuth-configured client to access the FreeAgent API once you’re authenticated and have a token handy.
See Ueberauth.Strategy.FreeAgent.OAuth.client/1
for more information.
License
Please see LICENSE for license details.