Description
It took me a while to understand the workflow of the app after not working on it for a while. This issue contains my notes while I'm going over the code again. I'll convert them to documentation in the Readme and hopefully this will also help with #149
The application let you authenticate with Google, Github or by email:
This is done with the first part of the index
controller which match the /
endpoint:
auth/lib/auth_web/controllers/auth_controller.ex
Lines 65 to 69 in 3a9d687
the second part of the index
is used to authenticate user for another application. The user application redirect to the auth app and contains the auth_client_id
query parameter, eg: /?auth_client_id=123
auth/lib/auth_web/controllers/auth_controller.ex
Lines 71 to 83 in 3a9d687
The redirection to the
auth
app is done using the auth_plug
library:https://github.com/dwyl/auth_plug/blob/77963c86483c78acb3f2fe386416d67b528607e8/lib/auth_plug.ex#L32-L39
case AuthPlug.Token.verify_jwt(jwt) do
{:ok, values} ->
AuthPlug.Token.put_current_token(conn, jwt, values)
# log the JWT verify error then redirect:
{:error, reason} ->
Logger.error("AuthPlug: " <> Kernel.inspect(reason))
redirect_to_auth(conn, options) # redirect to auth application
end
We can see that a jwt is validated and if it fails the user application redirect to the auth app with the auth_client_id
:
to =
opts.auth_url <>
"?referer=" <>
URI.encode(baseurl <> conn.request_path) <>
"&auth_client_id=" <> AuthPlug.Token.client_id()