Repository: auth0/auth0-python
Pull request #256 (2021-03-08 21:21:53)

Add scope to refresh_token
### Changes

Adding `scope` param to `refresh_token`.

### References

The auth0 API supports the `scope` param when refreshing token. https://auth0.com/docs/api/authentication#refresh-token

### Testing

- [x] This change adds unit test coverage

### Checklist

- [x] I have read the [Auth0 general contribution guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md)
- [x] I have read the [Auth0 Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md)
- [x] All existing and new tests complete without errors


criles25: the empty string default `scope=''` behaves the same as it being left out when calling the auth0 API

```
# scope=""
charlesriley@Charless-MBP auth0-python % curl --request POST \                                                                    
--url 'https://xometry-monolith-development.us.auth0.com/oauth/token' \
--header 'content-type: application/x-www-form-urlencoded' \
--data 'grant_type=refresh_token&client_id=foo&client_secret=bar&scope=""&refresh_token=baz'
{"access_token":"JWT","scope":"offline_access","expires_in":86400,"token_type":"Bearer"}%                                                                 

# scope left out 
charlesriley@Charless-MBP auth0-python % curl --request POST \                                                                    
--url 'https://xometry-monolith-development.us.auth0.com/oauth/token' \
--header 'content-type: application/x-www-form-urlencoded' \
--data 'grant_type=refresh_token&client_id=foo&client_secret=bar&refresh_token=baz' 
{"access_token":"JWT","scope":"offline_access","expires_in":86400,"token_type":"Bearer"}%                                                                 
```

Patch:
diff --git a/auth0/v3/authentication/get_token.py b/auth0/v3/authentication/get_token.py
index 2810969..dad945c 100644
--- a/auth0/v3/authentication/get_token.py
+++ b/auth0/v3/authentication/get_token.py
@@ -164,7 +164,7 @@ class GetToken(AuthenticationBase):
             }
         )
 
-    def refresh_token(self, client_id, client_secret, refresh_token, grant_type='refresh_token'):
+    def refresh_token(self, client_id, client_secret, refresh_token, grant_type='refresh_token', scope=''):
         """Calls /oauth/token endpoint with refresh token grant type
 
         Use this endpoint to refresh an access token, using the refresh token you got during authorization.
@@ -179,6 +179,9 @@ class GetToken(AuthenticationBase):
 
             refresh_token (str): The refresh token returned from the initial token request.
 
+            scope (str): String value of the different scopes the client is asking for.
+            Multiple scopes are separated with whitespace.
+
         Returns:
             access_token, id_token
         """
@@ -189,6 +192,7 @@ class GetToken(AuthenticationBase):
                 'client_id': client_id,
                 'client_secret': client_secret,
                 'refresh_token': refresh_token,
+                'scope': scope,
                 'grant_type': grant_type
             }
         )


Test patch:
diff --git a/auth0/v3/test/authentication/test_get_token.py b/auth0/v3/test/authentication/test_get_token.py
index c635022..e10c9b1 100644
--- a/auth0/v3/test/authentication/test_get_token.py
+++ b/auth0/v3/test/authentication/test_get_token.py
@@ -104,7 +104,8 @@ class TestGetToken(unittest.TestCase):
         g.refresh_token(client_id='cid',
                         client_secret='clsec',
                         refresh_token='rt',
-                        grant_type='gt')
+                        grant_type='gt',
+                        scope='s')
 
         args, kwargs = mock_post.call_args
 
@@ -113,5 +114,6 @@ class TestGetToken(unittest.TestCase):
             'client_id': 'cid',
             'client_secret': 'clsec',
             'refresh_token': 'rt',
-            'grant_type': 'gt'
-        })
\ No newline at end of file
+            'grant_type': 'gt',
+            'scope': 's'
+        })