I’m trying to setup Guardian to work with Phoenix and Ldap. I seem to be stuck with some configuration . My Guardian config looks roughly like this:
config :guardian, Guardian,
allowed_algos: ["HS512"],
verify_module: Guardian.JWT,
issuer: "Issuer",
ttl: { 30, :days},
verify_issuer: true,
secret_key: <MY KEY>,
serializer: MyApp.Auth.GuardianSerializer
I have a SessionController
where I’m hitting Ldap and then doing something like this:
case Ldap.authenticate(username, password) do
:ok -> handle_sign_in(conn, username)
_ -> handle_error(conn)
end
{:ok, user} = lookup_user(username)
conn
|> put_flash(:info, "Logged in.")
|> MyApp.Auth.Guardian.Plug.sign_in(user)
|> redirect(to: "/")
The Ldap portion is working fine, but I keep getting this error from Guardian:
Request: POST /sign_in
** (exit) an exception was raised:
** (RuntimeError) No secret key configured for JWT
(guardian) lib/guardian/token/jwt.ex:319: Guardian.Token.Jwt.fetch_secret/2
(guardian) lib/guardian/token/jwt.ex:163: Guardian.Token.Jwt.create_token/3
(guardian) lib/guardian.ex:754: Guardian.returning_tuple/1
(guardian) lib/guardian.ex:581: Guardian.encode_and_sign/4
(guardian) lib/guardian/plug.ex:172: Guardian.Plug.sign_in/5
(infrared) lib/myapp_web/controllers/session_controller.ex:23: MyAppWeb.SessionController.handle_sign_in/2
(infrared) lib/myapp_web/controllers/session_controller.ex:1: MyAppWeb.SessionController.action/2
(infrared) lib/myapp_web/controllers/session_controller.ex:1: MyAppWeb.SessionController.phoenix_controller_pipeline/2
(infrared) lib/myapp_web/endpoint.ex:1: MyAppWeb.Endpoint.instrument/4
(phoenix) lib/phoenix/router.ex:278: Phoenix.Router.__call__/1
(infrared) lib/myapp_web/endpoint.ex:1: MyAppWeb.Endpoint.plug_builder_call/2
(infrared) lib/plug/debugger.ex:99: MyAppWeb.Endpoint."call (overridable 3)"/2
(infrared) lib/myapp_web/endpoint.ex:1: MyAppWeb.Endpoint.call/2
(plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
I can’t tell if this is a config issue on my side or a bug. Any help would be much appreciated.