Skip to content

Commit bb233f3

Browse files
committed
add 127.0.0.1 to redir
1 parent 1e40a53 commit bb233f3

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

fasthtml/_modidx.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137
'fasthtml/oauth.py'),
138138
'fasthtml.oauth.Auth0AppClient.login_link': ( 'api/oauth.html#auth0appclient.login_link',
139139
'fasthtml/oauth.py'),
140-
'fasthtml.oauth.Auth0AppClient.redir_url': ('api/oauth.html#auth0appclient.redir_url', 'fasthtml/oauth.py'),
141140
'fasthtml.oauth.DiscordAppClient': ('api/oauth.html#discordappclient', 'fasthtml/oauth.py'),
142141
'fasthtml.oauth.DiscordAppClient.__init__': ( 'api/oauth.html#discordappclient.__init__',
143142
'fasthtml/oauth.py'),

fasthtml/oauth.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,19 @@ def parse_response(self, code):
9090
# %% ../nbs/api/08_oauth.ipynb
9191
class Auth0AppClient(_AppClient):
9292
"A `WebApplicationClient` for Auth0 OAuth2"
93-
def __init__(self, domain, client_id, client_secret, code=None, scope=None, https=True, redirect_uri="", **kwargs):
94-
self.redirect_uri,self.https,self.domain = redirect_uri,https,domain
93+
def __init__(self, domain, client_id, client_secret, code=None, scope=None, redirect_uri="", **kwargs):
94+
self.redirect_uri,self.domain = redirect_uri,domain
9595
config = self._fetch_openid_config()
9696
self.base_url,self.token_url,self.info_url = config["authorization_endpoint"],config["token_endpoint"],config["userinfo_endpoint"]
97-
super().__init__(client_id, client_secret, code=code, scope=scope, https=https, redirect_uri=redirect_uri, **kwargs)
97+
super().__init__(client_id, client_secret, code=code, scope=scope, redirect_uri=redirect_uri, **kwargs)
9898

9999
def _fetch_openid_config(self):
100100
r = httpx.get(f"https://{self.domain}/.well-known/openid-configuration")
101101
r.raise_for_status()
102102
return r.json()
103103

104-
def redir_url(self, req): return redir_url(req, self.redirect_uri, "https" if self.https else "http")
105-
106104
def login_link(self, req):
107-
d = dict(response_type="code", client_id=self.client_id, scope=self.scope, redirect_uri=self.redir_url(req))
105+
d = dict(response_type="code", client_id=self.client_id, scope=self.scope, redirect_uri=redir_url(req, self.redirect_uri))
108106
return f"{self.base_url}?{urlencode(d)}"
109107

110108
# %% ../nbs/api/08_oauth.ipynb
@@ -118,7 +116,7 @@ def login_link(self:WebApplicationClient, redirect_uri, scope=None, state=None):
118116
# %% ../nbs/api/08_oauth.ipynb
119117
def redir_url(request, redir_path, scheme=None):
120118
"Get the redir url for the host in `request`"
121-
scheme = 'http' if request.url.hostname == 'localhost' else 'https'
119+
scheme = 'http' if request.url.hostname in ("localhost", "127.0.0.1") else 'https'
122120
return f"{scheme}://{request.url.netloc}{redir_path}"
123121

124122
# %% ../nbs/api/08_oauth.ipynb

nbs/api/08_oauth.ipynb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,28 +172,26 @@
172172
{
173173
"cell_type": "code",
174174
"execution_count": null,
175-
"id": "29521d68",
175+
"id": "276520b0",
176176
"metadata": {},
177177
"outputs": [],
178178
"source": [
179179
"#| export\n",
180180
"class Auth0AppClient(_AppClient):\n",
181181
" \"A `WebApplicationClient` for Auth0 OAuth2\"\n",
182-
" def __init__(self, domain, client_id, client_secret, code=None, scope=None, https=True, redirect_uri=\"\", **kwargs):\n",
183-
" self.redirect_uri,self.https,self.domain = redirect_uri,https,domain\n",
182+
" def __init__(self, domain, client_id, client_secret, code=None, scope=None, redirect_uri=\"\", **kwargs):\n",
183+
" self.redirect_uri,self.domain = redirect_uri,domain\n",
184184
" config = self._fetch_openid_config()\n",
185185
" self.base_url,self.token_url,self.info_url = config[\"authorization_endpoint\"],config[\"token_endpoint\"],config[\"userinfo_endpoint\"]\n",
186-
" super().__init__(client_id, client_secret, code=code, scope=scope, https=https, redirect_uri=redirect_uri, **kwargs)\n",
186+
" super().__init__(client_id, client_secret, code=code, scope=scope, redirect_uri=redirect_uri, **kwargs)\n",
187187
"\n",
188188
" def _fetch_openid_config(self):\n",
189189
" r = httpx.get(f\"https://{self.domain}/.well-known/openid-configuration\")\n",
190190
" r.raise_for_status()\n",
191191
" return r.json()\n",
192192
"\n",
193-
" def redir_url(self, req): return redir_url(req, self.redirect_uri, \"https\" if self.https else \"http\")\n",
194-
"\n",
195193
" def login_link(self, req):\n",
196-
" d = dict(response_type=\"code\", client_id=self.client_id, scope=self.scope, redirect_uri=self.redir_url(req))\n",
194+
" d = dict(response_type=\"code\", client_id=self.client_id, scope=self.scope, redirect_uri=redir_url(req, self.redirect_uri))\n",
197195
" return f\"{self.base_url}?{urlencode(d)}\""
198196
]
199197
},
@@ -204,7 +202,7 @@
204202
"metadata": {},
205203
"outputs": [],
206204
"source": [
207-
"cli = GoogleAppClient.from_file('/Users/jhoward/subs_aai/_nbs/oauth-test/client_secret.json')"
205+
"# cli = GoogleAppClient.from_file('/Users/jhoward/subs_aai/_nbs/oauth-test/client_secret.json')"
208206
]
209207
},
210208
{
@@ -297,7 +295,7 @@
297295
"#| export\n",
298296
"def redir_url(request, redir_path, scheme=None):\n",
299297
" \"Get the redir url for the host in `request`\"\n",
300-
" scheme = 'http' if request.url.hostname == 'localhost' else 'https'\n",
298+
" scheme = 'http' if request.url.hostname in (\"localhost\", \"127.0.0.1\") else 'https'\n",
301299
" return f\"{scheme}://{request.url.netloc}{redir_path}\""
302300
]
303301
},

0 commit comments

Comments
 (0)