Sha256: 7b928ffd1350bb88115f52c6ceb3451db3526aef6d99c10342b5292f6f4e121d

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

module Passport
  module Oauth
    module Record
      def self.included(base)
        base.extend ClassMethods
        base.send :include, InstanceMethods
      end
      
      module ClassMethods
        # this gives you the final key and secret that we will store in the database
        def find_or_create_token
          hash = token_class.access(
            :token          => request_token,
            :secret         => request_secret,
            :oauth_verifier => verifier,
            :callback_url   => callback_url
          )
          if token.respond_to?(:find_by_key_or_token)
            token = token_class.find_by_key_or_token(hash[:key], hash[:token])
          end
          token ||= token_class.new(hash)
          token
        end
        
        def store(record)
          session[:auth_attributes] = record.attributes.reject! do |k, v|
            v.blank? || !record.respond_to?(k)
          end if record.respond_to?(:attributes)
        end
        
        # restore attributes
        def restore(record)
          record.attributes = session.delete(:auth_attributes) if record.respond_to?(:attributes)
        end
      end
      
      module InstanceMethods
        
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
passport-0.1.1 lib/passport/oauth/protocol/record.rb