- def create_token(%App{} = app, %User{} = user) do
- token = :crypto.strong_rand_bytes(32) |> Base.url_encode64
- refresh_token = :crypto.strong_rand_bytes(32) |> Base.url_encode64
+ def exchange_token(app, auth) do
+ with {:ok, auth} <- Authorization.use_token(auth),
+ true <- auth.app_id == app.id do
+ create_token(app, Repo.get(User, auth.user_id), auth.scopes)
+ end
+ end
+
+ def create_token(%App{} = app, %User{} = user, scopes \\ nil) do
+ scopes = scopes || app.scopes
+ token = :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false)
+ refresh_token = :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false)