dwyl / elixir-auth-github-demo

:octocat: A fully working demo Phoenix app for GitHub Authentication using elixir-auth-github
https://elixir-auth-github-demo.fly.dev
GNU General Public License v2.0
16 stars 0 forks source link

(UndefinedFunctionError) function :crypto.hmac/3 is undefined or private #17

Closed nelsonic closed 2 years ago

nelsonic commented 2 years ago

The Heroku version of this demo app https://elixir-auth-github-demo.herokuapp.com is still working fine:

image

It's running on an older version of Elixir/OTP:

https://github.com/dwyl/elixir-auth-github-demo/blob/016e4c478c9e92adcf32b5a316695809b6e50d23/elixir_buildpack.config#L1-L5

Just tried to run the app on my localhost using:

elixir -v

Erlang/OTP 24 [erts-12.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit] [dtrace]
Elixir 1.12.3 (compiled with Erlang/OTP 24)

Getting the following error:

image

Full debug stack trace:

elixir-auth-github-demo % mix phx.server
MacOSX 10.7 or later required for --file-events
[info] Running AppWeb.Endpoint with cowboy 2.8.0 at 0.0.0.0:4000 (http)
[info] Access AppWeb.Endpoint at http://localhost:4000

Webpack is watching the files…

Browserslist: caniuse-lite is outdated. Please run next command `npm update`
Hash: 9439bca6a51bb9c45624
Version: webpack 4.4.0
Time: 586ms
Built at: 27/09/2021 08:49:52
                Asset       Size       Chunks             Chunk Names
       ../css/app.css   10.6 KiB  ./js/app.js  [emitted]  ./js/app.js
               app.js   7.26 KiB  ./js/app.js  [emitted]  ./js/app.js
       ../favicon.ico   1.23 KiB               [emitted]
../images/phoenix.png   13.6 KiB               [emitted]
        ../robots.txt  202 bytes               [emitted]
   [0] multi ./js/app.js 28 bytes {./js/app.js} [built]
[../deps/phoenix_html/priv/static/phoenix_html.js] 2.21 KiB {./js/app.js} [built]
[./css/app.css] 39 bytes {./js/app.js} [built]
[./js/app.js] 493 bytes {./js/app.js} [built]
    + 2 hidden modules
Child mini-css-extract-plugin node_modules/css-loader/index.js!css/app.css:
    [./node_modules/css-loader/index.js!./css/app.css] ./node_modules/css-loader!./css/app.css 288 bytes {mini-css-extract-plugin} [built]
    [./node_modules/css-loader/index.js!./css/phoenix.css] ./node_modules/css-loader!./css/phoenix.css 10.9 KiB {mini-css-extract-plugin} [built]
        + 1 hidden module
[info] GET /
[debug] Processing with AppWeb.PageController.index/2
  Parameters: %{}
  Pipelines: [:browser]
[debug] Converted error UndefinedFunctionError to 500 response
[error] #PID<0.534.0> running AppWeb.Endpoint (connection #PID<0.533.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /
** (exit) an exception was raised:
    ** (UndefinedFunctionError) function :crypto.hmac/3 is undefined or private
        (crypto 5.0.2) :crypto.hmac/3
        (plug_crypto 1.1.2) lib/plug/crypto/key_generator.ex:81: Plug.Crypto.KeyGenerator.generate/7
        (plug_crypto 1.1.2) lib/plug/crypto/key_generator.ex:67: Plug.Crypto.KeyGenerator.with_cache/3
        (plug_crypto 1.1.2) lib/plug/crypto/key_generator.ex:51: Plug.Crypto.KeyGenerator.generate/6
        (plug 1.10.4) lib/plug/session/cookie.ex:96: Plug.Session.COOKIE.get/3
        (plug 1.10.4) lib/plug/session.ex:71: anonymous fn/5 in Plug.Session.fetch_session/1
        (plug 1.10.4) lib/plug/debugger.ex:277: Plug.Debugger.maybe_fetch_session/1
        (plug 1.10.4) lib/plug/debugger.ex:183: Plug.Debugger.render/6
        (plug 1.10.4) lib/plug/debugger.ex:158: Plug.Debugger.__catch__/5
        (app 1.4.0) lib/app_web/endpoint.ex:1: AppWeb.Endpoint.call/2
        (phoenix 1.5.4) lib/phoenix/endpoint/cowboy2_handler.ex:65: Phoenix.Endpoint.Cowboy2Handler.init/4
        (cowboy 2.8.0) ~/code/elixir-auth-github-demo/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
        (cowboy 2.8.0) ~/code/elixir-auth-github-demo/deps/cowboy/src/cowboy_stream_h.erl:300: :cowboy_stream_h.execute/3
        (cowboy 2.8.0) ~/code/elixir-auth-github-demo/deps/cowboy/src/cowboy_stream_h.erl:291: :cowboy_stream_h.request_process/3
        (stdlib 3.15.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

Need to get back to my "day job" work, so need to come back to this later.

Todo

nelsonic commented 2 years ago

Looks like updating Phoenix (and all deps, specifically plug_crypt) will solve this: https://elixirforum.com/t/undefinedfunctionerror-function-crypto-hmac-3-is-undefined-or-private/40060

As per: https://github.com/dwyl/learn-phoenix-framework/issues/143#issuecomment-927660108

      {:phoenix, "~> 1.6.0"},
      {:phoenix_ecto, "~> 4.4"},
      {:ecto_sql, "~> 3.6"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 3.0"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:phoenix_live_view, "~> 0.16.4"},
      {:floki, ">= 0.30.0", only: :test},
      {:phoenix_live_dashboard, "~> 0.5"},
      {:esbuild, "~> 0.2", runtime: Mix.env() == :dev},
      {:swoosh, "~> 1.3"},
      {:telemetry_metrics, "~> 0.6"},
      {:telemetry_poller, "~> 1.0"},
      {:gettext, "~> 0.18"},
      {:jason, "~> 1.2"},
      {:plug_cowboy, "~> 2.5"}
nelsonic commented 2 years ago

Update to Phoenix 1.6 going smoothly. All tests pass (as expected).

The app boots fine: image

And OAuth link works:

image

But when I attempt to sign in I get the following error:

image

[info] GET /auth/github/callback
[debug] Processing with AppWeb.GithubAuthController.index/2
  Parameters: %{"code" => "ac0098aaredacted"}
  Pipelines: [:browser]
[info] TLS :client: In state :wait_cert_cr at ssl_handshake.erl:1990 generated CLIENT ALERT: Fatal - Handshake Failure
 - {:bad_cert, :hostname_check_failed}
[info] Sent 500 in 373ms
[error] #PID<0.718.0> running AppWeb.Endpoint (connection #PID<0.717.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /auth/github/callback?code=ac0098aaredacted
** (exit) an exception was raised:
    ** (HTTPoison.Error) {:tls_alert, {:handshake_failure, 'TLS client: In state wait_cert_cr at ssl_handshake.erl:1990 generated CLIENT ALERT: Fatal - Handshake Failure\n {bad_cert,hostname_check_failed}'}}
        (httpoison 1.7.0) lib/httpoison.ex:128: HTTPoison.request!/5
        (elixir_auth_github 1.4.0) lib/elixir_auth_github.ex:79: ElixirAuthGithub.get_user_details/1
        (app 1.4.0) lib/app_web/controllers/github_auth_controller.ex:9: AppWeb.GithubAuthController.index/2
        (app 1.4.0) lib/app_web/controllers/github_auth_controller.ex:1: AppWeb.GithubAuthController.action/2
        (app 1.4.0) lib/app_web/controllers/github_auth_controller.ex:1: AppWeb.GithubAuthController.phoenix_controller_pipeline/2
        (phoenix 1.6.0) lib/phoenix/router.ex:355: Phoenix.Router.__call__/2
        (app 1.4.0) lib/app_web/endpoint.ex:1: AppWeb.Endpoint.plug_builder_call/2
        (app 1.4.0) lib/plug/debugger.ex:136: AppWeb.Endpoint."call (overridable 3)"/2
        (app 1.4.0) lib/app_web/endpoint.ex:1: AppWeb.Endpoint.call/2
        (phoenix 1.6.0) lib/phoenix/endpoint/cowboy2_handler.ex:43: Phoenix.Endpoint.Cowboy2Handler.init/4
        (cowboy 2.9.0) ~/code/elixir-auth-github-demo/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
        (cowboy 2.9.0) ~/code/elixir-auth-github-demo/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3
        (cowboy 2.9.0) ~/code/elixir-auth-github-demo/deps/cowboy/src/cowboy_stream_h.erl:295: :cowboy_stream_h.request_process/3
        (stdlib 3.15.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
nelsonic commented 2 years ago

Looks like we might need to update the underlying HTTPoision dependency in the parent package. 💭

nelsonic commented 2 years ago

Works flawlessly on localhost with latest Elixir & Phoenix: image

🚀

nelsonic commented 2 years ago

PR: #18