Skip to content

Documentation not clear about usage of sdk.authorize() method #53

@joepio

Description

@joepio

I'm trying to set up an app using the SDK, but I can't get my client to authorise.

Here's the relevant part of the docs that I fail to understand:

Screenshot 2021-03-29 at 20 53 26

My question boils down to this: what do I put in the code argument?

This is my code:

 const sdk = new SDK({
      baseUrl: 'http://api-sandbox.uphold.com',
      clientId: this.configService.get<string>('UPHOLD_CLIENT_ID'),
      clientSecret: this.configService.get<string>('UPHOLD_CLIENT_SECRET'),
    });
    this.sdk = sdk;

    sdk
      // What do I insert here?
      .authorize('code')
      .then(() => sdk.getMe())
      .then((user) => {
        console.log('sdk', user);
      });

And the error that I get:


Unhandled rejection UnauthorizedError: unauthorized
    at createError (/Users/joep/dev/src/gitlab.com/ontola/cash-link/node_modules/@uphold/uphold-sdk-javascript/dist/core/utils/error-factory.js:20:14)
    at /Users/joep/dev/src/gitlab.com/ontola/cash-link/node_modules/@uphold/uphold-sdk-javascript/dist/node/services/request-client.js:31:167
    at tryCatcher (/Users/joep/dev/src/gitlab.com/ontola/cash-link/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/joep/dev/src/gitlab.com/ontola/cash-link/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/Users/joep/dev/src/gitlab.com/ontola/cash-link/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/Users/joep/dev/src/gitlab.com/ontola/cash-link/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/Users/joep/dev/src/gitlab.com/ontola/cash-link/node_modules/bluebird/js/release/promise.js:725:18)
    at _drainQueueStep (/Users/joep/dev/src/gitlab.com/ontola/cash-link/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/Users/joep/dev/src/gitlab.com/ontola/cash-link/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/Users/joep/dev/src/gitlab.com/ontola/cash-link/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues (/Users/joep/dev/src/gitlab.com/ontola/cash-link/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (node:internal/timers:463:21)

Suggestions

Maybe I'm just missing something trivial, or this step is actually very simple and I'm just lacking some basic knowledge, but otherwise:

  • Return a more useful error then Unhandled rejection UnauthorizedError: unauthorized
  • Change the example in the docs and the description field for the code parameter which currently says Authorization code

Versions

Node v15.3.0, SDK 2.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions