@@ -851,6 +851,36 @@ def test_refresh_invalidates_old_tokens(self):
851851 self .assertIsNotNone (refresh_token .revoked )
852852 self .assertFalse (AccessToken .objects .filter (token = at ).exists ())
853853
854+ def test_refresh_twice_with_same_token_returns_401 (self ):
855+ """
856+ Ensure that using a refresh token twice returns 401
857+ """
858+ self .client .login (username = "test_user" , password = "123456" )
859+ authorization_code = self .get_auth ()
860+
861+ token_request_data = {
862+ "grant_type" : "authorization_code" ,
863+ "code" : authorization_code ,
864+ "redirect_uri" : "http://example.org" ,
865+ }
866+ auth_headers = get_basic_auth_header (self .application .client_id , CLEARTEXT_SECRET )
867+
868+ response = self .client .post (reverse ("oauth2_provider:token" ), data = token_request_data , ** auth_headers )
869+ content = json .loads (response .content .decode ("utf-8" ))
870+
871+ rt = content ["refresh_token" ]
872+
873+ token_request_data = {
874+ "grant_type" : "refresh_token" ,
875+ "refresh_token" : rt ,
876+ "scope" : content ["scope" ],
877+ }
878+ response = self .client .post (reverse ("oauth2_provider:token" ), data = token_request_data , ** auth_headers )
879+ self .assertEqual (response .status_code , 200 )
880+
881+ response = self .client .post (reverse ("oauth2_provider:token" ), data = token_request_data , ** auth_headers )
882+ self .assertEqual (response .status_code , 400 )
883+
854884 def test_refresh_no_scopes (self ):
855885 """
856886 Request an access token using a refresh token without passing any scope
0 commit comments