|
417 | 417 | "source": [
|
418 | 418 | "#| export\n",
|
419 | 419 | "class OAuth:\n",
|
420 |
| - " def __init__(self, app, cli, skip=None, redir_path='/redirect', logout_path='/logout', login_path='/login', https=True, http_patterns=http_patterns):\n", |
421 |
| - " if not skip: skip = [redir_path,login_path]\n", |
| 420 | + " 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", |
| 421 | + " if not skip: skip = [redir_path,error_path,login_path]\n", |
422 | 422 | " store_attr()\n",
|
423 | 423 | " def before(req, session):\n",
|
424 | 424 | " auth = req.scope['auth'] = session.get('auth')\n",
|
|
429 | 429 | " app.before.append(Beforeware(before, skip=skip))\n",
|
430 | 430 | "\n",
|
431 | 431 | " @app.get(redir_path)\n",
|
432 |
| - " def redirect(code:str, req, session, state:str=None):\n", |
433 |
| - " if not code: return \"No code provided!\"\n", |
| 432 | + " def redirect(req, session, code:str=None, error:str=None, state:str=None):\n", |
| 433 | + " if not code: session['oauth_error']=error; return RedirectResponse(self.error_path, status_code=303)\n", |
434 | 434 | " scheme = 'http' if url_match(req.url,self.http_patterns) or not self.https else 'https'\n",
|
435 | 435 | " base_url = f\"{scheme}://{req.url.netloc}\"\n",
|
436 | 436 | " info = AttrDictDefault(cli.retr_info(code, base_url+redir_path))\n",
|
|
0 commit comments