Sha256: 5eeb45940ad4905a4d695272f40c28481d54d5cfc78fc261a0491542998425f7

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

require 'digest/sha1'
require 'omniauth/core'

module OmniAuth
  module Strategies
    class Password
      include OmniAuth::Strategy
      
      def initialize(app, secret = 'changethisappsecret', options = {})
        @options = options
        @secret = secret
        super(app, :password)
      end

      attr_reader :secret
      
      def request_phase
        return fail!(:missing_information) unless request[:identifier] && request[:password]
        return fail!(:password_mismatch) if request[:password_confirmation] && request[:password_confirmation] != '' && request[:password] != request[:password_confirmation]
        env['REQUEST_METHOD'] = 'GET'
        env['PATH_INFO'] = request.path + '/callback'
        request['auth'] = auth_hash(encrypt(request[:identifier], request[:password]))
        @app.call(env)
      end
      
      def auth_hash(crypted_password)
        OmniAuth::Utils.deep_merge(super(), {
          'uid' => crypted_password,
          'user_info' => {
            @options[:identifier_key] => request[:identifier]
          }
        })
      end
      
      def callback_phase
        @app.call(env)
      end
      
      def encrypt(identifier, password)
        Digest::SHA1.hexdigest([identifier, password, secret].join('::'))
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
oa-core-0.1.1 lib/omniauth/strategies/password.rb
oa-core-0.1.0 lib/omniauth/strategies/password.rb
oa-core-0.0.5 lib/omniauth/strategies/password.rb
oa-core-0.0.4 lib/omniauth/strategies/password.rb