Skip to content

Authorization Headers are not supported #701

Open

Description

@bennycode

I am trying to use api to make request to Alpaca. The Readme.io demo page shows me that I can add Authorization Headers for the API Key & API Secret. When I follow the example, my code crashes with the following message:

Error: Sorry, this operation currently requires multiple forms of authentication which this library doesn't yet support.

Here is the example:

import api from 'api';
const sdk = api('@testalpacadocs/v1#zryj16ll4d1dl0');

sdk.auth(process.env.API_KEY);
sdk.auth(process.env.API_SECRET);

await sdk.postOrder({side: 'buy', type: 'market', time_in_force: 'day'});

Screenshot

image

Activity

  1. erunion commented on Aug 21, 2023

    @erunion
    Member

    So yeah api does support authorization headers, but it doesn't support API endpoints that have multiple forms of auth because sdk.auth() has no way of knowing which security scheme, and authorization header, to apply that value to.

    We've had some ideas on how to improve this, like adding a second argument to sdk.auth('API-KEY', 'x-api-key') to let you specify the header to attach it to but that conflicts with sdk.auth's handling of basic auth.

    Will leave this open for discussion.

  2. added
    help wanted
    on Aug 21, 2023
  3. bennycode commented on Aug 21, 2023

    @bennycode
    ContributorAuthor

    Getting this integrated would be a big enabler. Is there any workaround for me as a developer to set headers on the SDK? Can I access some internal variables or apply an interceptor to add the necessary header information?

  4. erunion commented on Aug 21, 2023

    @erunion
    Member

    There's unfortunately no workarounds at the moment.

  5. konhi commented on Jan 26, 2024

    @konhi

    I use API that requires 2 secrets, so it's really a blocker in using this lib. At least workaround would be great 🙏

  6. fl0wo commented on Apr 16, 2025

    @fl0wo

    Wow that's like the first thing I'd do when implementing such tool :)

    @erunion is there anything we can do to help? Or is there a reason why it HAS to be like this?

  7. bombillazo commented on Aug 15, 2025

    @bombillazo

    Hey, any futher discussion on this topic? Having some way to customize the auth would be super beneficial for more complex APIs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions