User is not authorized, bounce 'em to sign in
199592
def unauthorized(msg = t('flashes.failure_when_not_signed_in'))
      authenticate_session.logout
      respond_to do |format|
        format.any(:js, :json, :xml) { head :unauthorized }
        format.any { redirect_unauthorized(msg) }
      end
    end
957213
def authenticate(self, username=None, password=None, **kwargs):
        
        try:
            user = User.objects.get(email=username)
            if user.check_password(password):
                return user
        except (User.DoesNotExist, User.MultipleObjectsReturned):
            logging.warning('Unsuccessful login attempt using username/email: {0}'.format(username))

        return None
458719
async function authorize (action, target) {
    let result = await check(this.auth.credentials && this.auth.credentials.user, action, target)
    if (result !== true) throw Boom.unauthorized(action)
    return true
  }
740859
def attempt_reauthorization(blink):
    """"""
    _LOGGER.info("Auth token expired, attempting reauthorization.")
    headers = blink.get_auth_token(is_retry=True)
    return headers
991277
def _trig_auth_check(self, useriden):
        '''  '''
        if not self.user.admin and useriden != self.user.iden:
            raise s_exc.AuthDeny(user=self.user.name, mesg='As non-admin, may only manipulate triggers created by you')
1134506
def signedOn(self):
        """"""
        log.info("Signed on as %s.", self.nickname)
        if not self.password:
            # We aren't wating for auth, join all the channels
            self.joinChannels()
        else:
            self.msg("NickServ", "IDENTIFY %s" % self.password)
431005
def auth_pair(self, force_console=False):
        """"""
        if not self.auth_valid():
            self._get_auth(force_console)
        return (self.user, self.password)
1189331
function getAuthorization(user, auth) {
    if (auth === AUTH_BASIC) {
        return 'Basic ' + btoa(user.username + ':' + user.password);
    } else if (auth === AUTH_TOKEN) {
        return 'Token token=' + user.token;
    }
}
985258
def authenticate(api_key, api_url, **kwargs):
    """"""

    muddle = Muddle(**kwargs)

    # Login.
    muddle.authenticate(api_key, api_url)
    return muddle
506848
def _authenticate_client(self, client):
        """"""
        if self.login and not self.restart_required:
            try:
                db = client[self.auth_source]
                if self.x509_extra_user:
                    db.authenticate(
                        DEFAULT_SUBJECT,
                        mechanism='MONGODB-X509'
                    )
                else:
                    db.authenticate(
                        self.login, self.password)
            except Exception:
                logger.exception(
                    "Could not authenticate to %r as %s/%s"
                    % (client, self.login, self.password))
                raise
1161100
def sso(user, desired_username, name, email, profile_fields=None):
    
    if not user:
        if not settings.REGISTRATION_OPEN:
            raise SSOError('Account registration is closed')
        user = _create_desired_user(desired_username)
        _configure_user(user, name, email, profile_fields)

    if not user.is_active:
        raise SSOError('Account disabled')

    # login() expects the logging in backend to be set on the user.
    # We are bypassing login, so fake it.
    user.backend = settings.AUTHENTICATION_BACKENDS[0]
    return user
569707
def login(self, username=None, password=''):
        """"""
        auth = None
        if username is not None:
            # User login
            resp = self._login(username, password, self.client_id, self.client_secret)
            msg = "User Login"
        else:
            # client credentials
            resp = self._client(self.client_id, self.client_secret)
            msg = "Client credentials"
        if resp.status_code == requests.codes.ok:
            auth = resp.json()
            self.session.headers.update({
                'Authorization':
                    ("%s %s" % (auth['token_type'], auth['access_token']))
            })
        else:
            error = {'description': "%s not valid" % msg }
            raise UAAException(error, resp.status_code)
        return auth
927156
def authenticate_eauth(self, load):
        '''
        
        '''
        if 'eauth' not in load:
            log.warning('Authentication failure of type "eauth" occurred.')
            return False

        if load['eauth'] not in self.opts['external_auth']:
            log.warning('The eauth system "%s" is not enabled', load['eauth'])
            log.warning('Authentication failure of type "eauth" occurred.')
            return False

        # Perform the actual authentication. If we fail here, do not
        # continue.
        if not self.time_auth(load):
            log.warning('Authentication failure of type "eauth" occurred.')
            return False

        return True
906865
def AuthorizingClient(domain, auth, user_agent=None):
    """"""
    http_transport = transport.HttpTransport(domain, build_headers(auth, user_agent))
    return client.Client(http_transport)
394506
def requires_user(fn):
        
        @functools.wraps(fn)
        def wrap(*args, **kwargs):

            subject = WebYosai.get_current_subject()

            if subject.identifiers is None:
                msg = ("Attempting to perform a user-only operation.  The "
                       "current Subject is NOT a user (they haven't been "
                       "authenticated or remembered from a previous login). "
                       "ACCESS DENIED.")
                raise WebYosai.get_current_webregistry().raise_unauthorized(msg)
            return fn(*args, **kwargs)
        return wrap
42347
protected function _handleUnauthenticatedAccess()
    {
        header("HTTP/1.0 401 Unauthorized");
        $renderer = new TwigRenderer();
        $output = $renderer->render('unauth.tmpl', array());
        $result = array("code"=>"401","message" => $output);
        echo parent::encodeData($result);
        exit;

    }
356275
def authenticate(username, password, permission=None):
    
    try:
        author = Author.objects.get(
            **{'%s__exact' % Author.USERNAME_FIELD: username})
    except Author.DoesNotExist:
        raise Fault(LOGIN_ERROR, _('Username is incorrect.'))
    if not author.check_password(password):
        raise Fault(LOGIN_ERROR, _('Password is invalid.'))
    if not author.is_staff or not author.is_active:
        raise Fault(PERMISSION_DENIED, _('User account unavailable.'))
    if permission:
        if not author.has_perm(permission):
            raise Fault(PERMISSION_DENIED, _('User cannot %s.') % permission)
    return author