<commit_before>require 'warden'

# Satellite warden strategy will authenticate user for a
# 'satellite' client app for the configured provider,
# which for our purposes is likely to be 'devpost'
#
module Satellite
  class WardenStrategy < Warden::Strategies::Base

    # cookies[:production_user_jwt] provided when logged in on platform app
    # env['omniauth.auth'] provided when completed omniauth callback
    #
    def valid?
      user_cookie.present? && env['omniauth.auth']
    end

    def authenticate!
      user = user_class.find_or_create_with_omniauth(env['omniauth.auth'])
      if valid_session?(user)
        success! user
      else
        Rails.logger.info "Warden failure!!! #{env['omniauth.auth'].inspect}" if defined?(Rails)
        fail!("Could not log in")
      end
    end

    private

    def cookies
      env['action_dispatch.cookies']
    end

    def user_cookie
      @user_cookie ||= Satellite::UserCookie.new(cookies)
    end

    def user_decoder
      @user_decoder ||= Satellite::JWT::UserDecoder.new(user_cookie.to_cookie)
    end

    def valid_session?(user)
      user && user.provider_key?(cookie_provider_key)
    end

    def cookie_provider_key
      [Satellite.configuration.provider, user_decoder.user_uid]
    end

    def user_class
      Satellite.configuration.user_class
    end
  end
end

Warden::Strategies.add(:satellite, Satellite::WardenStrategy)

Warden::Manager.serialize_into_session do |user|
  [user.class.name, user.id]
end
<commit_msg>renamed JWT::UserDecoder<commit_after>require 'warden'

# Satellite warden strategy will authenticate user for a
# 'satellite' client app for the configured provider,
# which for our purposes is likely to be 'devpost'
#
module Satellite
  class WardenStrategy < Warden::Strategies::Base

    # cookies[:production_user_jwt] provided when logged in on platform app
    # env['omniauth.auth'] provided when completed omniauth callback
    #
    def valid?
      user_cookie.present? && env['omniauth.auth']
    end

    def authenticate!
      user = user_class.find_or_create_with_omniauth(env['omniauth.auth'])
      if valid_session?(user)
        success! user
      else
        Rails.logger.info "Warden failure!!! #{env['omniauth.auth'].inspect}" if defined?(Rails)
        fail!("Could not log in")
      end
    end

    private

    def cookies
      env['action_dispatch.cookies']
    end

    def user_cookie
      @user_cookie ||= Satellite::UserCookie.new(cookies)
    end

    def user_decoder
      @user_decoder ||= Satellite::JWTUserDecoder.new(user_cookie.to_cookie)
    end

    def valid_session?(user)
      user && user.provider_key?(cookie_provider_key)
    end

    def cookie_provider_key
      [Satellite.configuration.provider, user_decoder.user_uid]
    end

    def user_class
      Satellite.configuration.user_class
    end
  end
end

Warden::Strategies.add(:satellite, Satellite::WardenStrategy)

Warden::Manager.serialize_into_session do |user|
  [user.class.name, user.id]
end

{'fraction_non_alphanumeric': 0.09365659249418798, 'fraction_numerical': 0.0, 'mean_word_length': 3.482142857142857, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7369241', 'n_tokens_mistral': 966, 'n_tokens_neox': 913, 'n_words': 221}