1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.OAuth.OAuthControllerTest do
6 use Pleroma.Web.ConnCase
11 alias Pleroma.Web.OAuth.Authorization
12 alias Pleroma.Web.OAuth.OAuthController
13 alias Pleroma.Web.OAuth.Token
18 signing_salt: "cooldude"
20 clear_config_all([:instance, :account_activation_required])
22 describe "in OAuth consumer mode, " do
25 app: insert(:oauth_app),
28 |> Plug.Session.call(Plug.Session.init(@session_opts))
33 clear_config([:auth, :oauth_consumer_strategies]) do
35 [:auth, :oauth_consumer_strategies],
40 test "GET /oauth/authorize renders auth forms, including OAuth consumer form", %{
49 "response_type" => "code",
50 "client_id" => app.client_id,
51 "redirect_uri" => OAuthController.default_redirect_uri(app),
56 assert response = html_response(conn, 200)
57 assert response =~ "Sign in with Twitter"
58 assert response =~ o_auth_path(conn, :prepare_request)
61 test "GET /oauth/prepare_request encodes parameters as `state` and redirects", %{
68 "/oauth/prepare_request",
70 "provider" => "twitter",
72 "scope" => "read follow",
73 "client_id" => app.client_id,
74 "redirect_uri" => OAuthController.default_redirect_uri(app),
80 assert response = html_response(conn, 302)
82 redirect_query = URI.parse(redirected_to(conn)).query
83 assert %{"state" => state_param} = URI.decode_query(redirect_query)
84 assert {:ok, state_components} = Poison.decode(state_param)
86 expected_client_id = app.client_id
87 expected_redirect_uri = app.redirect_uris
90 "scope" => "read follow",
91 "client_id" => ^expected_client_id,
92 "redirect_uri" => ^expected_redirect_uri,
97 test "with user-bound registration, GET /oauth/<provider>/callback redirects to `redirect_uri` with `code`",
98 %{app: app, conn: conn} do
99 registration = insert(:registration)
100 redirect_uri = OAuthController.default_redirect_uri(app)
103 "scope" => Enum.join(app.scopes, " "),
104 "client_id" => app.client_id,
105 "redirect_uri" => redirect_uri,
111 |> assign(:ueberauth_auth, %{provider: registration.provider, uid: registration.uid})
113 "/oauth/twitter/callback",
115 "oauth_token" => "G-5a3AAAAAAAwMH9AAABaektfSM",
116 "oauth_verifier" => "QZl8vUqNvXMTKpdmUnGejJxuHG75WWWs",
117 "provider" => "twitter",
118 "state" => Poison.encode!(state_params)
122 assert response = html_response(conn, 302)
123 assert redirected_to(conn) =~ ~r/#{redirect_uri}\?code=.+/
126 test "with user-unbound registration, GET /oauth/<provider>/callback renders registration_details page",
127 %{app: app, conn: conn} do
131 "scope" => "read write",
132 "client_id" => app.client_id,
133 "redirect_uri" => OAuthController.default_redirect_uri(app),
139 |> assign(:ueberauth_auth, %{
142 info: %{nickname: user.nickname, email: user.email, name: user.name, description: nil}
145 "/oauth/twitter/callback",
147 "oauth_token" => "G-5a3AAAAAAAwMH9AAABaektfSM",
148 "oauth_verifier" => "QZl8vUqNvXMTKpdmUnGejJxuHG75WWWs",
149 "provider" => "twitter",
150 "state" => Poison.encode!(state_params)
154 assert response = html_response(conn, 200)
155 assert response =~ ~r/name="op" type="submit" value="register"/
156 assert response =~ ~r/name="op" type="submit" value="connect"/
157 assert response =~ user.email
158 assert response =~ user.nickname
161 test "on authentication error, GET /oauth/<provider>/callback redirects to `redirect_uri`", %{
166 "scope" => Enum.join(app.scopes, " "),
167 "client_id" => app.client_id,
168 "redirect_uri" => OAuthController.default_redirect_uri(app),
174 |> assign(:ueberauth_failure, %{errors: [%{message: "(error description)"}]})
176 "/oauth/twitter/callback",
178 "oauth_token" => "G-5a3AAAAAAAwMH9AAABaektfSM",
179 "oauth_verifier" => "QZl8vUqNvXMTKpdmUnGejJxuHG75WWWs",
180 "provider" => "twitter",
181 "state" => Poison.encode!(state_params)
185 assert response = html_response(conn, 302)
186 assert redirected_to(conn) == app.redirect_uris
187 assert get_flash(conn, :error) == "Failed to authenticate: (error description)."
190 test "GET /oauth/registration_details renders registration details form", %{
197 "/oauth/registration_details",
199 "authorization" => %{
200 "scopes" => app.scopes,
201 "client_id" => app.client_id,
202 "redirect_uri" => OAuthController.default_redirect_uri(app),
203 "state" => "a_state",
205 "email" => "john@doe.com"
210 assert response = html_response(conn, 200)
211 assert response =~ ~r/name="op" type="submit" value="register"/
212 assert response =~ ~r/name="op" type="submit" value="connect"/
215 test "with valid params, POST /oauth/register?op=register redirects to `redirect_uri` with `code`",
220 registration = insert(:registration, user: nil, info: %{"nickname" => nil, "email" => nil})
221 redirect_uri = OAuthController.default_redirect_uri(app)
225 |> put_session(:registration_id, registration.id)
230 "authorization" => %{
231 "scopes" => app.scopes,
232 "client_id" => app.client_id,
233 "redirect_uri" => redirect_uri,
234 "state" => "a_state",
235 "nickname" => "availablenick",
236 "email" => "available@email.com"
241 assert response = html_response(conn, 302)
242 assert redirected_to(conn) =~ ~r/#{redirect_uri}\?code=.+/
245 test "with unlisted `redirect_uri`, POST /oauth/register?op=register results in HTTP 401",
250 registration = insert(:registration, user: nil, info: %{"nickname" => nil, "email" => nil})
251 unlisted_redirect_uri = "http://cross-site-request.com"
255 |> put_session(:registration_id, registration.id)
260 "authorization" => %{
261 "scopes" => app.scopes,
262 "client_id" => app.client_id,
263 "redirect_uri" => unlisted_redirect_uri,
264 "state" => "a_state",
265 "nickname" => "availablenick",
266 "email" => "available@email.com"
271 assert response = html_response(conn, 401)
274 test "with invalid params, POST /oauth/register?op=register renders registration_details page",
279 another_user = insert(:user)
280 registration = insert(:registration, user: nil, info: %{"nickname" => nil, "email" => nil})
284 "authorization" => %{
285 "scopes" => app.scopes,
286 "client_id" => app.client_id,
287 "redirect_uri" => OAuthController.default_redirect_uri(app),
288 "state" => "a_state",
289 "nickname" => "availablenickname",
290 "email" => "available@email.com"
294 for {bad_param, bad_param_value} <-
295 [{"nickname", another_user.nickname}, {"email", another_user.email}] do
296 bad_registration_attrs = %{
297 "authorization" => Map.put(params["authorization"], bad_param, bad_param_value)
300 bad_params = Map.merge(params, bad_registration_attrs)
304 |> put_session(:registration_id, registration.id)
305 |> post("/oauth/register", bad_params)
307 assert html_response(conn, 403) =~ ~r/name="op" type="submit" value="register"/
308 assert get_flash(conn, :error) == "Error: #{bad_param} has already been taken."
312 test "with valid params, POST /oauth/register?op=connect redirects to `redirect_uri` with `code`",
317 user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt("testpassword"))
318 registration = insert(:registration, user: nil)
319 redirect_uri = OAuthController.default_redirect_uri(app)
323 |> put_session(:registration_id, registration.id)
328 "authorization" => %{
329 "scopes" => app.scopes,
330 "client_id" => app.client_id,
331 "redirect_uri" => redirect_uri,
332 "state" => "a_state",
333 "name" => user.nickname,
334 "password" => "testpassword"
339 assert response = html_response(conn, 302)
340 assert redirected_to(conn) =~ ~r/#{redirect_uri}\?code=.+/
343 test "with unlisted `redirect_uri`, POST /oauth/register?op=connect results in HTTP 401`",
348 user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt("testpassword"))
349 registration = insert(:registration, user: nil)
350 unlisted_redirect_uri = "http://cross-site-request.com"
354 |> put_session(:registration_id, registration.id)
359 "authorization" => %{
360 "scopes" => app.scopes,
361 "client_id" => app.client_id,
362 "redirect_uri" => unlisted_redirect_uri,
363 "state" => "a_state",
364 "name" => user.nickname,
365 "password" => "testpassword"
370 assert response = html_response(conn, 401)
373 test "with invalid params, POST /oauth/register?op=connect renders registration_details page",
379 registration = insert(:registration, user: nil)
383 "authorization" => %{
384 "scopes" => app.scopes,
385 "client_id" => app.client_id,
386 "redirect_uri" => OAuthController.default_redirect_uri(app),
387 "state" => "a_state",
388 "name" => user.nickname,
389 "password" => "wrong password"
395 |> put_session(:registration_id, registration.id)
396 |> post("/oauth/register", params)
398 assert html_response(conn, 401) =~ ~r/name="op" type="submit" value="connect"/
399 assert get_flash(conn, :error) == "Invalid Username/Password"
403 describe "GET /oauth/authorize" do
406 app: insert(:oauth_app, redirect_uris: "https://redirect.url"),
409 |> Plug.Session.call(Plug.Session.init(@session_opts))
414 test "renders authentication page", %{app: app, conn: conn} do
420 "response_type" => "code",
421 "client_id" => app.client_id,
422 "redirect_uri" => OAuthController.default_redirect_uri(app),
427 assert html_response(conn, 200) =~ ~s(type="submit")
430 test "properly handles internal calls with `authorization`-wrapped params", %{
439 "authorization" => %{
440 "response_type" => "code",
441 "client_id" => app.client_id,
442 "redirect_uri" => OAuthController.default_redirect_uri(app),
448 assert html_response(conn, 200) =~ ~s(type="submit")
451 test "renders authentication page if user is already authenticated but `force_login` is tru-ish",
452 %{app: app, conn: conn} do
453 token = insert(:oauth_token, app_id: app.id)
457 |> put_session(:oauth_token, token.token)
461 "response_type" => "code",
462 "client_id" => app.client_id,
463 "redirect_uri" => OAuthController.default_redirect_uri(app),
465 "force_login" => "true"
469 assert html_response(conn, 200) =~ ~s(type="submit")
472 test "renders authentication page if user is already authenticated but user request with another client",
477 token = insert(:oauth_token, app_id: app.id)
481 |> put_session(:oauth_token, token.token)
485 "response_type" => "code",
486 "client_id" => "another_client_id",
487 "redirect_uri" => OAuthController.default_redirect_uri(app),
492 assert html_response(conn, 200) =~ ~s(type="submit")
495 test "with existing authentication and non-OOB `redirect_uri`, redirects to app with `token` and `state` params",
500 token = insert(:oauth_token, app_id: app.id)
504 |> put_session(:oauth_token, token.token)
508 "response_type" => "code",
509 "client_id" => app.client_id,
510 "redirect_uri" => OAuthController.default_redirect_uri(app),
511 "state" => "specific_client_state",
516 assert URI.decode(redirected_to(conn)) ==
517 "https://redirect.url?access_token=#{token.token}&state=specific_client_state"
520 test "with existing authentication and unlisted non-OOB `redirect_uri`, redirects without credentials",
525 unlisted_redirect_uri = "http://cross-site-request.com"
526 token = insert(:oauth_token, app_id: app.id)
530 |> put_session(:oauth_token, token.token)
534 "response_type" => "code",
535 "client_id" => app.client_id,
536 "redirect_uri" => unlisted_redirect_uri,
537 "state" => "specific_client_state",
542 assert redirected_to(conn) == unlisted_redirect_uri
545 test "with existing authentication and OOB `redirect_uri`, redirects to app with `token` and `state` params",
550 token = insert(:oauth_token, app_id: app.id)
554 |> put_session(:oauth_token, token.token)
558 "response_type" => "code",
559 "client_id" => app.client_id,
560 "redirect_uri" => "urn:ietf:wg:oauth:2.0:oob",
565 assert html_response(conn, 200) =~ "Authorization exists"
569 describe "POST /oauth/authorize" do
570 test "redirects with oauth authorization" do
572 app = insert(:oauth_app, scopes: ["read", "write", "follow"])
573 redirect_uri = OAuthController.default_redirect_uri(app)
577 |> post("/oauth/authorize", %{
578 "authorization" => %{
579 "name" => user.nickname,
580 "password" => "test",
581 "client_id" => app.client_id,
582 "redirect_uri" => redirect_uri,
583 "scope" => "read:subscope write",
584 "state" => "statepassed"
588 target = redirected_to(conn)
589 assert target =~ redirect_uri
591 query = URI.parse(target).query |> URI.query_decoder() |> Map.new()
593 assert %{"state" => "statepassed", "code" => code} = query
594 auth = Repo.get_by(Authorization, token: code)
596 assert auth.scopes == ["read:subscope", "write"]
599 test "returns 401 for wrong credentials", %{conn: conn} do
601 app = insert(:oauth_app)
602 redirect_uri = OAuthController.default_redirect_uri(app)
606 |> post("/oauth/authorize", %{
607 "authorization" => %{
608 "name" => user.nickname,
609 "password" => "wrong",
610 "client_id" => app.client_id,
611 "redirect_uri" => redirect_uri,
612 "state" => "statepassed",
613 "scope" => Enum.join(app.scopes, " ")
616 |> html_response(:unauthorized)
619 assert result =~ app.client_id
620 assert result =~ redirect_uri
623 assert result =~ "Invalid Username/Password"
626 test "returns 401 for missing scopes", %{conn: conn} do
628 app = insert(:oauth_app)
629 redirect_uri = OAuthController.default_redirect_uri(app)
633 |> post("/oauth/authorize", %{
634 "authorization" => %{
635 "name" => user.nickname,
636 "password" => "test",
637 "client_id" => app.client_id,
638 "redirect_uri" => redirect_uri,
639 "state" => "statepassed",
643 |> html_response(:unauthorized)
646 assert result =~ app.client_id
647 assert result =~ redirect_uri
650 assert result =~ "This action is outside the authorized scopes"
653 test "returns 401 for scopes beyond app scopes hierarchy", %{conn: conn} do
655 app = insert(:oauth_app, scopes: ["read", "write"])
656 redirect_uri = OAuthController.default_redirect_uri(app)
660 |> post("/oauth/authorize", %{
661 "authorization" => %{
662 "name" => user.nickname,
663 "password" => "test",
664 "client_id" => app.client_id,
665 "redirect_uri" => redirect_uri,
666 "state" => "statepassed",
667 "scope" => "read write follow"
670 |> html_response(:unauthorized)
673 assert result =~ app.client_id
674 assert result =~ redirect_uri
677 assert result =~ "This action is outside the authorized scopes"
681 describe "POST /oauth/token" do
682 test "issues a token for an all-body request" do
684 app = insert(:oauth_app, scopes: ["read", "write"])
686 {:ok, auth} = Authorization.create_authorization(app, user, ["write"])
690 |> post("/oauth/token", %{
691 "grant_type" => "authorization_code",
692 "code" => auth.token,
693 "redirect_uri" => OAuthController.default_redirect_uri(app),
694 "client_id" => app.client_id,
695 "client_secret" => app.client_secret
698 assert %{"access_token" => token, "me" => ap_id} = json_response(conn, 200)
700 token = Repo.get_by(Token, token: token)
702 assert token.scopes == auth.scopes
703 assert user.ap_id == ap_id
706 test "issues a token for `password` grant_type with valid credentials, with full permissions by default" do
707 password = "testpassword"
708 user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
710 app = insert(:oauth_app, scopes: ["read", "write"])
712 # Note: "scope" param is intentionally omitted
715 |> post("/oauth/token", %{
716 "grant_type" => "password",
717 "username" => user.nickname,
718 "password" => password,
719 "client_id" => app.client_id,
720 "client_secret" => app.client_secret
723 assert %{"access_token" => token} = json_response(conn, 200)
725 token = Repo.get_by(Token, token: token)
727 assert token.scopes == app.scopes
730 test "issues a token for request with HTTP basic auth client credentials" do
732 app = insert(:oauth_app, scopes: ["scope1", "scope2", "scope3"])
734 {:ok, auth} = Authorization.create_authorization(app, user, ["scope1", "scope2"])
735 assert auth.scopes == ["scope1", "scope2"]
738 (URI.encode_www_form(app.client_id) <> ":" <> URI.encode_www_form(app.client_secret))
743 |> put_req_header("authorization", "Basic " <> app_encoded)
744 |> post("/oauth/token", %{
745 "grant_type" => "authorization_code",
746 "code" => auth.token,
747 "redirect_uri" => OAuthController.default_redirect_uri(app)
750 assert %{"access_token" => token, "scope" => scope} = json_response(conn, 200)
752 assert scope == "scope1 scope2"
754 token = Repo.get_by(Token, token: token)
756 assert token.scopes == ["scope1", "scope2"]
759 test "issue a token for client_credentials grant type" do
760 app = insert(:oauth_app, scopes: ["read", "write"])
764 |> post("/oauth/token", %{
765 "grant_type" => "client_credentials",
766 "client_id" => app.client_id,
767 "client_secret" => app.client_secret
770 assert %{"access_token" => token, "refresh_token" => refresh, "scope" => scope} =
771 json_response(conn, 200)
774 token_from_db = Repo.get_by(Token, token: token)
777 assert scope == "read write"
780 test "rejects token exchange with invalid client credentials" do
782 app = insert(:oauth_app)
784 {:ok, auth} = Authorization.create_authorization(app, user)
788 |> put_req_header("authorization", "Basic JTIxOiVGMCU5RiVBNCVCNwo=")
789 |> post("/oauth/token", %{
790 "grant_type" => "authorization_code",
791 "code" => auth.token,
792 "redirect_uri" => OAuthController.default_redirect_uri(app)
795 assert resp = json_response(conn, 400)
796 assert %{"error" => _} = resp
797 refute Map.has_key?(resp, "access_token")
800 test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do
801 Pleroma.Config.put([:instance, :account_activation_required], true)
802 password = "testpassword"
805 insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
806 |> User.confirmation_changeset(need_confirmation: true)
807 |> User.update_and_set_cache()
809 refute Pleroma.User.auth_active?(user)
811 app = insert(:oauth_app)
815 |> post("/oauth/token", %{
816 "grant_type" => "password",
817 "username" => user.nickname,
818 "password" => password,
819 "client_id" => app.client_id,
820 "client_secret" => app.client_secret
823 assert resp = json_response(conn, 403)
824 assert %{"error" => _} = resp
825 refute Map.has_key?(resp, "access_token")
828 test "rejects token exchange for valid credentials belonging to deactivated user" do
829 password = "testpassword"
833 password_hash: Comeonin.Pbkdf2.hashpwsalt(password),
837 app = insert(:oauth_app)
841 |> post("/oauth/token", %{
842 "grant_type" => "password",
843 "username" => user.nickname,
844 "password" => password,
845 "client_id" => app.client_id,
846 "client_secret" => app.client_secret
849 assert resp = json_response(conn, 403)
850 assert %{"error" => _} = resp
851 refute Map.has_key?(resp, "access_token")
854 test "rejects token exchange for user with password_reset_pending set to true" do
855 password = "testpassword"
859 password_hash: Comeonin.Pbkdf2.hashpwsalt(password),
860 password_reset_pending: true
863 app = insert(:oauth_app, scopes: ["read", "write"])
867 |> post("/oauth/token", %{
868 "grant_type" => "password",
869 "username" => user.nickname,
870 "password" => password,
871 "client_id" => app.client_id,
872 "client_secret" => app.client_secret
875 assert resp = json_response(conn, 403)
877 assert resp["error"] == "Password reset is required"
878 assert resp["identifier"] == "password_reset_required"
879 refute Map.has_key?(resp, "access_token")
882 test "rejects an invalid authorization code" do
883 app = insert(:oauth_app)
887 |> post("/oauth/token", %{
888 "grant_type" => "authorization_code",
889 "code" => "Imobviouslyinvalid",
890 "redirect_uri" => OAuthController.default_redirect_uri(app),
891 "client_id" => app.client_id,
892 "client_secret" => app.client_secret
895 assert resp = json_response(conn, 400)
896 assert %{"error" => _} = json_response(conn, 400)
897 refute Map.has_key?(resp, "access_token")
901 describe "POST /oauth/token - refresh token" do
902 clear_config([:oauth2, :issue_new_refresh_token])
904 test "issues a new access token with keep fresh token" do
905 Pleroma.Config.put([:oauth2, :issue_new_refresh_token], true)
907 app = insert(:oauth_app, scopes: ["read", "write"])
909 {:ok, auth} = Authorization.create_authorization(app, user, ["write"])
910 {:ok, token} = Token.exchange_token(app, auth)
914 |> post("/oauth/token", %{
915 "grant_type" => "refresh_token",
916 "refresh_token" => token.refresh_token,
917 "client_id" => app.client_id,
918 "client_secret" => app.client_secret
920 |> json_response(200)
927 "token_type" => "Bearer",
930 "refresh_token" => _,
936 refute Repo.get_by(Token, token: token.token)
937 new_token = Repo.get_by(Token, token: response["access_token"])
938 assert new_token.refresh_token == token.refresh_token
939 assert new_token.scopes == auth.scopes
940 assert new_token.user_id == user.id
941 assert new_token.app_id == app.id
944 test "issues a new access token with new fresh token" do
945 Pleroma.Config.put([:oauth2, :issue_new_refresh_token], false)
947 app = insert(:oauth_app, scopes: ["read", "write"])
949 {:ok, auth} = Authorization.create_authorization(app, user, ["write"])
950 {:ok, token} = Token.exchange_token(app, auth)
954 |> post("/oauth/token", %{
955 "grant_type" => "refresh_token",
956 "refresh_token" => token.refresh_token,
957 "client_id" => app.client_id,
958 "client_secret" => app.client_secret
960 |> json_response(200)
967 "token_type" => "Bearer",
970 "refresh_token" => _,
976 refute Repo.get_by(Token, token: token.token)
977 new_token = Repo.get_by(Token, token: response["access_token"])
978 refute new_token.refresh_token == token.refresh_token
979 assert new_token.scopes == auth.scopes
980 assert new_token.user_id == user.id
981 assert new_token.app_id == app.id
984 test "returns 400 if we try use access token" do
986 app = insert(:oauth_app, scopes: ["read", "write"])
988 {:ok, auth} = Authorization.create_authorization(app, user, ["write"])
989 {:ok, token} = Token.exchange_token(app, auth)
993 |> post("/oauth/token", %{
994 "grant_type" => "refresh_token",
995 "refresh_token" => token.token,
996 "client_id" => app.client_id,
997 "client_secret" => app.client_secret
999 |> json_response(400)
1001 assert %{"error" => "Invalid credentials"} == response
1004 test "returns 400 if refresh_token invalid" do
1005 app = insert(:oauth_app, scopes: ["read", "write"])
1009 |> post("/oauth/token", %{
1010 "grant_type" => "refresh_token",
1011 "refresh_token" => "token.refresh_token",
1012 "client_id" => app.client_id,
1013 "client_secret" => app.client_secret
1015 |> json_response(400)
1017 assert %{"error" => "Invalid credentials"} == response
1020 test "issues a new token if token expired" do
1021 user = insert(:user)
1022 app = insert(:oauth_app, scopes: ["read", "write"])
1024 {:ok, auth} = Authorization.create_authorization(app, user, ["write"])
1025 {:ok, token} = Token.exchange_token(app, auth)
1028 Ecto.Changeset.change(
1030 %{valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), -86_400 * 30)}
1033 {:ok, access_token} = Repo.update(change)
1037 |> post("/oauth/token", %{
1038 "grant_type" => "refresh_token",
1039 "refresh_token" => access_token.refresh_token,
1040 "client_id" => app.client_id,
1041 "client_secret" => app.client_secret
1043 |> json_response(200)
1050 "token_type" => "Bearer",
1051 "expires_in" => 600,
1052 "access_token" => _,
1053 "refresh_token" => _,
1059 refute Repo.get_by(Token, token: token.token)
1060 token = Repo.get_by(Token, token: response["access_token"])
1062 assert token.scopes == auth.scopes
1063 assert token.user_id == user.id
1064 assert token.app_id == app.id
1068 describe "POST /oauth/token - bad request" do
1069 test "returns 500" do
1072 |> post("/oauth/token", %{})
1073 |> json_response(500)
1075 assert %{"error" => "Bad request"} == response
1079 describe "POST /oauth/revoke - bad request" do
1080 test "returns 500" do
1083 |> post("/oauth/revoke", %{})
1084 |> json_response(500)
1086 assert %{"error" => "Bad request"} == response