<commit_before>require 'omniauth-oauth2'
require 'rest-client'
require 'multi_json'

module OmniAuth
  module Strategies
    class Gimmebar < OmniAuth::Strategies::OAuth2
      def initialize(app, client_id, client_secret, options = {})
        @callback = options.fetch(:callback_url, nil)
        super(app, client_id, client_secret, options)
      end

      option :client_options, {
        :site           => 'https://gimmebar.com',
        :authorize_url  => '/authorize',
        :token_url      => '/api/v1/auth/token/access'
      }

      option :provider_ignores_state, true

      option :uid_field, "user_id"

      uid { request.params[options.uid_field.to_s] }

      def request_phase
        redirect client.auth_code.authorize_url({
          :redirect_uri => callback_url,
          :token => request_token
        }.merge(options.authorize_params))
      end

      def request_token
        # We need to get a request token before redirecting the user
        response = RestClient.post(
          "https://gimmebar.com/api/v1/auth/token/request",
          :client_id => client.id,
          :client_secret => client.secret,
          :type => 'app'
        )
        MultiJson.load(response)["request_token"]
      end

      def callback_url
        @callback || super
      end
    end
  end
end<commit_msg>Retrieve additional data about the user<commit_after>require 'omniauth-oauth2'
require 'rest-client'
require 'multi_json'

module OmniAuth
  module Strategies
    class Gimmebar < OmniAuth::Strategies::OAuth2
      def initialize(app, client_id, client_secret, options = {})
        @callback = options.fetch(:callback_url, nil)
        super(app, client_id, client_secret, options)
      end

      option :client_options, {
        :site           => 'https://gimmebar.com',
        :authorize_url  => '/authorize',
        :token_url      => '/api/v1/auth/token/access'
      }

      option :provider_ignores_state, true

      uid { raw_info["id"] }

      info do
        {
          'email' => raw_info["email"],
          'name' => raw_info["name"]
        }
      end

      extra do
        { :raw_info => raw_info }
      end

      def request_phase
        redirect client.auth_code.authorize_url({
          :redirect_uri => callback_url,
          :token => request_token
        }.merge(options.authorize_params))
      end

      def request_token
        # We need to get a request token before redirecting the user
        response = RestClient.post(
          "https://gimmebar.com/api/v1/auth/token/request",
          :client_id => client.id,
          :client_secret => client.secret,
          :type => 'app'
        )
        MultiJson.load(response)["request_token"]
      end

      def callback_url
        @callback || super
      end

      def raw_info
        @raw_info ||= access_token.get(
          "https://gimmebar.com/api/v1/users/#{access_token.params["user_id"]}?_extension[]=authed_user",
        ).parsed
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10907881609577652, 'fraction_numerical': 0.0029930162953109413, 'mean_word_length': 2.1763463569165786, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, 'https://': 5, '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': '5377447', 'n_tokens_mistral': 925, 'n_tokens_neox': 900, 'n_words': 188}