<commit_before>require 'omniauth'

module OmniAuth
  module Strategies
    class AppDirect < OmniAuth::Strategies::OpenID
      include OmniAuth::Strategy

      AX = {
        :email => 'http://axschema.org/contact/email',
        :name => 'http://axschema.org/namePerson',
        :nickname => 'http://axschema.org/namePerson/friendly',
        :first_name => 'http://axschema.org/namePerson/first',
        :last_name => 'http://axschema.org/namePerson/last',
        :city => 'http://axschema.org/contact/city/home',
        :state => 'http://axschema.org/contact/state/home',
        :website => 'http://axschema.org/contact/web/default',
        :image => 'http://axschema.org/media/image/aspect11', 
        :roles => 'https://www.appdirect.com/schema/user/roles'
      }

      option :name, :appdirect
      option :required, [AX[:email], AX[:name], AX[:first_name], AX[:last_name], 'email', 'fullname', AX[:roles] ]
      option :optional, [AX[:nickname], AX[:city], AX[:state], AX[:website], AX[:image], 'postcode', 'nickname']
      option :store, ::OpenID::Store::Memory.new
      option :identifier, nil
      option :identifier_param, 'openid_url'

      def identifier
        i = 'https://www.appdirect.com/openid/id'
        i = env['rack.session']['openid_url'] if env && env['rack.session'] && env['rack.session']['openid_url']
        i
      end
      
      def get_identifier
        env['rack.session']['openid_url'] || 'https://www.appdirect.com/openid/id'
      end

      def callback_phase
        return fail!(:invalid_credentials) unless openid_response && openid_response.status == :success
        super
      end

      def ax_user_info
        ax = ::OpenID::AX::FetchResponse.from_success_response(openid_response)
        super
      end
    end
  end
end

OmniAuth.config.add_camelization 'appdirect', 'AppDirect'
OmniAuth.config.add_camelization 'app_direct', 'AppDirect'
OmniAuth.config.add_camelization 'app-direct', 'AppDirect'
<commit_msg>Roles<commit_after>require 'omniauth'

module OmniAuth
  module Strategies
    class AppDirect < OmniAuth::Strategies::OpenID
      include OmniAuth::Strategy

      AX = {
        :email => 'http://axschema.org/contact/email',
        :name => 'http://axschema.org/namePerson',
        :nickname => 'http://axschema.org/namePerson/friendly',
        :first_name => 'http://axschema.org/namePerson/first',
        :last_name => 'http://axschema.org/namePerson/last',
        :city => 'http://axschema.org/contact/city/home',
        :state => 'http://axschema.org/contact/state/home',
        :website => 'http://axschema.org/contact/web/default',
        :image => 'http://axschema.org/media/image/aspect11', 
        :roles => 'https://www.appdirect.com/schema/user/roles'
      }

      attr_reader :access_token

      option :name, :appdirect
      option :required, [AX[:email], AX[:name], AX[:first_name], AX[:last_name], 'email', 'fullname', AX[:roles] ]
      option :optional, [AX[:nickname], AX[:city], AX[:state], AX[:website], AX[:image], 'postcode', 'nickname']
      option :store, ::OpenID::Store::Memory.new
      option :identifier, nil
      option :identifier_param, 'openid_url'

      def identifier
        i = 'https://www.appdirect.com/openid/id'
        i = env['rack.session']['openid_url'] if env && env['rack.session'] && env['rack.session']['openid_url']
        i
      end
      
      def get_identifier
        env['rack.session']['openid_url'] || 'https://www.appdirect.com/openid/id'
      end

      def callback_phase
        return fail!(:invalid_credentials) unless openid_response && openid_response.status == :success
        super
      end

      def ax_user_info
        ax = ::OpenID::AX::FetchResponse.from_success_response(openid_response)
        super
      end

      def get_appdirect_attr(attribute)
        openid_response.message.get_arg('http://openid.net/srv/ax/1.0', attribute)
      end

      # Parsing the roles out of the return schema. 
      # Roles might be in the value.ext4 field if there is only one, 
      # or possibly in the value.ext4.N fields if there are many. 
      # Assume the worst: check both places  and reject any nils from the result.
      def roles
        [get_appdirect_attr('value.ext4')].tap do |roles|     # Roles array starts with one value: value.ext4 (possibly nil)
          get_appdirect_attr('count.ext4').to_i.times do |i|  # Then we use the roles count to cycle through each role variable 
            roles << get_appdirect_attr("value.ext4.#{i+1}")  # And shift it into the array
          end
        end.reject {|v| !v } # remove nils 
      end

      extra do          
        { :roles => roles }
      end

    end
  end
end

OmniAuth.config.add_camelization 'appdirect', 'AppDirect'
OmniAuth.config.add_camelization 'app_direct', 'AppDirect'
OmniAuth.config.add_camelization 'app-direct', 'AppDirect'

{'fraction_non_alphanumeric': 0.14516458801881005, 'fraction_numerical': 0.00265794316090779, 'mean_word_length': 2.8763866877971473, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 24, 'https://': 6, 'lorem ipsum': 0, 'www.': 6, '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': '6597215', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1526, 'n_words': 313}