Hello all,
after some years working with elixir, there are still some situations I don’t know how to clearly resolve, thinking about putting together some best practices for ecto and other tools. To make it easy I decided to start project and simply document all issues I came along. Besides that I’m also trying a lot of stuff (using plug and ecto without phoenix, schemas folder instead of domain driven design style). So I’m asking here for opinion, maybe some constructive critics etc GitHub - tino415/authex: Simple API only OAuth2/OpenID server. So far I stumble on these:
-
I’m trying to follow CQRS and also to use changeset for most casting and validation
but I think these things sometimes get in conflict. In this case I got to conflict
when I was trying to validate creation of token. Because, in case o refresh token,
I need casted refresh token from data to retrieve previous token to verify it validity,
I resolved to what I always does, basically manually cast it in action (sort of controller)
and pass selected token to changeset.Action:
@impl true def create(conn, %{"code" => code} = params) do with %{} = flow <- Authex.get_flow_by_code_without_token(code) do do_create(conn, flow, params) else nil -> View.unauthorized(conn) end end def create(conn, %{"refresh_token" => refresh_token} = params) do with %{} = flow <- Authex.get_flow_by_refresh_token(refresh_token) do do_create(conn, flow, params) else nil -> View.unauthorized(conn) end end def create(conn, body_params) do do_create(conn, nil, body_params) end
-
I always tried to use
put_assoc
so result after inserting contains that association and
I don’t need to return associated entity separately, but in this project it does not
work. So I have this line after updating token:|> case do {:ok, client} -> {:ok, Repo.preload(client, scopes: :scope)} r -> r end