Пример #1
0
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),
    )
Пример #2
0
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')
Пример #3
0
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)))
Пример #4
0
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)
Пример #5
0
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)),
    )