Construct the authn context with a authn context declaration
    :param decl: The authn context declaration
    :param authn_auth: Authenticating Authority
    :return: An AuthnContext instance
547273
def _authn_context_decl(decl, authn_auth=None):
    
    return factory(saml.AuthnContext,
                   authn_context_decl=decl,
                   authenticating_authority=factory(
                       saml.AuthenticatingAuthority, text=authn_auth))
267969
def begin_auth():
    

    repository    = request.headers['repository']
    if repository not in config['repositories']: return fail(no_such_repo_msg)

    # ==
    repository_path = config['repositories'][repository]['path']
    conn = auth_db_connect(cpjoin(repository_path, 'auth_transient.db')); gc_tokens(conn)

    # Issue a new token
    auth_token = base64.b64encode(pysodium.randombytes(35)).decode('utf-8')
    conn.execute("insert into tokens (expires, token, ip) values (?,?,?)",
                 (time.time() + 30, auth_token, request.environ['REMOTE_ADDR']))
    conn.commit()

    return success({'auth_token' : auth_token})
1168939
def parse_auth(rule):
    '''
    
    '''
    parser = argparse.ArgumentParser()
    rules = shlex.split(rule)
    rules.pop(0)
    noargs = ('back', 'test', 'nostart', 'kickstart', 'probe', 'enablecache',
              'disablecache', 'disablenis', 'enableshadow', 'disableshadow',
              'enablemd5', 'disablemd5', 'enableldap', 'enableldapauth',
              'enableldaptls', 'disableldap', 'disableldapauth',
              'enablekrb5kdcdns', 'disablekrb5kdcdns', 'enablekrb5realmdns',
              'disablekrb5realmdns', 'disablekrb5', 'disablehe-siod',
              'enablesmbauth', 'disablesmbauth', 'enablewinbind',
              'enablewinbindauth', 'disablewinbind', 'disablewinbindauth',
              'enablewinbindusedefaultdomain', 'disablewinbindusedefaultdomain',
              'enablewins', 'disablewins')
    for arg in noargs:
        parser.add_argument('--{0}'.format(arg), dest=arg, action='store_true')

    parser.add_argument('--enablenis', dest='enablenis', action='store')
    parser.add_argument('--hesiodrhs', dest='hesiodrhs', action='store')
    parser.add_argument('--krb5adminserver', dest='krb5adminserver',
                        action='append')
    parser.add_argument('--krb5kdc', dest='krb5kdc', action='append')
    parser.add_argument('--ldapbasedn', dest='ldapbasedn', action='store')
    parser.add_argument('--ldapserver', dest='ldapserver', action='append')
    parser.add_argument('--nisserver', dest='nisserver', action='append')
    parser.add_argument('--passalgo', dest='passalgo', action='store')
    parser.add_argument('--smbidmapgid', dest='smbidmapgid', action='store')
    parser.add_argument('--smbidmapuid', dest='smbidmapuid', action='store')
    parser.add_argument('--smbrealm', dest='smbrealm', action='store')
    parser.add_argument('--smbsecurity', dest='smbsecurity', action='store',
                        choices=['user', 'server', 'domain', 'dns'])
    parser.add_argument('--smbservers', dest='smbservers', action='store')
    parser.add_argument('--smbworkgroup', dest='smbworkgroup', action='store')
    parser.add_argument('--winbindjoin', dest='winbindjoin', action='store')
    parser.add_argument('--winbindseparator', dest='winbindseparator',
                        action='store')
    parser.add_argument('--winbindtemplatehomedir',
                        dest='winbindtemplatehomedir', action='store')
    parser.add_argument('--winbindtemplateprimarygroup',
                        dest='winbindtemplateprimarygroup', action='store')
    parser.add_argument('--winbindtemplateshell', dest='winbindtemplateshell',
                        action='store')

    parser.add_argument('--enablekrb5', dest='enablekrb5', action='store_true')
    if '--enablekrb5' in rules:
        parser.add_argument('--krb5realm', dest='krb5realm', action='store',
                            required=True)
    parser.add_argument('--enablehesiod', dest='enablehesiod',
                        action='store_true')
    if '--enablehesiod' in rules:
        parser.add_argument('--hesiodlhs', dest='hesiodlhs', action='store',
                            required=True)

    args = clean_args(vars(parser.parse_args(rules)))
    parser = None
    return args
734332
def _format_auth_line(key, enc, comment, options):
    '''
    
    '''
    line = ''
    if options:
        line += '{0} '.format(','.join(options))
    line += '{0} {1} {2}\n'.format(enc, key, comment)
    return line
1321968
function createAuthKey(context) {
    // Extract the nonces
    var newNonce = utility.string2Buffer(context.newNonce, 32);
    var serverNonce = utility.string2Buffer(context.resPQ.server_nonce, 16);
    // Create the serverSalt
    var serverSalt = utility.xor(newNonce.slice(0, 8), serverNonce.slice(0, 8));
    if (logger.isDebugEnabled()) {
        logger.debug('serverSalt(%s) = %s', serverSalt.length, serverSalt.toString('hex'));
    }
    // 
    var authKey = new AuthKey(context.authKeyID, context.authKeyValue);
    if (logger.isDebugEnabled()) {
        logger.debug('authKey = %s', authKey.toString());
    }
    return {
        key: authKey,
        serverSalt: serverSalt,
        toPrintable: tl.utility.toPrintable
    };
}
60747
def do_authentication(environ, start_response, authn_context, key,
                      redirect_uri):
    
    logger.debug("Do authentication")
    auth_info = AUTHN_BROKER.pick(authn_context)

    if len(auth_info):
        method, reference = auth_info[0]
        logger.debug("Authn chosen: %s (ref=%s)", method, reference)
        return method(environ, start_response, reference, key, redirect_uri)
    else:
        resp = Unauthorized("No usable authentication method")
        return resp(environ, start_response)
977784
def create(self, auth, type, desc, defer=False):
        
        return self._call('create', auth, [type, desc], defer)
1279597
def create_context(id_type=None, env=None, username=None, password=None,
        tenant_id=None, tenant_name=None, api_key=None, verify_ssl=None):
    
    if env:
        set_environment(env)
    return _create_identity(id_type=id_type, username=username,
            password=password, tenant_id=tenant_id, tenant_name=tenant_name,
            api_key=api_key, verify_ssl=verify_ssl, return_context=True)
1329452
def requires_auth(f):
    

    @wraps(f)
    def requires_auth_decorator(*args, **kwargs):

        try:
            authenticate_http_request()
        except PyMacaronException as e:
            return e.http_reply()

        return f(*args, **kwargs)

    return requires_auth_decorator
332990
def token(request, response, verify_user, context=None, **kwargs):
    
    token = request.get_header('Authorization')
    if token:
        try:
            verified_token = verify_user(token)
        except TypeError:
            verified_token = verify_user(token, context)
        if verified_token:
            return verified_token
        else:
            return False
    return None
1254503
private SecurityContext securityContext() {
        return SecurityContext.builder()
                .securityReferences(defaultAuth())
                .forPaths(PathSelectors.regex(swaggerProperties().getAuthorization().getAuthRegex()))
                .build();
    }
740163
def requires_password_auth(fn):
    """"""
    def wrapper(self, *args, **kwargs):
        self.auth_context = HAPI.auth_context_password
        return fn(self, *args, **kwargs)
    return wrapper
832128
def __auth_call(self, load):
        '''
        
        '''
        if 'eauth' not in load:
            return False
        fstr = '{0}.auth'.format(load['eauth'])
        if fstr not in self.auth:
            return False
        # When making auth calls, only username, password, auth, and token
        # are valid, so we strip anything else out.
        _valid = ['username', 'password', 'eauth', 'token']
        _load = {key: value for (key, value) in load.items() if key in _valid}

        fcall = salt.utils.args.format_call(
            self.auth[fstr],
            _load,
            expected_extra_kws=AUTH_INTERNAL_KEYWORDS)
        try:
            if 'kwargs' in fcall:
                return self.auth[fstr](*fcall['args'], **fcall['kwargs'])
            else:
                return self.auth[fstr](*fcall['args'])
        except Exception as e:
            log.debug('Authentication module threw %s', e)
            return False
487396
def pick_auth(endpoint_context, areq, all=False):
    

    acrs = []
    try:
        if len(endpoint_context.authn_broker) == 1:
            return endpoint_context.authn_broker.default()

        if "acr_values" in areq:
            if not isinstance(areq["acr_values"], list):
                areq["acr_values"] = [areq["acr_values"]]
            acrs = areq["acr_values"]
        else:  # same as any
            try:
                acrs = areq["claims"]["id_token"]["acr"]["values"]
            except KeyError:
                try:
                    _ith = areq[verified_claim_name("id_token_hint")]
                except KeyError:
                    try:
                        _hint = areq['login_hint']
                    except KeyError:
                        pass
                    else:
                        if endpoint_context.login_hint2acrs:
                            acrs = endpoint_context.login_hint2acrs(_hint)
                else:
                    try:
                        acrs = [_ith['acr']]
                    except KeyError:
                        pass

                if not acrs:
                    return endpoint_context.authn_broker.default()

        for acr in acrs:
            res = endpoint_context.authn_broker.pick(acr)
            logger.debug("Picked AuthN broker for ACR %s: %s" % (
                str(acr), str(res)))
            if res:
                if all:
                    return res
                else:
                    # Return the first guess by pick.
                    return res[0]

    except KeyError as exc:
        logger.debug(
            "An error occurred while picking the authN broker: %s" % str(exc))

    return None
1130411
def authenticate(self, request):
        
        authenticators = self._meta.authenticators

        if request.method == 'OPTIONS' and ADREST_ALLOW_OPTIONS:
            self.auth = AnonimousAuthenticator(self)
            return True

        error_message = "Authorization required."
        for authenticator in authenticators:
            auth = authenticator(self)
            try:
                if not auth.authenticate(request):
                    raise AssertionError(error_message)

                self.auth = auth
                auth.configure(request)
                return True
            except AssertionError, e:
                error_message = str(e)

        raise HttpError(error_message, status=status.HTTP_401_UNAUTHORIZED)
697880
def eauth(self, adata, load):
        '''
        
        '''
        for sub_auth in [adata]:
            if load['eauth'] not in sub_auth:
                continue
            try:
                name = self.loadauth.load_name(load)
                if not ((name in sub_auth[load['eauth']]) |
                        ('*' in sub_auth[load['eauth']])):
                    continue
                if not self.loadauth.time_auth(load):
                    continue
            except Exception as exc:
                log.error('Exception occurred while authenticating: %s', exc)
                continue
            yield {'sub_auth': sub_auth, 'name': name}
        yield {}
643462
def cmd_auth(auth_phrase=None):
    
    def decorate(func):
        """
        decorates the funcion
        """
        # get the Singleton
        ap_ = ArgParseInator(skip_init=True)
        # set the authorization name
        auth_name = id(func)
        if auth_phrase is None:
            # if we don't have a specific auth_phrase we set the
            # **authorization needed** to True
            ap_.auths[auth_name] = True
        else:
            # else if we have a specific auth_phrase we set it for the
            # command authorization
            ap_.auths[auth_name] = str(auth_phrase)
        return func
    return decorate