Comments (2)
I believe it is. It's not very well documented, and I had to dig into the implementation to find it, but since this library uses the requests library, and aiohttp for async, behind the scenes you should be able to create a custom auth handler for requests (example shown here) and pass that as a keyword arg to your http methods. Here's my 22:30 guess at what that might look like. I'll be working on a problem similar to this in the morning so will update once I get that working.
from requests.auth import AuthBase
class SignatureAuth(AuthBase):
def __init__(self, adp_token, private_key):
self.adp_token = adp_token
self.private_key = private_key
def __call__(self, r):
r.headers.update(self.sign_request(r.url, r.method, r.body, self.adp_token, self.private_key))
return r
# some predefined resource, SignedResource
signature_auth = SignatureAuth(adp_token, private_key)
test_api = API(api_root_url="https://test.com")
test_api.add_resource(resource_name="test", resource_class=SignedResource)
test_api.retrieve(queryParam, auth=signature_auth)
from python-simple-rest-client.
Hi. Thank you very much.
My solution looks like similar to yours. I have create a class who inherits from requests.auth.AuthBase.
Next I create a own Resource class who inherits from simple_rest_client.resource.Resource.
class UserResource(Resource):
actions = {
'library': {'method': 'GET', 'url': "0.0/library/books"},
'retrieve_wishlist': {'method': 'GET', 'url': '1.0/wishlist'},
'add_to_wishlist': {'method': 'POST', 'url': '1.0/wishlist'},
'remove_from_wishlist': {'method': 'DELETE', 'url': '1.0/wishlist/{}'},
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.session.auth = PrivateKeyAuth(adp_token, private_key)
default_header = {
"Accept": 'application/json',
'Content-Type': 'application/json'
}
# create api instance
audible_api = API(
api_root_url='https://api.audible.de', headers=default_header,
json_encode_body=True
)
# add events resource with EventResource
audible_api.add_resource(resource_name='user', resource_class=UserResource)
# show resource actions
params = {'response_groups': 'product_desc'}
response = audible_api.user.retrieve_wishlist(params=params)
from python-simple-rest-client.
Related Issues (20)
- Extending resource default actions HOT 1
- File upload example
- Looks like json encoder uses huge amount of memory
- New httpx v0.8.0 breaks library
- Authentication HOT 1
- Dash in resource name: Mangling of resource names in add_resource() breaks compatibility HOT 2
- Feature request: Support docstring
- New httpx 0.12.1 breaks simple rest client
- feature request : Support for OAuth based authentication for API client
- Incorrect exception caught on timeout
- json_encode_body cannot be overridden if True in API HOT 2
- Handle connection refused exception
- Proxy Error 503
- Posibility to disable timeout?
- Question about concurrent requests limit
- add custom user agent feature
- suggestion regarding async HOT 3
- Incompatible with httpx>=0.19.0
- How to code for composite primary key?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-simple-rest-client.