From 583da03cfd76fe2061f4748f95775d771f6d1eb5 Mon Sep 17 00:00:00 2001 From: Joel Lee Date: Mon, 25 Jan 2021 10:47:20 +0800 Subject: [PATCH] Test initial stubs against gotrue-example site --- gotrue_py/admin.py | 2 +- gotrue_py/client.py | 43 +++++++++++++++++++++++++++++++++++++------ gotrue_py/user.py | 7 +++++-- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/gotrue_py/admin.py b/gotrue_py/admin.py index e47405b7..3b762bd9 100644 --- a/gotrue_py/admin.py +++ b/gotrue_py/admin.py @@ -4,7 +4,7 @@ def __init__(self): self.user = user def listUsers(aud): - return requests.get() + return requests.post() def getUser(self,user): pass diff --git a/gotrue_py/client.py b/gotrue_py/client.py index 640ca88b..920ac1d5 100644 --- a/gotrue_py/client.py +++ b/gotrue_py/client.py @@ -1,15 +1,36 @@ +import requests +import user +import re +import urllib +import json +HTTPRegexp = /^http:\/\//; +defaultApiURL = "/.netlify/identity" + class Client: def __init__(url, audience='', setCookie=False): - pass - - def _request(): - pass + if re.match(HTTPRegexp): + # 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.") + if audience: + self.audience = audience + self.setCookie = setCookie + self.BASE_URL = "https://distracted-elion-6bf6a2.netlify.app/.netlify/identity/" + def _request(path, options=[]): + options = option.headers or [] + aud = options.audience or self.audience + if aud: + options.headers['X-JWT-AUD'] = aud + def settings(): pass def signup(email, password, data): - pass + data = json.dumps({ + "email": "yadayada@gmail.com", + "password": "yadayada" + }) + requests.post("https://distracted-elion-6bf6a2.netlify.app/.netlify/identity/signup", data) def login(): pass @@ -39,8 +60,18 @@ def currentUser(): pass def verify(type, token, remember): + requests.post("https://distracted-elion-6bf6a2.netlify.app/.netlify/identity/verify",data=json.dumps({"type": "signup", "token": "cixoe6C7k1tqx2UuYL_O3w"})) pass def _setRememberHeaders(remember): - pass + if self.setCookie: + self.api.defaultHeaders = self.api.defaultHeaders or {}; + self.api.defaultHeaders['X-Use-Cookie'] = remember ? '1' : 'session'; + def grant_token(type, payload): + payload = json.dumps({ + "email": "yadayada@gmail.com", + "password": "yadayada" + }) + headers = { 'Content-Type': 'application/x-www-form-urlencoded' } + requests.post("https://distracted-elion-6bf6a2.netlify.app/.netlify/identity/verify",data=json.dumps({"type": "signup", "token": "tokenthing"})) diff --git a/gotrue_py/user.py b/gotrue_py/user.py index 73232d14..16e61be1 100644 --- a/gotrue_py/user.py +++ b/gotrue_py/user.py @@ -1,10 +1,13 @@ class User: def __init__(api, tokenRepsonse, audience): - pass + self.api = api + self.url = api.apiURL + self._processTokenResponse(tokenResponse) + currentUser = self @staticmethod def removeSavedSession(): - pass + # isBrowser() @staticmethod def recoverSession():