Skip to content
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

Compatibility with Requests AuthBase #103

Open
aparamon opened this issue Feb 1, 2019 · 2 comments
Open

Compatibility with Requests AuthBase #103

aparamon opened this issue Feb 1, 2019 · 2 comments

Comments

@aparamon
Copy link

aparamon commented Feb 1, 2019

Currently, asks supports extensible authz/authn:
https://asks.readthedocs.io/en/latest/overview-of-funcs-and-args.html#authing
https://github.com/theelous3/asks/blob/master/asks/auth.py
It is possible to inherit from AuthBase to introduce missing auth methods.

Unfortunately, asks.auth.AuthBase is not compatible with requests.auth.AuthBase:
http://docs.python-requests.org/en/master/user/authentication/#new-forms-of-authentication

It would be awesome if existing non-trivial requests auth plugins could be used with asks as well.
For example:
https://github.com/lepture/authlib/blob/dee7f003b74252e22d62e11a91ec1b629b6fdeae/authlib/client/oauth2_session.py#L22-L34

@andersea
Copy link
Contributor

andersea commented Jul 4, 2019

Specifically for signing requests to cryptocurrency exchange apis I need the body to be available in the request object.

Edit:

The body is generated here, but isn't added as an attribute of the request object.

    # handle building the request body, if any
    body = ''
    if any((self.data, self.files, self.json is not None)):
        content_type, content_len, body = await self._formulate_body()
        asks_headers['Content-Type'] = content_type
        asks_headers['Content-Length'] = content_len

See - https://www.bitmex.com/app/apiKeysUsage

Here is a requests based auth implementation:

https://github.com/BitMEX/sample-market-maker/blob/master/market_maker/auth/APIKeyAuthWithExpires.py

@andersea
Copy link
Contributor

andersea commented Jul 4, 2019

PR #128 adds the body attribute to allow the described use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants