Search code examples
artifactoryjfrog-cli

How do I base64 encode a password for JFrog Artifactory?


I'm writing a script to configure .npmrc file with JFrog Artifactory credentials. Artifactory/NPM requires the configured password to be base64 encoded, i.e. (with the password "test"):

//mycompany.jfrog.io/mycompany/api/npm/npm-repo/:_password=dGVzdAo=

However, a base64 encoded string does not match what Artifactory provides for the password in the Set Me Up dialog. In fact, base64 decoding the string that Artifactory provides in this dialog yields a different string that is not the account's password. How is the password string provided by Artifactory generated?


Solution

  • You can use the Artifactory npm auth REST API to retrieve the setting for the .npmrc.
    For example:

    $ curl -uadmin:<CREDENTIAL> http://<ARTIFACTORY_SERVER_DOMAIN>:8081/artifactory/api/npm/auth
    

    Will return the following response

    _auth = YWRtaW46e0RFU2VkZX1uOFRaaXh1Y0t3bHN4c2RCTVIwNjF3PT0=
    email = myemail@email.com
    always-auth = true
    

    For more info see the npm repositories documentation.