<commit_before>module Kracken
  class Authenticator
    attr_reader :auth_hash, :user_class

    ## Factory Methods

    # Login the user with their credentails. Used for proxying the
    # authentication to the auth server, normally from a mobile app
    def self.user_with_credentials(email, password)
      response = Kracken::CredentialAuthenticator.new.fetch(email, password)
      response ? self.new(response).to_app_user : nil
    end

    # Login the user with an auth token. Used for API authentication for the
    # public APIs
    def self.user_with_token(token)
      response = Kracken::TokenAuthenticator.new.fetch(token)
      response ? self.new(response).to_app_user : nil
    end

    def initialize(response)
      @auth_hash = create_auth_hash(response)
    end

    # Convert this Factory to a User object per the host app.
    def to_app_user
      raise MissingUIDError unless auth_hash.uid
      Kracken.config.user_class.find_or_create_from_auth_hash(auth_hash)
    end

    private

    def create_auth_hash(response_hash)
      Hashie::Mash.new({
        provider: response_hash['provider'],
        uid: response_hash['uid'],
        info: response_hash['info']
      })
    end

  end
end<commit_msg>Include credential details in the `auth_hash` when creating a user<commit_after>module Kracken
  class Authenticator
    attr_reader :auth_hash, :user_class

    ## Factory Methods

    # Login the user with their credentails. Used for proxying the
    # authentication to the auth server, normally from a mobile app
    def self.user_with_credentials(email, password)
      response = Kracken::CredentialAuthenticator.new.fetch(email, password)
      response ? self.new(response).to_app_user : nil
    end

    # Login the user with an auth token. Used for API authentication for the
    # public APIs
    def self.user_with_token(token)
      response = Kracken::TokenAuthenticator.new.fetch(token)
      response ? self.new(response).to_app_user : nil
    end

    def initialize(response)
      @auth_hash = create_auth_hash(response)
    end

    # Convert this Factory to a User object per the host app.
    def to_app_user
      raise MissingUIDError unless auth_hash.uid
      Kracken.config.user_class.find_or_create_from_auth_hash(auth_hash)
    end

    private

    def create_auth_hash(response_hash)
      Hashie::Mash.new({
        provider: response_hash['provider'],
        uid: response_hash['uid'],
        info: response_hash['info'],
        credentials: response_hash['credentials'],
      })
    end

  end
end
{'fraction_non_alphanumeric': 0.07290448343079922, 'fraction_numerical': 0.0, 'mean_word_length': 3.248344370860927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3684861', 'n_tokens_mistral': 766, 'n_tokens_neox': 742, 'n_words': 208}