Skip to content

Get an OAuth 2 provider running in your phoenix with controllers, views and models in just two minutes

License

Notifications You must be signed in to change notification settings

Tiltify/phoenix_oauth2_provider

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PhoenixOauth2Provider

Build Status hex.pm hex.pm downloads

Get an OAuth 2.0 provider running in your Phoenix app with schema modules and templates in just two minutes.

Installation

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

def deps do
  [
    # ...
    {:phoenix_oauth2_provider, "~> 0.5.1"}
    # ...
  ]
end

Run mix deps.get to install it.

Getting started

Install ExOauthProvider first:

mix ex_oauth2_provider.install

Follow the instructions to update config/config.exs.

Set up routes:

defmodule MyAppWeb.Router do
  use MyAppWeb, :router
  use PhoenixOauth2Provider.Router, otp_app: :my_app

  # ...

  pipeline :protected do
    # Require user authentication
  end

  scope "/" do
    pipe_through :api

    oauth_api_routes()
  end

  scope "/" do
    pipe_through [:browser, :protected]

    oauth_routes()
  end

  # ...
end

That's it! The following OAuth 2.0 routes will now be available in your app:

oauth_authorize_path  GET    /oauth/authorize         AuthorizationController :new
oauth_authorize_path  POST   /oauth/authorize         AuthorizationController :create
oauth_authorize_path  GET    /oauth/authorize/:code   AuthorizationController :show
oauth_authorize_path  DELETE /oauth/authorize         AuthorizationController :delete
oauth_token_path      POST   /oauth/token             TokenController :create
oauth_token_path      POST   /oauth/revoke            TokenController :revoke

Please read the ExOauth2Provider documentation for further customization.

Configuration

Templates

To generate views and templates run:

mix phoenix_oauth2_provider.gen.templates

Set up the PhoenixOauth2Provider configuration with :web_module:

config :my_app, PhoenixOauth2Provider,
  web_module: MyAppWeb

Current resource owner

Set up what key in the plug conn assigns that PhoenixOauth2Provider should use to fetch the current resource owner.

config :my_app, PhoenixOauth2Provider,
  current_resource_owner: :current_user

LICENSE

(The MIT License)

Copyright (c) 2017-2019 Dan Schultzer & the Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Get an OAuth 2 provider running in your phoenix with controllers, views and models in just two minutes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 99.9%
  • HTML 0.1%