Auth Application Workflow? [Docs]
- Dominant language
- Elixir
- Stars
- 141
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
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:
https://github.com/dwyl/auth/blob/3a9d68720c02d2a8bdec33ffd8b70c35a4e5289a/lib/auth_web/controllers/auth_controller.ex#L65-L69
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`
https://github.com/dwyl/auth/blob/3a9d68720c02d2a8bdec33ffd8b70c35a4e5289a/lib/auth_web/controllers/auth_controller.ex#L71-L83
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
```elixir
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`:
```elixir
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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.