Repository: nylas/nylas-python

Issue:
Allow users to pass `state` during authentication

Discussion:

Patch:
diff --git a/nylas/client/client.py b/nylas/client/client.py
index 8278ae5..b41f782 100644
--- a/nylas/client/client.py
+++ b/nylas/client/client.py
@@ -143,13 +143,13 @@ class APIClient(json.JSONEncoder):
             if 'Authorization' in self.session.headers:
                 del self.session.headers['Authorization']
 
-    def authentication_url(self, redirect_uri, login_hint=''):
+    def authentication_url(self, redirect_uri, login_hint='', state=''):
         args = {'redirect_uri': redirect_uri,
                 'client_id': self.app_id or 'None',  # 'None' for back-compat
                 'response_type': 'code',
                 'scope': 'email',
                 'login_hint': login_hint,
-                'state': ''}
+                'state': state}
 
         url = URLObject(self.authorize_url).add_query_params(args.items())
         return str(url)


Test patch:
diff --git a/tests/test_client.py b/tests/test_client.py
index 8a8590d..ea4831d 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -83,6 +83,12 @@ def test_client_authentication_url(api_client, api_url):
     expected2 = expected.set_query_param("login_hint", "hint")
     assert urls_equal(expected2, actual2)
 
+    actual3 = URLObject(
+        api_client.authentication_url("/redirect", state="confusion")
+    )
+    expected3 = expected.set_query_param("state", "confusion")
+    assert urls_equal(expected3, actual3)
+
 
 @responses.activate
 def test_client_token_for_code(api_client, api_url):