|
16 | 16 | AUTH_SERVER_PORT = 12400 |
17 | 17 |
|
18 | 18 |
|
19 | | -def _perform_saml_authentication(opts, owner, enable_token_creation=False): |
| 19 | +def _perform_saml_authentication(opts, owner, enable_token_creation=False, json=False): |
20 | 20 | """Perform SAML authentication via web browser and local web server.""" |
21 | 21 | session = create_configured_session(opts) |
22 | 22 | api_host = opts.api_config.host |
23 | 23 |
|
24 | 24 | idp_url = get_idp_url(api_host, owner, session=session) |
25 | | - click.echo( |
26 | | - f"Opening your organization's SAML IDP URL in your browser: {click.style(idp_url, bold=True)}" |
27 | | - ) |
| 25 | + if not json: |
| 26 | + click.echo( |
| 27 | + f"Opening your organization's SAML IDP URL in your browser: {click.style(idp_url, bold=True)}" |
| 28 | + ) |
28 | 29 | click.echo() |
29 | 30 | webbrowser.open(idp_url) |
30 | | - click.echo("Starting webserver to begin authentication ... ") |
| 31 | + if not json: |
| 32 | + click.echo("Starting webserver to begin authentication ... ") |
31 | 33 |
|
32 | 34 | auth_server = AuthenticationWebServer( |
33 | 35 | (AUTH_SERVER_HOST, AUTH_SERVER_PORT), |
@@ -86,13 +88,16 @@ def authenticate(ctx, opts, owner, token, force, save_config, json): |
86 | 88 | """Authenticate to Cloudsmith using the org's SAML setup.""" |
87 | 89 | owner = owner[0].strip("'[]'") |
88 | 90 |
|
89 | | - click.echo( |
90 | | - f"Beginning authentication for the {click.style(owner, bold=True)} org ... " |
91 | | - ) |
| 91 | + if not json: |
| 92 | + click.echo( |
| 93 | + f"Beginning authentication for the {click.style(owner, bold=True)} org ... " |
| 94 | + ) |
92 | 95 |
|
93 | 96 | context_message = "Failed to authenticate via SSO!" |
94 | 97 | with handle_api_exceptions(ctx, opts=opts, context_msg=context_message): |
95 | | - _perform_saml_authentication(opts, owner, enable_token_creation=token) |
| 98 | + _perform_saml_authentication( |
| 99 | + opts, owner, enable_token_creation=token, json=json |
| 100 | + ) |
96 | 101 |
|
97 | 102 | if token: |
98 | 103 | ctx.invoke(create, opts=opts, save_config=save_config, force=force, json=json) |
0 commit comments