"401 Content access is protected by token" authentication failure while performing maven release

I am getting a “401 Content access is protected by token” authentication failure while performing maven release. But I did not make any changes regarding Sonatype/Nexus.

[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.8:deploy (injected-nexus-deploy) on project manifold-all: Remote staging failed: Failed to deploy artifacts: Could not transfer artifact systems.manifold:manifold-tuple-rt:jar.asc:javadoc:2024.1.19 from/to ossrh (https://oss.sonatype.org:443/service/local/staging/deployByRepositoryId/systemsmanifold-1279): authentication failed for https://oss.sonatype.org:443/service/local/staging/deployByRepositoryId/systemsmanifold-1279/systems/manifold/manifold-tuple-rt/2024.1.19/manifold-tuple-rt-2024.1.19-javadoc.jar.asc, status: 401 Content access is protected by token

This is my own FOSS repo and I’m not doing anything special. I released the prior version a few days ago with no problems. And reading this it appears this “protected by token” feature can only be set in Sonatype Nexus Repository software, which I do not have or use.

Not sure how this could happen without my making changes via Sonatype/Nexus. Any ideas?
Sonatype won’t help me because I’m not a paying customer. Thanks.

2 Likes

I’m having the exact same issue. FOSS project that can no longer be published with our existing credentials, and no way to configure User Tokens

We’ve recently made necessary changes to our account management system that involves requiring a user token to publish. Although we attempted to reach out to all of our publishers before this change, we realize that the communication might not have reached you. Please follow the instructions on publishing via a user token in order to resolve this issue.

Please keep in mind that the user tokens generated in Central Portal cannot be used in OSSRH. Additionally, if you need to reset your OSSRH password, please follow these instructions to manage your credentials.

1 Like

I ran into this as well. The instructions from @mben-soula worked for me –

  1. Go to https://s01.oss.sonatype.org/
  2. Go to profile
  3. Change the pulldown from “Summary” to “User Token”
  4. Click on “Access User Token”

I am using Gradle in my project, so I have all my credentials stored in a private gradle.properties file. Using the username and password values from the “Access User Token” popup, I created two new entries:

ossrhToken=...
ossrhTokenPassword=...

And finally, I updated my Gradle build script, shoud look something like this:

maven {
    credentials {
        username = findProperty("ossrhToken") as String
        password = findProperty("ossrhTokenPassword") as String
    }
}
4 Likes

Same here. Thanks for the question @rmckinley

I have an existing project that publishes to oss.sonatype.org. I’ve accessed my token, stored it in my private gradle.properties, and replaced my old username / password configuration with:

    maven {
      name = "nexus"
      url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
      credentials {
        username = findProperty("ossrhToken") as String
        password = findProperty("ossrhTokenPassword") as String
      }
    }

but I still get Received status code 401 from server: Content access is protected by token. I don’t understand what I’m missing.

Do I need to start publishing via s01.oss.sonatype.org? I don’t have account credentials there and my understanding was existing projects keep using the original server.

3 Likes

I’m experiencing the same problem. The token has been created, the settings.xml file has been updated, but I’m getting “401 - Unauthorized” reply from the server. What’s my next step?

can you tell me more info about where to insert these code in gradle file ?

My Android studio Project implementation ‘com.vanniktech.maven.publish.base:com.vanniktech.maven.publish.base.gradle.plugin:0.25.3’

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.

  • Where:
    Build file ‘/Users/zlb/code/FaceVerification/FaceVerifyLib/build.gradle’ line: 13

Mmm I am having the same problem. But the artifacts are in the staging repository.

I was able to fix it by creating a user token :slight_smile:

@zenglb

You can see my relevant Sonatype publishing code here. I hope that helps.

Misc. information about the Gradle maven publishing plugin here and also here.

Got the same issue, and creating a user token got me to the same situation as for @yegor256 (Hi Egor, I’ve read your book once!) - getting 401 - Unauthorized. For some reason recreating a user token for the second time fixed the issue for me.

1 Like

I solved this problem by making sure my token is created at oss.sonatype.org and I deploy to the same server (mentioning it in settings.xml). Apparently, there are many servers and you can create tokens at each one of them. Apparently, the tokens won’t work on other servers.

Can every one guide me the username and passwod to access nexus repository manager because I use the same username and password in maven central repository but it not match.
https://oss.sonatype.org/

Can’t make this work.

I can log in to https://oss.sonatype.org/

But when I select the profile I get an error message and the profiles comes up empty.

When I try to access the token a username/password dialog pops up and when I click on “Confirm” I get a new Error dialog saying “Username mismatch”

I figured this may have something to do with the empty profile, but when I try to change anything in the profile I get 403 Forbidden.

I have tried https://s01.oss.sonatype.org/ as well, but there I can’t log in.

We had same “401 content access is protected by token”. First did not work after generating user token. We tried “Reset User Token” button (under the “Access User Token” button), and generating a new one via “Access User Token” button. Plus we pressed explicit “Close” button after generating in the popup containing the credentials (instead of letting it automatic close after 1 minute). After this we could upload artifacts again with these new user token credentials, so seems either the “reset” or the “explicit close” fixed it. Maybe this helps others.

+1 had the same issue. Resetting the token value fixed it. Token worked for several releases of our library (most recently June 21), but then failed with the next release on July 3. Reset the token values July 5 and retried the release and it succeeded :woman_shrugging:

Also hit by this issue. I cannot get this to work for https://s01.oss.sonatype.org/, I have done the UserToken reset dance multiple times now to no avail.

Here is how I am passing it into my gradle setup, via Github Actions ENV variables.

publishing {
    repositories {
        maven {
            name = "OSSRH"
            url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2")
            credentials {
                username = System.getenv("OSSRH_USER_TOKEN_USERNAME")
                password = System.getenv("OSSRH_USER_TOKEN_PASSWORD")
            }
        }
    }

Just tried one last time and it worked with a new set of credentials. I must’ve cycled through about 5 sets before it worked

I also encountered this problem. I tried generate user token multiple times and configed it properly, but keep getting 401. I finally make it work by upgrade my maven version to 3.9.8, maybe it also suits your situation.