Skip to content

Instantly share code, notes, and snippets.

View javierg's full-sized avatar

Javier Guerra javierg

View GitHub Profile
defp deps do
[
...
{:guardian, "~> 0.13.0"}
]
end
alias PhoenixUeberauthComeonin.Repo
Repo.insert! %User{
name: "Administrator",
email: "admin@admin.com",
password: Comeonin.Bcrypt.hashpwsalt("admin")
}
defmodule User do
use PhoenixUeberauthComeonin.Web, :model
import Comeonin.Bcrypt
alias Ueberauth.Auth
alias PhoenixUeberauthComeonin.Repo
schema "users" do
field :name, :string
<%= form_tag @callback_url, method: "post", class: "login", novalidate: true do %>
<div class="control-group">
<label class="control-label" for="email-input">Email</label>
<input class="form-control" type="email" name="email" value="<%= @conn.params["email"] %>" required />
</div>
<div class="control-group">
<label class="control-label" for="password-input">Password</label>
<input class="form-control" type="password" name="password" required />
</div>
defmodule PhoenixUeberauthComeonin.SessionsView do
use PhoenixUeberauthComeonin.Web, :view
end
defmodule PhoenixUeberauthComeonin.SessionsController do
use PhoenixUeberauthComeonin.Web, :controller
alias Ueberauth.Strategy.Helpers
plug Ueberauth
def new(conn, _params) do
render conn, "new.html", callback_url: Helpers.callback_url(conn)
end
scope "/sessions", PhoenixUeberauthComeonin do
pipe_through [:browser]
get "/new", SessionsController, :new
post "/identity/callback", SessionsController,
:identity_callback
end
config :ueberauth, Ueberauth,
providers: [
identity: { Ueberauth.Strategy.Identity, [
callback_methods: ["POST"],
uid_field: :email,
nickname_field: :email,
request_path: "/sessions/new",
callback_path: "/sessions/identity/callback",
]}
]
def application do
[mod: {PhoenixUeberauthComeonin, []},
applications: [
...
ueberauth,
ueberauth_identity,
...
defp deps do
[...
{:ueberauth, "~> 0.4"},
{:ueberauth_identity, "~> 0.2"},
...]