Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ukrit-himakoon opened this issue Oct 29, 2017 · 4 comments
Labels

Comments

@ukrit-himakoon
Copy link

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
Copy link
Member

@ukrit-himakoon
Copy link
Author

ukrit-himakoon commented Nov 1, 2017

;) 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
Copy link

@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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants