1
1
""" This class provides authorization server activity. """
2
2
import re
3
- import six
4
3
import json
5
4
import pprint
6
5
from dominate import tags as dom
@@ -343,11 +342,15 @@ def handle_response(self, status_code=None, payload=None, headers=None, newSessi
343
342
344
343
:return: TornadoResponse()
345
344
"""
346
- sLog .debug (
347
- f"Handle authorization response with { status_code } status code:" ,
348
- "HTML page" if isinstance (payload , str ) and payload .startswith ("<!DOCTYPE html>" ) else payload ,
349
- )
350
345
resp = TornadoResponse (payload , status_code )
346
+ if not isinstance (payload , dict ):
347
+ sLog .debug (
348
+ f"Handle authorization response with { status_code } status code:" ,
349
+ "HTML page" if payload .startswith ("<!DOCTYPE html>" ) else payload ,
350
+ )
351
+ elif "error" in payload :
352
+ resp .clear_cookie ("auth_session" ) # pylint: disable=no-member
353
+ sLog .error (f"{ payload ['error' ]} : { payload .get ('error_description' , 'unknown' )} " )
351
354
if headers :
352
355
sLog .debug ("Headers:" , headers )
353
356
for key , value in headers :
@@ -356,7 +359,7 @@ def handle_response(self, status_code=None, payload=None, headers=None, newSessi
356
359
sLog .debug ("Initialize new session:" , newSession )
357
360
# pylint: disable=no-member
358
361
resp .set_secure_cookie ("auth_session" , json .dumps (newSession ), secure = True , httponly = True )
359
- if delSession or isinstance ( payload , dict ) and "error" in payload :
362
+ if delSession :
360
363
resp .clear_cookie ("auth_session" ) # pylint: disable=no-member
361
364
return resp
362
365
@@ -386,18 +389,13 @@ def validate_consent_request(self, request, provider=None):
386
389
387
390
:return: response generated by `handle_response` or S_ERROR or html
388
391
"""
389
- if request .method != "GET" :
390
- return self .handle_response (
391
- payload = getHTML ("use GET method" , theme = "error" , info = "Use GET method to access this endpoint." ),
392
- delSession = True ,
393
- )
394
392
try :
395
393
request = self .create_oauth2_request (request )
396
394
# Check Identity Provider
397
395
req = self .validateIdentityProvider (request , provider )
398
396
399
- # If return IdP selector
400
- if isinstance (req , six . string_types ):
397
+ # If return HTML page with IdP selector
398
+ if isinstance (req , str ):
401
399
return req
402
400
403
401
sLog .info ("Validate consent request for " , req .state )
0 commit comments