X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Foauth%2Ftoken.ex;h=ea4d56a291ae08f5b37cadc60e4d7ef97986ebcb;hb=bc4f77b10bb4360ac00d1999b1d08fa55e1fa547;hp=ca9e718ac8a27b562c4de9936500f50bddc51b23;hpb=3b141194715e362d65482672d00b10991d102fa2;p=akkoma diff --git a/lib/pleroma/web/oauth/token.ex b/lib/pleroma/web/oauth/token.ex index ca9e718ac..ea4d56a29 100644 --- a/lib/pleroma/web/oauth/token.ex +++ b/lib/pleroma/web/oauth/token.ex @@ -16,6 +16,7 @@ defmodule Pleroma.Web.OAuth.Token do schema "oauth_tokens" do field(:token, :string) field(:refresh_token, :string) + field(:scopes, {:array, :string}, default: []) field(:valid_until, :naive_datetime) belongs_to(:user, Pleroma.User, type: Pleroma.FlakeId) belongs_to(:app, App) @@ -26,17 +27,19 @@ defmodule Pleroma.Web.OAuth.Token do 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)) + create_token(app, Repo.get(User, auth.user_id), auth.scopes) end end - def create_token(%App{} = app, %User{} = user) do + 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) token = %Token{ token: token, refresh_token: refresh_token, + scopes: scopes, user_id: user.id, app_id: app.id, valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), 60 * 10)