dataverse-client-javascript icon indicating copy to clipboard operation
dataverse-client-javascript copied to clipboard

feat: add config setting "bearerTokenGetFunction"

Open vera opened this issue 1 month ago • 0 comments

What this PR does / why we need it:

This PR adds a config setting bearerTokenGetFunction to define a custom function to retrieve the bearer token. This is more flexible than the current bearerTokenLocalStorageKey setting.

Which issue(s) this PR closes:

  • Closes #396

Related Dataverse PRs:

/

Special notes for your reviewer:

/

Suggestions on how to test this:

I've tested this by initializing with the following config:

ApiConfig.init(
  "http://localhost:8080/api",
  DataverseApiAuthMechanism.BEARER_TOKEN,
  undefined,
  undefined,
  () => {
    const value = localStorage.getItem("oidc.default");
    if (value) {
      const token = JSON.parse(value).tokens?.accessToken;
      return token || null;
    } else {
      return null;
    }
  }
);

and confirmed that bearer-token-authenticated requests are correctly sent.

Is there a release notes or changelog update needed for this change?:

Yes, that would be good.

Additional documentation:

/

vera avatar Nov 04 '25 09:11 vera