Skip to content

Instantly share code, notes, and snippets.

def callback(%{assigns: %{ueberauth_auth: auth}} = conn, params) do
user_data = %{token: auth.credentials.token, email: auth.info.email, provider: "github"}
……
end
scope "/auth", OauthTutorialWeb do
pipe_through :browser
get "/:provider", AuthController, :request
get "/:provider/callback", AuthController, :callback
end
defmodule OauthTutorialWeb.AuthController do
use OauthTutorialWeb, :controller
plug Ueberauth
def callback(conn, params) do
IO.inspect(conn)
IO.inspect(params)
end
config :ueberauth, Ueberauth,
providers: [
github: {Ueberauth.Strategy.Github, [default_scope: "user:email"]}
]
config :ueberauth, Ueberauth.Strategy.Github.OAuth,
client_id: "your-client-id",
client_secret: "your-client-secret"
{:ueberauth, "~> 0.7.0"},
{:ueberauth_github, "~> 0.8.1"}
defmodule OauthTutorial.Repo.Migrations.CreateUsers do
use Ecto.Migration
def change do
create table(:users) do
add :email, :string
add :provider, :string
add :token, :string
timestamps()
defmodule OauthTutorial.Accounts.User do
use Ecto.Schema
import Ecto.Changeset
schema "users" do
field :email, :string
field :provider, :string
field :token, :string
timestamps()
# Configure your database
config :oauth_tutorial, OauthTutorial.Repo,
username: "postgres",
password: "your-password-goes-here",
hostname: "localhost",
database: "oauth_tutorial_dev",
stacktrace: true,
show_sensitive_data_on_connection_error: true,
pool_size: 10
override def run(args: List[String]): IO[ExitCode] = {
//resource modules
lazy val infrastructureResourceModule = new InfrastructureResourceModule(config)
val programStream =
for {
//modules
....................
//routes
....................
class PubSubModule(client: Client[IO], pubSubConfiguration: PubSubConfiguration)(implicit logger: Logger[IO]) {
lazy val pusSubProducerFactory = new PubSubProducerFactoryImpl(client, pubSubConfiguration)
lazy val orderProducer: Resource[IO, PubsubProducer[IO, OrderEvent]] =
pusSubProducerFactory.createProducer[OrderEvent](pubSubConfiguration.topics.orders)
}