Skip to content

Commit

Permalink
All constructor args can now be configured at class level
Browse files Browse the repository at this point in the history
This makes it easy to write pre-configured subclasses:

```python
class MyService(OAuth2):
    site = "https://www.example.com"
    authorization_url = "/o/auth"
    ...
```
  • Loading branch information
rollcat committed Feb 25, 2018
1 parent 725d720 commit 7eb926b
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions requests_oauth2/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@


class OAuth2(object):
client_id = None
client_secret = None
site = None
redirect_uri = None
authorization_url = '/oauth/authorize'
token_url = '/oauth/token'
revoke_url = '/oauth2/revoke'
scope_sep = None

def __init__(self, client_id, client_secret, site, redirect_uri,
authorization_url=None, token_url=None,
revoke_url=None, scope_sep=None):
def __init__(self, client_id=None, client_secret=None, site=None,
redirect_uri=None, authorization_url=None,
token_url=None, revoke_url=None, scope_sep=None):
"""
Initializes the hook with OAuth2 parameters
"""
self.client_id = client_id
self.client_secret = client_secret
self.site = site
self.redirect_uri = redirect_uri
if client_id is not None:
self.client_id = client_id
if client_secret is not None:
self.client_secret = client_secret
if site is not None:
self.site = site
if redirect_uri is not None:
self.redirect_uri = redirect_uri
if authorization_url is not None:
self.authorization_url = authorization_url
if token_url is not None:
Expand Down

0 comments on commit 7eb926b

Please sign in to comment.