'Authenticate against AWS codeartifact using token

I have a Kotlin class, its task is to push a jar file to codeartifact, i do get a token successfully but i keep on getting a 401 back from codeartifact service, i am reading the following doc[1]
The documentation does not show examples other than curl and maven plugin, which is not what i use, so i am trying to mimic this behavior with a javax.ws.rs.client.HttpClient:

        val authTokenReq = GetAuthorizationTokenRequest.builder()
          .domain(domainName)
          .domainOwner(domainOwner)
            .durationSeconds(1000)
             .build()
             val token = CodeartifactClient.create().getAuthorizationToken(authTokenReq).authorizationToken()
    
val authString = "aws:$token"
    val encodedAuth = Base64.getEncoder().encode(authString.toByteArray(Charsets.UTF_8))
    val upload = client.target(to)
      .request()
      .header("X-Checksum-Sha1", sha1)
      .header("Authorization", "Basic " + encodedAuth.toString(Charsets.UTF_8))
      .put(Entity.entity(packageVersionAssetAsBytes.asInputStream(), "application/java-archive"))

Unfortunatelly i get:

"exception":"java.lang.RuntimeException: Upload failed, status=401 

Does anyone has a tip about how i should properly use codeartifact token? [1]: https://docs.aws.amazon.com/codeartifact/latest/ug/maven-curl.html



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source