MunifTanjim / node-bitbucket

Bitbucket API client for Browser and Node.js
https://bitbucketjs.netlify.app
MIT License
105 stars 31 forks source link

Token Authorization doesn't seem to be working #135

Open sh-ghanique opened 11 months ago

sh-ghanique commented 11 months ago

What am I doing wrong here?

Consider the following code:

import { Bitbucket } from "bitbucket";

const apiToken = 'Token as copied from https://id.atlassian.com/manage/api-tokens';
const bitbucket = new Bitbucket({
  baseUrl: 'https://api.bitbucket.org/2.0',
  auth: {
    token: apiToken,
  }
});

const repos = bitbucket.user.get({}).then(value => {
  console.log(value.data);
});

Steps to reproduce

  1. Go to https://id.atlassian.com/manage/api-tokens
  2. Create a new API token.
  3. Copy the API token
  4. In the code above replace "Token as copied from https://id.atlassian.com/manage/api-tokens'" with the API token.
  5. Run the code.

Expected

The current user is being logged.

Actual

BITBUCKET CLOUD API LATEST UPDATES:  https://developer.atlassian.com/cloud/bitbucket 
index.ts:11
Process exited with code 1
Uncaught i HTTPError: Unauthorized
    at <anonymous> (/wrk/bitbucket/node_modules/bitbucket/src/request/fetch-wrapper.ts:48:17)
    at processTicksAndRejections (internal/process/task_queues:95:5)
MunifTanjim commented 11 months ago

Is that token for bitbucket or token for atlassian? Can you make api call without this library with that token?

Brianzchen commented 10 months ago

Same issue, having dug around and reading posts such as https://stackoverflow.com/questions/68597002/why-is-personal-access-token-not-working-for-bitbucket-rest-api it seems that bitbucket expects you to have both a token with a username. So I got it working by passing username and password=token