def get_authorization_stream(context: Context) -> Observable: return return_value(context).pipe( op.flat_map(call_async(validate_redirect_uri)), op.flat_map(call_async(validate_response_type)), op.flat_map(call_async(validate_scope)), op.flat_map(select_flow), )
def select_flow(context: Context) -> Observable: response_type = next(iter(context.oauth2_request.response_type)) if response_type == 'code': return return_value(context).pipe( op.flat_map(call_async(authorization_code_grant))) if response_type == 'token': return return_value(context).pipe( op.flat_map(call_async(implicit_grant))) raise InvalidRequest('Invalid response_type parameter')
def get_authorization_stream(request: OIDCRequest) -> Observable: response_params: Dict[str, Any] = {} # yapf: disable return just(request).pipe( op.flat_map(call_async(validate_redirect_uri)), op.flat_map(call_async(validate_response_type)), op.flat_map(call_async(validate_scope)), op.flat_map(select_flows), op.merge_all(), op.do_action(lambda x: response_params.update(asdict(x))), op.last(), op.map(lambda x: AuthorizationResponse(**response_params)))
def select_flows(request: OIDCRequest) -> Observable: observables: List[Observable] = [] for response_type in sorted( request.response_type, key=lambda x: x == 'id_token' and 1 or 0): if response_type == 'code': observables.append( just(request).pipe( op.flat_map(call_async(oauth2_authorization_code_grant)))) elif response_type == 'token': observables.append( just(request).pipe( op.flat_map(call_async(oauth2_implicit_grant)))) elif response_type == 'id_token': observables.append( just(request).pipe(op.flat_map(call_async(implicit_grant)))) else: raise InvalidRequest('Invalid response_type parameter') return from_list(observables)
def get_token_stream(context: Context) -> Observable: return return_value(context).pipe( op.map(validate_grant_type), op.flat_map(call_async(validate_code)), op.flat_map(call_async(get_token_by_code)), )