Authenticate a request

 Takes a block which will be called with the auth_key from the request,
 and which should return a Signature::Token (or nil if no token can be
 found for the key)

 Raises errors in the same way as authenticate_by_token!
486991
def authenticate(timestamp_grace = 600)
      raise ArgumentError, "Block required" unless block_given?
      key = @auth_hash['auth_key']
      raise AuthenticationError, "Missing parameter: auth_key" unless key
      token = yield key
      unless token
        raise AuthenticationError, "Unknown auth_key"
      end
      authenticate_by_token!(token, timestamp_grace)
      return token
    end
274247
def authenticate!(*args)
      defaults = {action: RailsWarden.unauthenticated_action}
      if args.last.is_a? Hash
        args[-1] = defaults.merge(args.last)
      else
        args << defaults
      end
      warden.authenticate!(*args)
    end
1374436
def validate_token
      token = params[:token]
      return false if token.nil?
      
      user = User.validate_token(token)
      return false if user.nil?
     
      login_user(user)
      return true
    end
432786
def authenticate!
      access_token = get_access_token
    
      if @client.authorized?
        session[:access_token] = access_token.token
        session[:secret_token] = access_token.secret
        session[:user] = @client.info

        session[:user]
      else
        nil
      end
    end
227670
def auth(self, auth_key):
        
        if self._socket is None:
            self._socket = self._connect()
        return self.call('auth', {"AuthKey": auth_key}, expect_body=False)
512960
def authenticate(self):
        
        if self._auth_token is None or self._token_expiry < time.time():
            self._perform_auth()

        yield self._auth_token
868288
def authenticate_credentials(self, token: bytes, request=None):
        
        user = AuthToken.get_user_for_token(token)

        if user is None:
            raise AuthenticationFailed(_('Invalid auth token.'))

        if not user.is_active:
            raise AuthenticationFailed(_('User inactive or deleted.'))

        return user, token
119491
def call_api(path, params = {})
      raise ArgumentError, 'You must include an HTTP method' unless params[:method]
      raise InvalidConnection, 'You have not authenticated and have no token' unless @token
      headers = {
        'Content-Type' => 'application/json',
        'Authorization' => "Bearer #{@token}"
      }
      headers.merge!(params[:headers]) if params[:headers]

      arguments = {headers: headers}
      arguments.merge!({body: params[:body].to_json}) if params[:body]
      arguments.merge!({query: params[:query]}) if params[:query]

      HTTParty.send params[:method], url(path), arguments
    end
873498
def get_request(self, request):
        """"""
        request.headers['authenticate'] = {
            'username': self.username,
            'apiKey': self.api_key,
        }
        return request
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)
1289002
def auth(self, encoded):
        
        message, signature = self.split(encoded)
        computed = self.sign(message)
        if not hmac.compare_digest(signature, computed):
            raise AuthenticatorInvalidSignature
2013
def authenticate
      begin
        client = Plaid::Client.new(env: PlaidRails.env,
          client_id: PlaidRails.client_id,
          secret: PlaidRails.secret,
          public_key: PlaidRails.public_key)
        @exchange_token = client.item.public_token.exchange(link_params[:public_token])
        @params = link_params.merge!(token: link_params[:public_token])
        
      rescue => e
        Rails.logger.error "Error: #{e}"
        render text: e.message, status: 500
      end
    end
470706
def authenticate(cls, request, route, server_config):
        
        if not server_config.getboolean("auth", False):
            return

        user = server_config.get("user", "").strip()
        password = server_config.get("password", "").strip()

        if len(user) == 0:
            return

        if "AUTHORIZATION" in request.headers:
            if request.headers["AUTHORIZATION"] == aiohttp.helpers.BasicAuth(user, password, "utf-8").encode():
                return

        log.error("Invalid auth. Username should %s", user)

        response = Response(request=request, route=route)
        response.set_status(401)
        response.headers["WWW-Authenticate"] = 'Basic realm="GNS3 server"'
        # Force close the keep alive. Work around a Qt issue where Qt timeout instead of handling the 401
        # this happen only for the first query send by the client.
        response.force_close()
        return response
174408
def authenticate(&callback)
      user("me") do |user|
        self.token = user.token
        callback.call(user)
      end
    end
468226
def request(params, &block)
      cached_token = check_cache(request_params(params))
      return cached_token if cached_token
      cache_response(request_no_cache(request_params(params), &block))
    end
1245479
def authenticate(previous_token = None):
    

    # if we already have a session token, try to authenticate with it
    if previous_token != None:
        headers = server_connection.request("authenticate", {
            'session_token' : previous_token,
            'repository'    : config['repository']})[1] # Only care about headers

        if headers['status'] == 'ok':
            return previous_token

    # If the session token has expired, or if we don't have one, re-authenticate

    headers = server_connection.request("begin_auth", {'repository' : config['repository']})[1] # Only care about headers

    if headers['status'] == 'ok':
        signature = base64.b64encode(pysodium.crypto_sign_detached(headers['auth_token'].decode('utf-8'), config['private_key']))
        headers = server_connection.request("authenticate", {
            'auth_token' : headers['auth_token'],
            'signature'  : signature,
            'user'       : config['user'],
            'repository' : config['repository']})[1] # Only care about headers

        if headers['status'] == 'ok': return headers['session_token']
    raise SystemExit('Authentication failed')
1106062
def verify_chatwork_webhook_signature!(token = nil)
      ChatworkWebhookVerify.verify!(
        token:     token,
        body:      request.env["rack.input"].read,
        signature: request.headers["X-ChatWorkWebhookSignature"] || params[:chatwork_webhook_signature],
      )
    rescue ChatworkWebhookVerify::InvalidSignatureError, ::ArgumentError
      raise ActionController::BadRequest, "signature is invalid"
    end