oauth: add me property to token responses
This commit is contained in:
parent
34fc0dca2e
commit
e0edc706cf
@ -105,6 +105,7 @@ def token_exchange(conn, %{"grant_type" => "authorization_code"} = params) do
|
|||||||
fixed_token = fix_padding(params["code"]),
|
fixed_token = fix_padding(params["code"]),
|
||||||
%Authorization{} = auth <-
|
%Authorization{} = auth <-
|
||||||
Repo.get_by(Authorization, token: fixed_token, app_id: app.id),
|
Repo.get_by(Authorization, token: fixed_token, app_id: app.id),
|
||||||
|
%User{} = user <- Repo.get(User, auth.user_id),
|
||||||
{:ok, token} <- Token.exchange_token(app, auth),
|
{:ok, token} <- Token.exchange_token(app, auth),
|
||||||
{:ok, inserted_at} <- DateTime.from_naive(token.inserted_at, "Etc/UTC") do
|
{:ok, inserted_at} <- DateTime.from_naive(token.inserted_at, "Etc/UTC") do
|
||||||
response = %{
|
response = %{
|
||||||
@ -113,7 +114,8 @@ def token_exchange(conn, %{"grant_type" => "authorization_code"} = params) do
|
|||||||
refresh_token: token.refresh_token,
|
refresh_token: token.refresh_token,
|
||||||
created_at: DateTime.to_unix(inserted_at),
|
created_at: DateTime.to_unix(inserted_at),
|
||||||
expires_in: 60 * 10,
|
expires_in: 60 * 10,
|
||||||
scope: Enum.join(token.scopes, " ")
|
scope: Enum.join(token.scopes, " "),
|
||||||
|
me: user.ap_id
|
||||||
}
|
}
|
||||||
|
|
||||||
json(conn, response)
|
json(conn, response)
|
||||||
@ -142,7 +144,8 @@ def token_exchange(
|
|||||||
access_token: token.token,
|
access_token: token.token,
|
||||||
refresh_token: token.refresh_token,
|
refresh_token: token.refresh_token,
|
||||||
expires_in: 60 * 10,
|
expires_in: 60 * 10,
|
||||||
scope: Enum.join(token.scopes, " ")
|
scope: Enum.join(token.scopes, " "),
|
||||||
|
me: user.ap_id
|
||||||
}
|
}
|
||||||
|
|
||||||
json(conn, response)
|
json(conn, response)
|
||||||
|
@ -132,11 +132,12 @@ test "issues a token for an all-body request" do
|
|||||||
"client_secret" => app.client_secret
|
"client_secret" => app.client_secret
|
||||||
})
|
})
|
||||||
|
|
||||||
assert %{"access_token" => token} = json_response(conn, 200)
|
assert %{"access_token" => token, "me" => ap_id} = json_response(conn, 200)
|
||||||
|
|
||||||
token = Repo.get_by(Token, token: token)
|
token = Repo.get_by(Token, token: token)
|
||||||
assert token
|
assert token
|
||||||
assert token.scopes == auth.scopes
|
assert token.scopes == auth.scopes
|
||||||
|
assert user.ap_id == ap_id
|
||||||
end
|
end
|
||||||
|
|
||||||
test "issues a token for `password` grant_type with valid credentials, with full permissions by default" do
|
test "issues a token for `password` grant_type with valid credentials, with full permissions by default" do
|
||||||
|
Loading…
Reference in New Issue
Block a user