Skip to content

Commit

Permalink
Allow headers and lint with black
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Lee authored and Joel Lee committed Feb 5, 2021
1 parent d768579 commit d9c9533
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ credentials = {"email": "anemail@gmail.com", "password": "gmebbnok"}
client.sign_up(credentials)
client.sign_in(credentials)
```


### Development
### Development/TODOs
- Figure out to use either Sessions to manage headers or allow passing in of headers

16 changes: 10 additions & 6 deletions gotrue/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,35 @@ def jsonify(dictionary: dict):


class Client:
def __init__(self, url, audience='', setCookie=False):
def __init__(self, url, audience="", setCookie=False, headers={}):
if re.match(HTTPRegexp, url):
# TODO: Decide whether to convert this to a logging statement
print(
"Warning:\n\nDO NOT USE HTTP IN PRODUCTION FOR GOTRUE EVER!\nGoTrue REQUIRES HTTPS to work securely."
)
self.BASE_URL = url
self.headers = headers

def settings(self):
"""Get environment settings for the server"""
return requests.get(f"{self.BASE_URL}/settings")
return requests.get(f"{self.BASE_URL}/settings", headers=self.headers)

def sign_up(self, credentials: dict):
return requests.post(f"{self.BASE_URL}/signup", jsonify(credentials))
return requests.post(
f"{self.BASE_URL}/signup", jsonify(credentials), headers=self.headers
)

def sign_in(self, credentials: dict):
"""Sign in with email and password"""
return self.grant_token("password", credentials)
return self.grant_token("password", credentials, headers=self.headers)

def refresh_access_token(self, refresh_token: str):
return grant_token("refresh_token", {"refresh_token": refresh_token})

def grant_token(self, type: str, data: dict):
return requests.post(f"{self.BASE_URL}/token?grant_type=#{type}/",
jsonify(data))
return requests.post(
f"{self.BASE_URL}/token?grant_type=#{type}/", jsonify(data)
)

def sign_out(jwt: str):
"""Sign out user using a valid JWT"""
Expand Down

0 comments on commit d9c9533

Please sign in to comment.