connexion.security

This module defines SecurityHandlerFactories which support the creation of security handlers for operations.

isort:skip_file

Submodules

Package Contents

Classes

SecurityHandlerFactory

get_*_func -> _get_function -> get_function_from_name (name=security function defined in spec)

class connexion.security.SecurityHandlerFactory
get_*_func -> _get_function -> get_function_from_name (name=security function defined in spec)

(if url defined instead of a function -> get_token_info_remote)

std security functions: security_{passthrough,deny}

verify_* -> returns a security wrapper around the security function
check_* -> returns a function tasked with doing auth for use inside the verify wrapper

check helpers (used outside wrappers): _need_to_add_context_or_scopes the security function

verify helpers (used inside wrappers): get_auth_header_value, get_cookie_value

no_value
required_scopes_kw = required_scopes
context_kw = context_
client
get_tokeninfo_func(self, security_definition: dict) Optional[Callable]
>>> get_tokeninfo_url({'x-tokenInfoFunc': 'foo.bar'})
'<function foo.bar>'
classmethod get_scope_validate_func(cls, security_definition)
Return type:

function

>>> get_scope_validate_func({'x-scopeValidateFunc': 'foo.bar'})
'<function foo.bar>'
classmethod get_basicinfo_func(cls, security_definition)
Return type:

function

>>> get_basicinfo_func({'x-basicInfoFunc': 'foo.bar'})
'<function foo.bar>'
classmethod get_apikeyinfo_func(cls, security_definition)
Return type:

function

>>> get_apikeyinfo_func({'x-apikeyInfoFunc': 'foo.bar'})
'<function foo.bar>'
classmethod get_bearerinfo_func(cls, security_definition)
Return type:

function

>>> get_bearerinfo_func({'x-bearerInfoFunc': 'foo.bar'})
'<function foo.bar>'
async static security_passthrough(request)
static security_deny(function)
Return type:

types.FunctionType

static validate_scope(required_scopes, token_scopes)
Parameters:
  • required_scopes – Scopes required to access operation

  • token_scopes – Scopes granted by authorization server

Return type:

bool

static get_auth_header_value(request)

Called inside security wrapper functions

Return Authorization type and value if any. If not Authorization, return (None, None) Raise OAuthProblem for invalid Authorization header

verify_oauth(self, token_info_func, scope_validate_func, required_scopes)
verify_basic(self, basic_info_func)

Called inside security wrapper functions

Returns cookie value by its name. None if no such value. :param cookies: str: cookies raw data :param name: str: cookies key

verify_api_key(self, api_key_info_func, loc, name)
verify_bearer(self, token_info_func)
Parameters:

token_info_func – types.FunctionType

Return type:

types.FunctionType

verify_multiple_schemes(self, schemes)

Verifies multiple authentication schemes in AND fashion. If any scheme fails, the entire authentication fails.

Parameters:

schemes (dict) – mapping scheme_name to auth function

Return type:

types.FunctionType

static verify_none()
Return type:

types.FunctionType

check_bearer_token(self, token_info_func)
check_basic_auth(self, basic_info_func)
check_api_key(self, api_key_info_func)
check_oauth_func(self, token_info_func, scope_validate_func)
classmethod verify_security(cls, auth_funcs)
get_token_info_remote(self, token_info_url)

Return a function which will call token_info_url to retrieve token info.

Returned function must accept oauth token in parameter. It must return a token_info dict in case of success, None otherwise.

Parameters:

token_info_url (str) – Url to get information about the token

Return type:

types.FunctionType