<commit_before>require "rack"
require "rack/request"
require "oauth"
require "oauth/request_proxy/rack_request"

module OAuth
  module Rack

    # An OAuth 1.0a filter to be used together with the oauth-plugin for rails.T
    # This is still experimental
    #
    # Add it as middleware to your config/application.rb:
    #
    # require 'oauth/rack/oauth_filter'
    # config.middleware.use OAuth::Rack::OAuthFilter

    class OAuthFilter
      def initialize(app)
        @app = app
      end

      def call(env)
        request = ::Rack::Request.new(env)
        env["oauth_plugin"] = true
        strategies = []
        if token_string = oauth2_token(request)
          if token = Oauth2Token.first(:conditions => ['invalidated_at IS NULL AND authorized_at IS NOT NULL and token = ?', token_string])
            env["oauth.token"]   = token
            env["oauth.version"] = 2
            strategies << :oauth20_token
            strategies << :token
          end

        elsif oauth1_verify(request) do |request_proxy|
            client_application = ClientApplication.find_by_key(request_proxy.consumer_key)
            env["oauth.client_application_candidate"] = client_application

            # Store this temporarily in client_application object for use in request token generation
            client_application.token_callback_url = request_proxy.oauth_callback if request_proxy.oauth_callback
            oauth_token = nil

            if request_proxy.token
              oauth_token = client_application.tokens.first(:conditions => { :token => request_proxy.token })
              if oauth_token.respond_to?(:provided_oauth_verifier=)
                oauth_token.provided_oauth_verifier = request_proxy.oauth_verifier
              end
              env["oauth.token_candidate"] = oauth_token
            end
            # return the token secret and the consumer secret<commit_msg>Only consider valid OAuth 1 tokens<commit_after>require "rack"
require "rack/request"
require "oauth"
require "oauth/request_proxy/rack_request"

module OAuth
  module Rack

    # An OAuth 1.0a filter to be used together with the oauth-plugin for rails.T
    # This is still experimental
    #
    # Add it as middleware to your config/application.rb:
    #
    # require 'oauth/rack/oauth_filter'
    # config.middleware.use OAuth::Rack::OAuthFilter

    class OAuthFilter
      def initialize(app)
        @app = app
      end

      def call(env)
        request = ::Rack::Request.new(env)
        env["oauth_plugin"] = true
        strategies = []
        if token_string = oauth2_token(request)
          if token = Oauth2Token.first(:conditions => ['invalidated_at IS NULL AND authorized_at IS NOT NULL and token = ?', token_string])
            env["oauth.token"]   = token
            env["oauth.version"] = 2
            strategies << :oauth20_token
            strategies << :token
          end

        elsif oauth1_verify(request) do |request_proxy|
            client_application = ClientApplication.find_by_key(request_proxy.consumer_key)
            env["oauth.client_application_candidate"] = client_application

            # Store this temporarily in client_application object for use in request token generation
            client_application.token_callback_url = request_proxy.oauth_callback if request_proxy.oauth_callback
            oauth_token = nil

            if request_proxy.token
              oauth_token = client_application.tokens.first(:conditions => ['invalidated_at IS NULL AND authorized_at IS NOT NULL and token = ?', request_proxy.token])
              if oauth_token.respond_to?(:provided_oauth_verifier=)
                oauth_token.provided_oauth_verifier = request_proxy.oauth_verifier
              end
              env["oauth.token_candidate"] = oauth_token
            end
            # return the token secret and the consumer secret
{'fraction_non_alphanumeric': 0.07567567567567568, 'fraction_numerical': 0.004375804375804376, 'mean_word_length': 2.578268876611418, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3197160', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1067, 'n_words': 269}