Skip to content

Commit

Permalink
Merge pull request #570 from AnswerDotAI/handle-oauth-error
Browse files Browse the repository at this point in the history
handle oauth error
  • Loading branch information
johnowhitaker authored Nov 7, 2024
2 parents ef8f676 + f018749 commit a206c06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions fasthtml/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ def url_match(url, patterns=http_patterns):

# %% ../nbs/api/08_oauth.ipynb
class OAuth:
def __init__(self, app, cli, skip=None, redir_path='/redirect', logout_path='/logout', login_path='/login', https=True, http_patterns=http_patterns):
if not skip: skip = [redir_path,login_path]
def __init__(self, app, cli, skip=None, redir_path='/redirect', error_path='/error', logout_path='/logout', login_path='/login', https=True, http_patterns=http_patterns):
if not skip: skip = [redir_path,error_path,login_path]
store_attr()
def before(req, session):
auth = req.scope['auth'] = session.get('auth')
Expand All @@ -150,8 +150,8 @@ def before(req, session):
app.before.append(Beforeware(before, skip=skip))

@app.get(redir_path)
def redirect(code:str, req, session, state:str=None):
if not code: return "No code provided!"
def redirect(req, session, code:str=None, error:str=None, state:str=None):
if not code: session['oauth_error']=error; return RedirectResponse(self.error_path, status_code=303)
scheme = 'http' if url_match(req.url,self.http_patterns) or not self.https else 'https'
base_url = f"{scheme}://{req.url.netloc}"
info = AttrDictDefault(cli.retr_info(code, base_url+redir_path))
Expand Down
8 changes: 4 additions & 4 deletions nbs/api/08_oauth.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@
"source": [
"#| export\n",
"class OAuth:\n",
" def __init__(self, app, cli, skip=None, redir_path='/redirect', logout_path='/logout', login_path='/login', https=True, http_patterns=http_patterns):\n",
" if not skip: skip = [redir_path,login_path]\n",
" def __init__(self, app, cli, skip=None, redir_path='/redirect', error_path='/error', logout_path='/logout', login_path='/login', https=True, http_patterns=http_patterns):\n",
" if not skip: skip = [redir_path,error_path,login_path]\n",
" store_attr()\n",
" def before(req, session):\n",
" auth = req.scope['auth'] = session.get('auth')\n",
Expand All @@ -429,8 +429,8 @@
" app.before.append(Beforeware(before, skip=skip))\n",
"\n",
" @app.get(redir_path)\n",
" def redirect(code:str, req, session, state:str=None):\n",
" if not code: return \"No code provided!\"\n",
" def redirect(req, session, code:str=None, error:str=None, state:str=None):\n",
" if not code: session['oauth_error']=error; return RedirectResponse(self.error_path, status_code=303)\n",
" scheme = 'http' if url_match(req.url,self.http_patterns) or not self.https else 'https'\n",
" base_url = f\"{scheme}://{req.url.netloc}\"\n",
" info = AttrDictDefault(cli.retr_info(code, base_url+redir_path))\n",
Expand Down

0 comments on commit a206c06

Please sign in to comment.