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, " <>
571 "keeping only non-admin scopes for non-admin user" do
572 app = insert(:oauth_app, scopes: ["read", "write", "admin"])
573 redirect_uri = OAuthController.default_redirect_uri(app)
575 non_admin = insert(:user, is_admin: false)
576 admin = insert(:user, is_admin: true)
578 for {user, expected_scopes} <- %{
579 non_admin => ["read:subscope", "write"],
580 admin => ["read:subscope", "write", "admin"]
584 |> post("/oauth/authorize", %{
585 "authorization" => %{
586 "name" => user.nickname,
587 "password" => "test",
588 "client_id" => app.client_id,
589 "redirect_uri" => redirect_uri,
590 "scope" => "read:subscope write admin",
591 "state" => "statepassed"
595 target = redirected_to(conn)
596 assert target =~ redirect_uri
598 query = URI.parse(target).query |> URI.query_decoder() |> Map.new()
600 assert %{"state" => "statepassed", "code" => code} = query
601 auth = Repo.get_by(Authorization, token: code)
603 assert auth.scopes == expected_scopes
607 test "returns 401 for wrong credentials", %{conn: conn} do
609 app = insert(:oauth_app)
610 redirect_uri = OAuthController.default_redirect_uri(app)
614 |> post("/oauth/authorize", %{
615 "authorization" => %{
616 "name" => user.nickname,
617 "password" => "wrong",
618 "client_id" => app.client_id,
619 "redirect_uri" => redirect_uri,
620 "state" => "statepassed",
621 "scope" => Enum.join(app.scopes, " ")
624 |> html_response(:unauthorized)
627 assert result =~ app.client_id
628 assert result =~ redirect_uri
631 assert result =~ "Invalid Username/Password"
634 test "returns 401 for missing scopes " <>
635 "(including all admin-only scopes for non-admin user)" do
636 user = insert(:user, is_admin: false)
637 app = insert(:oauth_app, scopes: ["read", "write", "admin"])
638 redirect_uri = OAuthController.default_redirect_uri(app)
640 for scope_param <- ["", "admin:read admin:write"] do
643 |> post("/oauth/authorize", %{
644 "authorization" => %{
645 "name" => user.nickname,
646 "password" => "test",
647 "client_id" => app.client_id,
648 "redirect_uri" => redirect_uri,
649 "state" => "statepassed",
650 "scope" => scope_param
653 |> html_response(:unauthorized)
656 assert result =~ app.client_id
657 assert result =~ redirect_uri
660 assert result =~ "This action is outside the authorized scopes"
664 test "returns 401 for scopes beyond app scopes hierarchy", %{conn: conn} do
666 app = insert(:oauth_app, scopes: ["read", "write"])
667 redirect_uri = OAuthController.default_redirect_uri(app)
671 |> post("/oauth/authorize", %{
672 "authorization" => %{
673 "name" => user.nickname,
674 "password" => "test",
675 "client_id" => app.client_id,
676 "redirect_uri" => redirect_uri,
677 "state" => "statepassed",
678 "scope" => "read write follow"
681 |> html_response(:unauthorized)
684 assert result =~ app.client_id
685 assert result =~ redirect_uri
688 assert result =~ "This action is outside the authorized scopes"
692 describe "POST /oauth/token" do
693 test "issues a token for an all-body request" do
695 app = insert(:oauth_app, scopes: ["read", "write"])
697 {:ok, auth} = Authorization.create_authorization(app, user, ["write"])
701 |> post("/oauth/token", %{
702 "grant_type" => "authorization_code",
703 "code" => auth.token,
704 "redirect_uri" => OAuthController.default_redirect_uri(app),
705 "client_id" => app.client_id,
706 "client_secret" => app.client_secret
709 assert %{"access_token" => token, "me" => ap_id} = json_response(conn, 200)
711 token = Repo.get_by(Token, token: token)
713 assert token.scopes == auth.scopes
714 assert user.ap_id == ap_id
717 test "issues a token for `password` grant_type with valid credentials, with full permissions by default" do
718 password = "testpassword"
719 user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
721 app = insert(:oauth_app, scopes: ["read", "write"])
723 # Note: "scope" param is intentionally omitted
726 |> post("/oauth/token", %{
727 "grant_type" => "password",
728 "username" => user.nickname,
729 "password" => password,
730 "client_id" => app.client_id,
731 "client_secret" => app.client_secret
734 assert %{"access_token" => token} = json_response(conn, 200)
736 token = Repo.get_by(Token, token: token)
738 assert token.scopes == app.scopes
741 test "issues a token for request with HTTP basic auth client credentials" do
743 app = insert(:oauth_app, scopes: ["scope1", "scope2", "scope3"])
745 {:ok, auth} = Authorization.create_authorization(app, user, ["scope1", "scope2"])
746 assert auth.scopes == ["scope1", "scope2"]
749 (URI.encode_www_form(app.client_id) <> ":" <> URI.encode_www_form(app.client_secret))
754 |> put_req_header("authorization", "Basic " <> app_encoded)
755 |> post("/oauth/token", %{
756 "grant_type" => "authorization_code",
757 "code" => auth.token,
758 "redirect_uri" => OAuthController.default_redirect_uri(app)
761 assert %{"access_token" => token, "scope" => scope} = json_response(conn, 200)
763 assert scope == "scope1 scope2"
765 token = Repo.get_by(Token, token: token)
767 assert token.scopes == ["scope1", "scope2"]
770 test "issue a token for client_credentials grant type" do
771 app = insert(:oauth_app, scopes: ["read", "write"])
775 |> post("/oauth/token", %{
776 "grant_type" => "client_credentials",
777 "client_id" => app.client_id,
778 "client_secret" => app.client_secret
781 assert %{"access_token" => token, "refresh_token" => refresh, "scope" => scope} =
782 json_response(conn, 200)
785 token_from_db = Repo.get_by(Token, token: token)
788 assert scope == "read write"
791 test "rejects token exchange with invalid client credentials" do
793 app = insert(:oauth_app)
795 {:ok, auth} = Authorization.create_authorization(app, user)
799 |> put_req_header("authorization", "Basic JTIxOiVGMCU5RiVBNCVCNwo=")
800 |> post("/oauth/token", %{
801 "grant_type" => "authorization_code",
802 "code" => auth.token,
803 "redirect_uri" => OAuthController.default_redirect_uri(app)
806 assert resp = json_response(conn, 400)
807 assert %{"error" => _} = resp
808 refute Map.has_key?(resp, "access_token")
811 test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do
812 Pleroma.Config.put([:instance, :account_activation_required], true)
813 password = "testpassword"
816 insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
817 |> User.confirmation_changeset(need_confirmation: true)
818 |> User.update_and_set_cache()
820 refute Pleroma.User.auth_active?(user)
822 app = insert(:oauth_app)
826 |> post("/oauth/token", %{
827 "grant_type" => "password",
828 "username" => user.nickname,
829 "password" => password,
830 "client_id" => app.client_id,
831 "client_secret" => app.client_secret
834 assert resp = json_response(conn, 403)
835 assert %{"error" => _} = resp
836 refute Map.has_key?(resp, "access_token")
839 test "rejects token exchange for valid credentials belonging to deactivated user" do
840 password = "testpassword"
844 password_hash: Comeonin.Pbkdf2.hashpwsalt(password),
848 app = insert(:oauth_app)
852 |> post("/oauth/token", %{
853 "grant_type" => "password",
854 "username" => user.nickname,
855 "password" => password,
856 "client_id" => app.client_id,
857 "client_secret" => app.client_secret
860 assert resp = json_response(conn, 403)
861 assert %{"error" => _} = resp
862 refute Map.has_key?(resp, "access_token")
865 test "rejects token exchange for user with password_reset_pending set to true" do
866 password = "testpassword"
870 password_hash: Comeonin.Pbkdf2.hashpwsalt(password),
871 password_reset_pending: true
874 app = insert(:oauth_app, scopes: ["read", "write"])
878 |> post("/oauth/token", %{
879 "grant_type" => "password",
880 "username" => user.nickname,
881 "password" => password,
882 "client_id" => app.client_id,
883 "client_secret" => app.client_secret
886 assert resp = json_response(conn, 403)
888 assert resp["error"] == "Password reset is required"
889 assert resp["identifier"] == "password_reset_required"
890 refute Map.has_key?(resp, "access_token")
893 test "rejects an invalid authorization code" do
894 app = insert(:oauth_app)
898 |> post("/oauth/token", %{
899 "grant_type" => "authorization_code",
900 "code" => "Imobviouslyinvalid",
901 "redirect_uri" => OAuthController.default_redirect_uri(app),
902 "client_id" => app.client_id,
903 "client_secret" => app.client_secret
906 assert resp = json_response(conn, 400)
907 assert %{"error" => _} = json_response(conn, 400)
908 refute Map.has_key?(resp, "access_token")
912 describe "POST /oauth/token - refresh token" do
913 clear_config([:oauth2, :issue_new_refresh_token])
915 test "issues a new access token with keep fresh token" do
916 Pleroma.Config.put([:oauth2, :issue_new_refresh_token], true)
918 app = insert(:oauth_app, scopes: ["read", "write"])
920 {:ok, auth} = Authorization.create_authorization(app, user, ["write"])
921 {:ok, token} = Token.exchange_token(app, auth)
925 |> post("/oauth/token", %{
926 "grant_type" => "refresh_token",
927 "refresh_token" => token.refresh_token,
928 "client_id" => app.client_id,
929 "client_secret" => app.client_secret
931 |> json_response(200)
938 "token_type" => "Bearer",
941 "refresh_token" => _,
947 refute Repo.get_by(Token, token: token.token)
948 new_token = Repo.get_by(Token, token: response["access_token"])
949 assert new_token.refresh_token == token.refresh_token
950 assert new_token.scopes == auth.scopes
951 assert new_token.user_id == user.id
952 assert new_token.app_id == app.id
955 test "issues a new access token with new fresh token" do
956 Pleroma.Config.put([:oauth2, :issue_new_refresh_token], false)
958 app = insert(:oauth_app, scopes: ["read", "write"])
960 {:ok, auth} = Authorization.create_authorization(app, user, ["write"])
961 {:ok, token} = Token.exchange_token(app, auth)
965 |> post("/oauth/token", %{
966 "grant_type" => "refresh_token",
967 "refresh_token" => token.refresh_token,
968 "client_id" => app.client_id,
969 "client_secret" => app.client_secret
971 |> json_response(200)
978 "token_type" => "Bearer",
981 "refresh_token" => _,
987 refute Repo.get_by(Token, token: token.token)
988 new_token = Repo.get_by(Token, token: response["access_token"])
989 refute new_token.refresh_token == token.refresh_token
990 assert new_token.scopes == auth.scopes
991 assert new_token.user_id == user.id
992 assert new_token.app_id == app.id
995 test "returns 400 if we try use access token" do
997 app = insert(:oauth_app, scopes: ["read", "write"])
999 {:ok, auth} = Authorization.create_authorization(app, user, ["write"])
1000 {:ok, token} = Token.exchange_token(app, auth)
1004 |> post("/oauth/token", %{
1005 "grant_type" => "refresh_token",
1006 "refresh_token" => token.token,
1007 "client_id" => app.client_id,
1008 "client_secret" => app.client_secret
1010 |> json_response(400)
1012 assert %{"error" => "Invalid credentials"} == response
1015 test "returns 400 if refresh_token invalid" do
1016 app = insert(:oauth_app, scopes: ["read", "write"])
1020 |> post("/oauth/token", %{
1021 "grant_type" => "refresh_token",
1022 "refresh_token" => "token.refresh_token",
1023 "client_id" => app.client_id,
1024 "client_secret" => app.client_secret
1026 |> json_response(400)
1028 assert %{"error" => "Invalid credentials"} == response
1031 test "issues a new token if token expired" do
1032 user = insert(:user)
1033 app = insert(:oauth_app, scopes: ["read", "write"])
1035 {:ok, auth} = Authorization.create_authorization(app, user, ["write"])
1036 {:ok, token} = Token.exchange_token(app, auth)
1039 Ecto.Changeset.change(
1041 %{valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), -86_400 * 30)}
1044 {:ok, access_token} = Repo.update(change)
1048 |> post("/oauth/token", %{
1049 "grant_type" => "refresh_token",
1050 "refresh_token" => access_token.refresh_token,
1051 "client_id" => app.client_id,
1052 "client_secret" => app.client_secret
1054 |> json_response(200)
1061 "token_type" => "Bearer",
1062 "expires_in" => 600,
1063 "access_token" => _,
1064 "refresh_token" => _,
1070 refute Repo.get_by(Token, token: token.token)
1071 token = Repo.get_by(Token, token: response["access_token"])
1073 assert token.scopes == auth.scopes
1074 assert token.user_id == user.id
1075 assert token.app_id == app.id
1079 describe "POST /oauth/token - bad request" do
1080 test "returns 500" do
1083 |> post("/oauth/token", %{})
1084 |> json_response(500)
1086 assert %{"error" => "Bad request"} == response
1090 describe "POST /oauth/revoke - bad request" do
1091 test "returns 500" do
1094 |> post("/oauth/revoke", %{})
1095 |> json_response(500)
1097 assert %{"error" => "Bad request"} == response