ex.)
 before_action -> { require_authentication! as: :user }, only: :secret_action
763459
def require_authentication!(options = {})
      options.reverse_merge!(as: :user)
      return if self.class.allow_actions == :all
      return if self.class.allow_actions.present? && params[:action].to_sym.in?(self.class.allow_actions)

      unless signed_in?(options)
        session["#{options[:as]}_return_to"] = request.url if request.get?
        redirect_to new_session_path_for(options[:as])
      end
    end
107309
def should_require_authentication(self, url):
        
        return (not self.routes # require auth for all URLs
                or any(route.match(url) for route in self.routes))
387536
def secretly(reactor, action, system=None, username=None,
             prompt="Password:"):
    
    if system is None:
        system = action.__module__
        if system == '__main__':
            system = os.path.abspath(sys.argv[0])
    if username is None:
        username = getpass.getuser()
    while True:
        secret = keyring.get_password(system, username)
        if secret is not None:
            break
        pinentry = yield choosePinentry()
        keyring.set_password(
            system, username,
            (yield pinentry.askForPassword(
                reactor, prompt, "Enter Password",
                "Password Prompt for {username}@{system}"
                .format(system=system, username=username)))
        )
    yield maybeDeferred(action, secret)
730191
def authorize(action, subject)
      current_ability.authorize! action, subject
    rescue ::CanCan::AccessDenied
      Rails.logger.info I18n.t('errors.unauthorized', user: user, action: action, subject: subject)
      raise Forbidden
    end
523581
def authorize!(action, subject, *args)
      message = args.last.is_a?(Hash) && args.last.key?(:message) ? args.pop[:message] : nil
      if cannot?(action, subject, *args)
        message ||= unauthorized_message(action, subject)
        raise AccessDenied.new(message, action, subject, args)
      end
      subject
    end
499668
def before(self):
        """"""
        user = self.request.user()

        if user and user.verified_at is None:
            self.request.redirect('/email/verify')
774269
def permission_required(perm, login_url=None):
    

    return user_passes_test(lambda u: u.has_perm(perm), login_url=login_url)
1172195
def _authenticate_plain(credentials, sock_info):
    
    source = credentials.source
    username = credentials.username
    password = credentials.password
    payload = ('\x00%s\x00%s' % (username, password)).encode('utf-8')
    cmd = SON([('saslStart', 1),
               ('mechanism', 'PLAIN'),
               ('payload', Binary(payload)),
               ('autoAuthorize', 1)])
    sock_info.command(source, cmd)
335993
def receive_verify_post(params, request)
      if request.post?
        [:action, :email, :send_id, :sig].each { |key| return false unless params.has_key?(key) }

        return false unless params[:action] == :verify

        sig = params.delete(:sig)
        params.delete(:controller)
        return false unless sig == get_signature_hash(params, @secret)

        _send = get_send(params[:send_id])
        return false unless _send.has_key?('email')

        return false unless _send['email'] == params[:email]

        return true
      else
        return false
      end
    end
257059
def deny_user(user):
    """"""
    def processor(action, argument):
        db.session.add(
            ActionUsers.deny(action, argument=argument, user_id=user.id)
        )
    return processor
410985
def permission_for_action(self, action):
        
        return "%s.%s_%s" % (self.app_name.lower(), self.model_name.lower(), action)
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
1033720
def signed_in?(options = {})
      options.reverse_merge!(as: :user)
      current_authenticated(options).present? && \
        current_authenticated(options).class.name.demodulize.underscore == options[:as].to_s
    end
53267
public function beforeAction($action)
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        if (!Yii::$app->session->hasSessionId) {
            throw new BadRequestHttpException('Need an active session');
        }
        return parent::beforeAction($action);
    }
287720
def authorized?(robot, user, required_groups)
      required_groups.nil? || required_groups.any? do |group|
        robot.auth.user_in_group?(user, group)
      end
    end
963113
def requires_basic_auth(f):
    """"""

    def check_auth(username, password):
        return username == "guest" and password == "secret"

    def authenticate():
        return Response(
            "Authentication required.", 401,
            {"WWW-Authenticate": "Basic realm='Login Required'"},
        )

    @wraps(f)
    def decorated(*args, **kwargs):
        # NOTE: This example will require Basic Auth only when you run the
        # app directly. For unit tests, we can't block it from getting the
        # Swagger specs so we just allow it to go thru without auth.
        # The following two lines of code wouldn't be needed in a normal
        # production environment.
        if __name__ != "__main__":
            return f(*args, **kwargs)

        auth = request.authorization
        if not auth or not check_auth(auth.username, auth.password):
            return authenticate()
        return f(*args, **kwargs)

    return decorated
1353771
def check_auth_params
      if (Fulfil.authentication.nil? || Fulfil.authentication[:subdomain].empty? || Fulfil.authentication[:api_key].empty?)
        raise Fulfil::AuthenticationError, "Please set your subdomain and api key"
      end
    end