diff --git a/nylas/client/client.py b/nylas/client/client.py index 9bc2f458..6f7ab174 100644 --- a/nylas/client/client.py +++ b/nylas/client/client.py @@ -152,6 +152,8 @@ def authentication_url( login_hint="", state="", scopes=("email", "calendar", "contacts"), + provider="", + redirect_on_error=None, ): args = { "redirect_uri": redirect_uri, @@ -165,6 +167,16 @@ def authentication_url( if isinstance(scopes, str): scopes = [scopes] args["scopes"] = ",".join(scopes) + if provider and provider in [ + "icloud", + "gmail", + "office365", + "exchange", + "imap", + ]: + args["provider"] = provider + if redirect_on_error is not None and isinstance(redirect_on_error, bool): + args["redirect_on_error"] = "true" if redirect_on_error is True else "false" url = URLObject(self.authorize_url).add_query_params(args.items()) return str(url) diff --git a/tests/test_client.py b/tests/test_client.py index 9d3ba21c..1eb6f4b8 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -143,6 +143,62 @@ def test_client_authentication_url_scopes_none(api_client, api_url): assert urls_equal(expected, actual) +def test_client_authentication_url_optional_params(api_client, api_url): + expected = ( + URLObject(api_url) + .with_path("/oauth/authorize") + .set_query_params( + [ + ("login_hint", ""), + ("state", ""), + ("redirect_uri", "/redirect"), + ("response_type", "code"), + ("client_id", "None"), + ("scopes", "email"), + ("provider", "gmail"), + ("redirect_on_error", "false"), + ] + ) + ) + actual = URLObject( + api_client.authentication_url( + "/redirect", scopes="email", provider="gmail", redirect_on_error=False + ) + ) + assert urls_equal(expected, actual) + + +def test_client_authentication_url_invalid_param_values(api_client, api_url): + expected = ( + URLObject(api_url) + .with_path("/oauth/authorize") + .set_query_params( + [ + ("login_hint", ""), + ("state", ""), + ("redirect_uri", "/redirect"), + ("response_type", "code"), + ("client_id", "None"), + ("scopes", "email"), + ] + ) + ) + actual = URLObject( + api_client.authentication_url("/redirect", scopes="email", provider="Google") + ) + assert urls_equal(expected, actual) + + expected2 = expected.set_query_param("provider", "gmail") + + actual2 = URLObject( + api_client.authentication_url( + "/redirect", scopes="email", provider="gmail", redirect_on_error="true" + ) + ) + + assert urls_equal(expected2, actual2) + + def test_client_token_for_code(mocked_responses, api_client, api_url): endpoint = re.compile(api_url + "/oauth/token") response_body = json.dumps({"access_token": "hooray"})