This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def callback(%{assigns: %{ueberauth_auth: auth}} = conn, params) do | |
user_data = %{token: auth.credentials.token, email: auth.info.email, provider: "github"} | |
…… | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scope "/auth", OauthTutorialWeb do | |
pipe_through :browser | |
get "/:provider", AuthController, :request | |
get "/:provider/callback", AuthController, :callback | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule OauthTutorialWeb.AuthController do | |
use OauthTutorialWeb, :controller | |
plug Ueberauth | |
def callback(conn, params) do | |
IO.inspect(conn) | |
IO.inspect(params) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:ueberauth, "~> 0.7.0"}, | |
{:ueberauth_github, "~> 0.8.1"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule OauthTutorial.Accounts.User do | |
use Ecto.Schema | |
import Ecto.Changeset | |
schema "users" do | |
field :email, :string | |
field :provider, :string | |
field :token, :string | |
timestamps() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override def run(args: List[String]): IO[ExitCode] = { | |
//resource modules | |
lazy val infrastructureResourceModule = new InfrastructureResourceModule(config) | |
val programStream = | |
for { | |
//modules | |
.................... | |
//routes | |
.................... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |