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:
|
case get_client_id_from_query(conn) do |
|
# no auth_client_id means the request is for auth app |
|
0 -> |
|
Auth.Log.info(conn, params) |
|
render_login_buttons(conn, params) |
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
|
client_id -> |
|
if client_id_valid?(client_id, conn) do |
|
msg = "request with client_id: #{client_id} (index:73)" |
|
Auth.Log.info(conn, Map.merge(params, %{msg: msg})) |
|
render_login_buttons(conn, params) |
|
else |
|
msg = "auth_client_id: #{client_id} is not valid (index:77)" |
|
Auth.Log.error(conn, Map.merge(params, %{msg: msg})) |
|
|
|
conn |
|
|> put_flash(:error, msg) |
|
|> unauthorized(msg) |
|
end |
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()
see https://github.com/dwyl/auth_plug/blob/77963c86483c78acb3f2fe386416d67b528607e8/lib/auth_plug.ex#L47-L51
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
indexcontroller which match the/endpoint:auth/lib/auth_web/controllers/auth_controller.ex
Lines 65 to 69 in 3a9d687
the second part of the
indexis used to authenticate user for another application. The user application redirect to the auth app and contains theauth_client_idquery parameter, eg:/?auth_client_id=123auth/lib/auth_web/controllers/auth_controller.ex
Lines 71 to 83 in 3a9d687
The redirection to the
authapp is done using theauth_pluglibrary:https://github.com/dwyl/auth_plug/blob/77963c86483c78acb3f2fe386416d67b528607e8/lib/auth_plug.ex#L32-L39
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:see https://github.com/dwyl/auth_plug/blob/77963c86483c78acb3f2fe386416d67b528607e8/lib/auth_plug.ex#L47-L51