• This repository has been archived on 14/Sep/2021
  • Stars
    star
    785
  • Rank 57,957 (Top 2 %)
  • Language
    Elixir
  • Created over 4 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An authentication system generator for Phoenix 1.5 applications.

Phx.Gen.Auth

An authentication system generator for Phoenix 1.5 applications.

Note: This project is no longer maintained as mix phx.gen.auth has been merged into Phoenix v1.6.

Overview

The purpose of phx.gen.auth is to generate a pre-built authentication system into a Phoenix 1.5 application that follows both security and elixir best practices. By generating code into the user's application instead of using a library, the user has complete freedom to modify the authentication system so it works best with their app. The following links have more information regarding the motivation and design of the code this generates.

Usage

Generating a Phoenix 1.5 app

phx.gen.auth must be installed into a Phoenix 1.5 application.

Once the installer is installed, a new project can be generated by running

$ mix phx.new my_app

Please note, the --no-ecto and --no-html options are not supported.

Installation

After running mix phx.new, cd into your application's directory (ex. my_app).

Basic installation

  1. Add phx_gen_auth to your list of dependencies in mix.exs

    def deps do
      [
        {:phx_gen_auth, "~> 0.7", only: [:dev], runtime: false},
        ...
      ]
    end
  2. Install and compile the dependencies

    $ mix do deps.get, deps.compile
    

Umbrella installation

  1. cd into your project's web app directory (ex. apps/my_app_web)

    $ cd apps/my_app_web
    
  2. Add phx_gen_auth to your list of dependencies in mix.exs

    def deps do
      [
        {:phx_gen_auth, "~> 0.7", only: [:dev], runtime: false},
        ...
      ]
    end
  3. Install and compile the dependencies

    $ mix do deps.get, deps.compile
    

Running the generator

From the root of your phoenix app (or apps/my_app_web in an umbrella app), you can install the authentication system with the following command

$ mix phx.gen.auth Accounts User users

This creates the templates,views, and controllers on the web namespace, and a new MyApp.Accounts context, in the application namespace.

Verify the database connection details for the development and test environments in config/ so the migrator and tests can run properly. Then run the following to create the database

$ mix ecto.create

Next, let's install the dependencies and migrate the database

$ mix deps.get
$ mix ecto.migrate

Let's run the tests and make sure our new authentication system works as expected.

$ mix test

Finally, let's start our phoenix server and try it out.

$ mix phx.server

Note on apps upgraded from Phoenix 1.4

If you've upgraded your app from Phoenix 1.4, you'll need to make the following update to test/support/conn_case.ex to get mix test to pass:

using do
  quote do
    # Import conveniences for testing with connections
    import Plug.Conn
    import Phoenix.ConnTest
+   import DemoWeb.ConnCase
    alias DemoWeb.Router.Helpers, as: Routes

    # The default endpoint for testing
    @endpoint DemoWeb.Endpoint
  end
end

Changing id types

By default, this generator uses the same type of id fields as the rest of the application. To override this configuration, the generator accepts --binary-id and --no-binary-id flags.

$ mix phx.gen.auth Accounts User users --binary-id

More information about these options are available in the documentation.

Learning more

To learn more about phx.gen.auth, run the following command.

$ mix help phx.gen.auth

You can also look up the mix task in hexdocs.

Upgrading

Since mix phx.gen.auth generates its code directly into your application, upgrading the version of this library will not upgrade your application's current authentication logic.

To see the changes that have been made to the generator output since the version that was used in your application, visit the CHANGELOG and click the [Diff] links for each version. These diffs will show you the changes to make to your application so it can be up to date with the current generator output.

License

Copyright 2020 Dashbit, Aaron Renner

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

More Repositories

1

zone-meal-tracker

Meal tracker for the Zone diet. (Reference app for Application Layering blog post)
Elixir
43
star
2

crowdfundr

Example crowdfunding app for ElixirConf
Elixir
37
star
3

heroku-buildpack-rgeo-prep

A buildpack that allows the RGeo gem to be built successfully on Heroku.
Shell
17
star
4

constantizer

Helpers to evaluate elixir functions at compile time instead of runtime
Elixir
14
star
5

freezer-eye

Nerves poncho project to ensure my freezer is plugged in
Elixir
5
star
6

adapter-pattern-example

Elixir
3
star
7

ex_riak

Simple wrapper around riak-erlang-client for Elixir
Elixir
3
star
8

formtacular

Form submission backend in elixir
Elixir
2
star
9

phoenix_generator_proposals_live

Elixir
2
star
10

rumbl

Example app from Programming Phoenix book for annotating videos in real time
Elixir
2
star
11

producer_consumer_testing

Elixir
2
star
12

not_loaded

Helpers to indicate a field might have a value but is not loaded. Inspired by Ecto.
Elixir
2
star
13

durango-coders-rubymotion-presentation

Slides for Durango Coders ruby motion presentation
JavaScript
2
star
14

liveview_streams

Demo app to show liveview_streams memory usage
Elixir
1
star
15

ranch_hand_system_rpi

Elixir
1
star
16

dialyxir_issue

Elixir
1
star
17

gen_stage_playground

Elixir
1
star
18

distillery_config_example

Elixir
1
star
19

rubymotion-storyboard-playground

Rubymotion app playground with storyboards and appium
Ruby
1
star
20

dotfiles

My new, thoughtbot-based dotfiles.
Emacs Lisp
1
star
21

refactoring_example

Elixir
1
star
22

ranch_hand

Elixir
1
star
23

my_logger_app

Elixir
1
star
24

tds_deadlock_demo

Elixir
1
star
25

live_view_playground

Elixir
1
star
26

dotfiles-old

My OLD personal dotfiles
Vim Script
1
star
27

webcamery

Webcam gallery written in Phoenix
Elixir
1
star
28

nerves_system_rpi0_zbar

Elixir
1
star
29

browser_test_sandbox_poc

Elixir
1
star
30

live_view_textarea_test_helper_bug

Elixir
1
star
31

phx_gen_auth_playground

Elixir
1
star
32

sims

Elixir
1
star
33

durango-coders-rubymotion-demo

Demo app created at the DurangoCoders RubyMotion presentation
Ruby
1
star
34

phx_gen_auth_output

Elixir
1
star
35

wallaby_liveview_playground

Elixir
1
star
36

planet-express-demo

Planet Express Demo app from backbonerails.com
CoffeeScript
1
star
37

not_loaded_poison

Poison integration for NotLoaded (https://github.com/aaronrenner/not_loaded)
Elixir
1
star
38

stream-data-lazy-tree-zip-error

Elixir
1
star
39

omni_eye

Sample project from nerves training
Elixir
1
star
40

internet_monitor_system_rpi0

Elixir
1
star
41

deps_issue

Elixir
1
star
42

broken_schema

Elixir
1
star
43

pure_http

WIP
Elixir
1
star