Auth0 "Authentication Error" without any helpful details

I followed the instructions for Ash Authentication Phoenix and got password auth working with some help. Then I tried to switch to Auth0 using this quickstart: https://ash-hq.org/docs/guides/ash_authentication/latest/tutorials/auth0-quickstart Here are the changes I ended up with https://github.com/dewetblomerus/red/pull/2/files Now, when I click the "Sign In" button and go to /sign-in I see a nice "Sign in with Auth0" button. When I click it, I go to /auth/user/auth0 which renders a blank page with the words: "Authentication Error". Server logs:
[info] GET /auth/user/auth0
[debug] Processing with RedWeb.AuthController
Parameters: %{}
Pipelines: [:browser]
[info] Sent 401 in 13ms
[info] GET /auth/user/auth0
[debug] Processing with RedWeb.AuthController
Parameters: %{}
Pipelines: [:browser]
[info] Sent 401 in 13ms
My versions of things:
ash, "2.14.20"
ash_authentication, "3.11.15"
ash_authentication_phoenix, "1.8.3"
ash, "2.14.20"
ash_authentication, "3.11.15"
ash_authentication_phoenix, "1.8.3"
10 Replies
ZachDaniel
ZachDaniel2y ago
So the first step is to look in your auth controller and print out the reason in the failure hook That authentication failure page is just a placeholder for what you might do on a critical failure. Typically instead of rendering the failure template you’d redirect to the sign in page with a flash message or something like that.
dewet
dewetOP2y ago
reason #=> %AshAuthentication.Errors.MissingSecret{
resource: Red.Accounts.User,
changeset: nil,
query: nil,
error_context: [],
vars: [],
path: [:authentication, :strategies, :auth0, :client_id],
stacktrace: #Stacktrace<>,
class: :forbidden
}
reason #=> %AshAuthentication.Errors.MissingSecret{
resource: Red.Accounts.User,
changeset: nil,
query: nil,
error_context: [],
vars: [],
path: [:authentication, :strategies, :auth0, :client_id],
stacktrace: #Stacktrace<>,
class: :forbidden
}
activity #=> {:auth0, :request} Should I be looking at my Secrets module that has: use AshAuthentication.Secret? It is using Application.fetch_env!/2 so the values definitely exist. Or is it my User resources that needs a secret attribute? I found something! I tried this:
def secret_for([:authentication, :strategies, :auth0, :redirect_uri], Red.Accounts.User, _) do
get_config(:redirect_uri)
|> dbg()
end
def secret_for([:authentication, :strategies, :auth0, :redirect_uri], Red.Accounts.User, _) do
get_config(:redirect_uri)
|> dbg()
end
And saw this: get_config(:redirect_uri) #=> :error I typed uri in the Secrets module and url in my config. I'll make a suggested edit to the docs so that people will see an immediate error pointing to the problem if they do this. It would have been nice if the Secrets module raised an error for me, letting me know that I did not supply a proper binary.
ZachDaniel
ZachDaniel2y ago
Yeah, that makes sense, there should have been an explicit "internal" error raised that would tell you a secret was missing If you get a chance, could you open an error on ash_authentication with that info?
dewet
dewetOP2y ago
A github issue?
ZachDaniel
ZachDaniel2y ago
yep! If you have time
dewet
dewetOP2y ago
Will do. No problem. Thanks for the help! Today I learned to translate "This error must be happening somewhere in the framework" to "Let me see if this error is inspectable from code I wrote".
dewet
dewetOP2y ago
GitHub
Helpful Error from AshAuthentication.Secret secret_for · Issue ...
Trying to set up Auth0 using this guide I got to the login error page, but no errors were raised. Here is the reason from the AuthController: reason #=> %AshAuthentication.Errors.MissingSecret{ ...
ZachDaniel
ZachDaniel2y ago
Hey @dewet perhaps if you have a minute you could offer up your experience using auth0 here? They seem to have had some trouble during the implementation: https://elixirforum.com/t/a-toy-project-in-a-non-toy-framework-observe-my-journey-as-a-phoenix-veteran-trying-out-ash-for-the-first-time/58465/22
Elixir Programming Language Forum
A toy project in a non-toy framework. Observe my journey as a Phoen...
@olivermt really enjoying reading about your journey and thought process. Thanks very much for sharing. Please keep going!
dewet
dewetOP2y ago
I took a read through but I don't have anything to add. I ended up running into another error and didn't know how to debug it. I can make a post on ElixirForum.
ZachDaniel
ZachDaniel2y ago
😦 Definitely post about it and we’ll help out

Did you find this page helpful?