<commit_before>require 'omniauth-oauth2'

module OmniAuth
  module Strategies
    class Bitbucket2 < OmniAuth::Strategies::OAuth2
      DEFAULT_RESPONSE_TYPE = 'token'
      DEFAULT_GRANT = 'authorization_code'

      option :name, 'bitbucket'

      option :client_options, {
        :site => 'https://bitbucket.org',
        :authorize_url => 'https://bitbucket.org/site/oauth2/authorize',
        :token_url => 'https://bitbucket.org/site/oauth2/access_token'
      }

      def authorize_params
        super.tap do |params|
          params[:response_type] ||= DEFAULT_RESPONSE_TYPE
          params[:client_id] = client.id
        end
      end

      def token_params
        super.tap do |params|
          params[:grant_type] ||= DEFAULT_GRANT
          params[:client_id] = client.id
          params[:client_secret] = client.secret
        end
      end

      uid { raw_info['uuid'].to_s }

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

      extra do
        {:raw_info => raw_info}
      end

      def raw_info
        access_token.options[:mode] = :query
        @raw_info ||= access_token.get('user').parsed
      end
    end
  end
end

OmniAuth.config.add_camelization 'bitbucket', 'Bitbucket2'
<commit_msg>user info & emails<commit_after>require 'omniauth-oauth2'

module OmniAuth
  module Strategies
    class Bitbucket2 < OmniAuth::Strategies::OAuth2
      DEFAULT_RESPONSE_TYPE = 'token'
      DEFAULT_GRANT = 'authorization_code'

      option :name, 'bitbucket'

      option :client_options, {
        :site => 'https://bitbucket.org',
        :authorize_url => 'https://bitbucket.org/site/oauth2/authorize',
        :token_url => 'https://bitbucket.org/site/oauth2/access_token'
      }

      def request_phase
        super
      end

      def authorize_params
        super.tap do |params|
          params[:response_type] ||= DEFAULT_RESPONSE_TYPE
          params[:client_id] = client.id
        end
      end

      def token_params
        super.tap do |params|
          params[:grant_type] ||= DEFAULT_GRANT
          params[:client_id] = client.id
          params[:client_secret] = client.secret
        end
      end

      uid { raw_info['uuid'].to_s }

      info do
        {
          'nickname' => raw_info['username'],
          'email' => primary_email,
          'name' => raw_info['display_name'],
          'image' => raw_info['links']['avatar']['href'],
        }
      end

      extra do
        {:raw_info => raw_info, :all_emails => emails}
      end

      def raw_info
        access_token.options[:mode] = :query
        @raw_info ||= access_token.get('user').parsed
      end

      def primary_email
        primary = emails.find{ |i| i['is_primary'] && i['is_confirmed'] }
        primary && primary['email'] || nil
      end

      def emails
        access_token.options[:mode] = :query
        email_response = access_token.get('user/emails').parsed
        @emails ||= email_response && email_response['values'] || nil
      end
    end
  end
end

OmniAuth.config.add_camelization 'bitbucket', 'Bitbucket2'

{'fraction_non_alphanumeric': 0.11681643132220795, 'fraction_numerical': 0.0038510911424903724, 'mean_word_length': 2.233402489626556, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 6, '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': '5884238', 'n_tokens_mistral': 995, 'n_tokens_neox': 963, 'n_words': 182}