ueberauth / ueberauth_example

Example Phoenix application using Überauth for authentication
http://ueberauth-example.herokuapp.com
MIT License
220 stars 73 forks source link

login with username/password got cookie store expects conn.secret_key_base to be set #37

Closed ukrit-himakoon closed 5 years ago

ukrit-himakoon commented 7 years ago

It happens with sign in with username/password Can anyone help to solve this?

osboxes@osboxes:~/projects/ueberauth_example$ sudo mix phoenix.server 
Compiling 13 files (.ex)
Generated ueberauth_example app
[info] Running UeberauthExample.Endpoint with Cowboy using http://localhost:4000
29 Oct 05:44:40 - info: compiled 5 files into 2 files, copied 3 in 4257ms
[info] GET /
[debug] Processing by UeberauthExample.PageController.index/2
  Parameters: %{}
  Pipelines: [:browser]
[info] Sent 200 in 79ms
[error] backend port not found: :inotifywait

[info] GET /auth/identity
[debug] Processing by UeberauthExample.AuthController.request/2
  Parameters: %{"provider" => "identity"}
  Pipelines: [:browser]
[info] Sent 500 in 160ms
[error] #PID<0.515.0> running UeberauthExample.Endpoint terminated
Server: localhost:4000 (http)
Request: GET /auth/identity
** (exit) an exception was raised:
    ** (ArgumentError) cookie store expects conn.secret_key_base to be set
        (plug) lib/plug/session/cookie.ex:157: Plug.Session.COOKIE.validate_secret_key_base/1
        (plug) lib/plug/session/cookie.ex:152: Plug.Session.COOKIE.derive/3
        (plug) lib/plug/session/cookie.ex:103: Plug.Session.COOKIE.put/4
        (plug) lib/plug/session.ex:92: anonymous fn/3 in Plug.Session.before_send/2
        (elixir) lib/enum.ex:1623: Enum."-reduce/3-lists^foldl/2-0-"/3
        (plug) lib/plug/conn.ex:961: Plug.Conn.run_before_send/2
        (plug) lib/plug/conn.ex:392: Plug.Conn.send_resp/1
        (ueberauth_example) web/controllers/auth_controller.ex:1: UeberauthExample.AuthController.action/2
        (ueberauth_example) web/controllers/auth_controller.ex:1: UeberauthExample.AuthController.phoenix_controller_pipeline/2
        (ueberauth_example) lib/ueberauth_example/endpoint.ex:1: UeberauthExample.Endpoint.instrument/4
        (ueberauth_example) lib/phoenix/router.ex:261: UeberauthExample.Router.dispatch/2
        (ueberauth_example) web/router.ex:1: UeberauthExample.Router.do_call/2
        (ueberauth_example) lib/ueberauth_example/endpoint.ex:1: UeberauthExample.Endpoint.phoenix_pipeline/1
        (ueberauth_example) lib/plug/debugger.ex:123: UeberauthExample.Endpoint."call (overridable 3)"/2
        (ueberauth_example) lib/ueberauth_example/endpoint.ex:1: UeberauthExample.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
doomspork commented 7 years ago

@ukrit-himakoon I suspect you're missing this value: https://github.com/ueberauth/ueberauth_example/blob/master/config/prod.secret.exs#L7

ukrit-himakoon commented 7 years ago

;) Thanks, sorry that I'm kinda new to phoenix.

So I need to run example in production only? How to add this to dev?

AlchemistCamp commented 5 years ago

@ukrit-himakoon You're seeing this issue because this app breaks with the Phoenix conventions of putting this value in your config files. That's probably since they deployed on Heroku, and chose to inject settings from the OS environment variables instead of config files.

You can use mix phx.gen.secret to create a new secret and then paste that value into the secret_key_base: section of your config.exs file. Then do it again for prod.secret.exs and do not track prod.secret.exs in your source control. Instead, manually copy it to your server with SCP. You'll need to either do the same with the oauth files where there's a System.get_env in the repo or else actually set those system environment variables in your shell before running Phoenix.

Note: If you generate a new app with mix phx.new my_app you can see how config and secrets like this are handled in a typical app.

doomspork commented 5 years ago

@AlchemistCamp we'd love contributions from the community's help to improve these examples 😁