Search code examples
mavenauthorizationsettings

How to use Bearer Authorization Token in Maven settings.xml


Currently application using username and password (encrypted) to download Maven artifacts through JFrog Artifactory.

How can we specify we want to connect using a HTTP Header"Authorization: Bearer <identityToken>" insead of the username and password in the settings.xml file?

I have tried using the xml tag token like below

<token>${identityToken}</token>

But that did not work.


Solution

  • This works for me in ~/.m2/settings.xml. The documentation for maven-resolver-transport-http is here. You can create a JWT access token from your Artifactory user profile, or as an admin here.

    <server>
      <id>my-server</id>
      <configuration>
        <httpHeaders>
          <property>
            <name>Authorization</name>
            <value>Bearer ${env.JFROG_TOKEN}</value>
          </property>
        </httpHeaders>
      </configuration>
    </server>