urlwatch icon indicating copy to clipboard operation
urlwatch copied to clipboard

Feature request: Custom AWS (requests) Authentication

Open batandwa opened this issue 3 years ago • 7 comments

I would like create a custom hook that sets custom authentication that is compatible request module.

For context... I thought this would be useful when I was doing AWS v4 signing using the aws_request_auth module.

batandwa avatar Aug 08 '22 13:08 batandwa

I am willing to contribute to this...

batandwa avatar Aug 08 '22 13:08 batandwa

Custom authentication here means special HTTP headers sent with the request? Or something more sophisticated?

thp avatar Aug 08 '22 14:08 thp

Whatever the request module allows in the auth parameter when executing request()

batandwa avatar Aug 08 '22 14:08 batandwa

On the other hand... That may lead to the request module being an irreplaceable dependency.

batandwa avatar Aug 08 '22 14:08 batandwa

On the other hand... That may lead to the request module being an irreplaceable dependency.

That's fine, it is already a required dependency.

Whatever the request module allows in the auth parameter when executing request()

The docs say:

auth – (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.

So I guess this means you get a tuple like (username, password) passed there and requests takes care of creating the right header. Should be easy to allow for this. However, for "custom" authentication, you can anyway just set a HTTP header. Granted, for Basic auth, username/password is convenient, and for Digest auth it's essential.

thp avatar Sep 17 '22 17:09 thp

..and i read your request again -- in this case, you probably would like to have a way of adding all the AWS settings and then pass the AWSRequestsAuth() object to the auth, so just configuring username/password in the YAML is not enough.

thp avatar Sep 17 '22 17:09 thp

One way to do it would be to subclass jobs.UrlJob as done in share/urlwatch/examples/hooks.py.example:

class CustomLoginJob(jobs.UrlJob):
    """Custom login for my webpage"""

    __kind__ = 'aws-login'
    __required__ = ('aws_access_key', 'aws_secret_access_key', ...)

    def retrieve(self, job_state):
        ... # TODO: Make request, return response, use self.aws_access_key, etc...

thp avatar Sep 17 '22 17:09 thp