zowe / zowe-cli

Zowe CLI
Eclipse Public License 2.0
108 stars 85 forks source link

`zowe auth login apiml` creates additional base profiles #1650

Open zFernand0 opened 1 year ago

zFernand0 commented 1 year ago

Originally posted by @plavjanik in https://github.com/zowe/zowe-cli/issues/1341

When I want to get a new token using zowe auth login apiml, it does not work well for me:

$ zowe auth login apiml                                                                                                                                                                                                                                                                                         
Enter the user name for your service (will be hidden): 
Enter the password for your service (will be hidden): 
Do you want to store the host, port, and token on disk for use with future commands? If you answer Yes, the credentials will be saved to a base profile named 'base_apiml_apiml'. If you answer No, the token will be printed to the terminal and will not be stored on disk. [y/N]:

Login successful. The authentication token is stored in the 'base_apiml_apiml' base profile for future use. To revoke this token and remove it from your profile, review the 'zowe auth logout' command.

This creates a new base profile:

        "base_apiml": {
            "type": "base",
            "properties": {
                "host": "sys32.lvn.broadcom.net",
                "port": 60004,
                "tokenType": "apimlAuthenticationToken"
            },
            "secure": [
                "tokenValue"
            ]
        },
        "base_apiml_apiml": {
            "type": "base",
            "properties": {
                "host": "sys32.lvn.broadcom.net",
                "port": 60004,
                "tokenType": "apimlAuthenticationToken"
            },
            "secure": [
                "tokenValue"
            ]
        }
    },
    "defaults": {
        "zosmf": "zosmf",
        "tso": "tso",
        "ssh": "ssh",
        "base": "base_apiml_apiml"
    },

There are two base profiles, I just wanted to refresh my token for the existing profile. How do I do that? The command fails too:

+ zowe zos-files create data-set-classic USERID.TESTBASH.DATASET1
Command Error:
This operation requires authentication.

z/OSMF REST API Error:
Rest API failure with HTTP(S) status 401

Host:      sys32.lvn.broadcom.net
Port:      1443
Base Path: 
Resource:  /zosmf/restfiles/ds/USERID.TESTBASH.DATASET1
Request:   POST
Headers:   [{"Accept-Encoding":"gzip"},{"X-CSRF-ZOSMF-HEADER":true}]
Payload:   POST

Error Details:
Token is not valid or expired.

For CLI usage, see `zowe auth login apiml --help`
github-actions[bot] commented 1 year ago

Thank you for creating a bug report. We will investigate the bug and evaluate its impact on the product. If you haven't already, please ensure you have provided steps to reproduce the bug and as much context as possible.

zFernand0 commented 11 months ago

Hey @plavjanik, After some investigation, the way in which you could refresh the token is by answering no to that prompt, and copying the token value to a config set command like this: zowe config set profiles.base_apiml.properties.tokenValue <tokenValue> --secure (note: you may need the --global-config flag)

As part of the fixes included in the PR below, you should be able to run zowe config secure. (note: you may need the --global-config flag) You will then be prompted for user and password on each base profile (if you have multiple in your config file) and store the token automatically (if autoStore: true).


Question: Would you expect that subsequent zowe auth login apiml operations will behave the same way as zowe config secure and just refresh your token (without creating a new base profile?