-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Authorization (question) #39
Comments
It depends on a logic required for token and concrete http backend. Here are some trivial examples As you need refreshable token the simpliest way is to put that logic into do_request method: class Client(RequestsClient):
def do_request(self, request: HttpRequest) -> Any:
token = get_token() # you logic
self.session.headers["Authorization"] = f"Token {token}"
super().do_request(request) From library side we can probably extend |
I think your example works, but clearly in a suboptimal way. a token usually has a lifetime and it would be better for us to use the same token until the current one expires By the optimal solution I mean your code but with the changes that the wrapper knows when to send a request to receive a token, and when not necessary, and it caches the token if it is still valid Moreover, you will need to cache the token either locally (if there is one instance of the service), or in a shared data source such as postgresql, redis, and etc. (in the case of, for example, several k8s pods or several wsgi/asgi processes) |
I did not mean you need to get new token every time in that method. You can implement your own logic here. There are so many options that I can't imagine now how framework can provide any help here |
Understood |
Hi!
Does your wrapper have the ability to send requests with an authentication token?
As a client I could provide an endpoint and authorization data, and in return I could receive, for example, a json web token. This assumes correct operation in a concurrent environment within one service instance and caching of the token until it expires
The text was updated successfully, but these errors were encountered: