question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Per-request auth / headers / request options

See original GitHub issue

Describe the solution you’d like In server side rendering environments it is common that a single process may need to make requests on behalf of several users, each with their own set of credentials. It seems like this is doable with something like:

import { MyService, OpenAPI } from 'MyService'

OpenAPI.TOKEN = () => { OpenAPI.TOKEN = undefined; return 'abc123' }
MyService.someOperation({})

The issue is that the TOKEN needs to be set before each call in a bit of a clunky way, and if there the is anything async that happens between setting it and the request actually being sent off it’s possible for one request to incorrectly be made with credentials intended for another. Ideally I’d like to be able to pass credentials as a final argument any operation (this works better with the “useOptions” style). I’d also be OK with passing some kind of extension of ApiRequestOptions so that resolvers could work on a per-req basis, e.g.:

import { MyService, OpenAPI } from 'MyService'

OpenAPI.TOKEN = (opts) => opts.myCustomAuth
MyService.someOperation({}, { myCustomAuth: 'abc123' )

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
obabichevcommented, Oct 16, 2021

@Lanny I see, it makes sense

But I still think that global parameters are evil =) What I see is that two parts of the generated code might be split:

  • fixed part core
  • floating part models/services

in this case, core part might have a client which can be instantiated in order to have own token/url/etc. And models/services can accept the client as an argument and be just functions.

But the main problem I see is that these changes require a lot of effort, bring significant changes into library api and probably conflict with other functionality I don’t know about… =)

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP authentication - MDN Web Docs - Mozilla
The Authorization and Proxy-Authorization request headers contain the credentials to authenticate a user agent with a (proxy) server.
Read more >
Using Axios to set request headers - LogRocket Blog
Axios is a flexible and robust HTTP client. Learn different ways Axios can be used to set request headers for API calls.
Read more >
Advanced Usage — Requests 2.28.1 documentation
This is done by providing data to the properties on a Session object: s = requests.Session() s.auth = ('user', 'pass') s.headers.update({'x-test': 'true'}) ...
Read more >
http post - how to send Authorization header? - Stack Overflow
Unfornately there is no Authorization header. How should I add it correctly? Whole request sent by my code looks as follow: OPTIONS /oauth/token ......
Read more >
HTTP/1.1: Header Field Definitions
The Accept request-header field can be used to specify certain media types which are acceptable for the response. Accept headers can be used...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found