Class: OpenID::Store::MongoidStore

Inherits:
Interface
  • Object
show all
Defined in:
lib/openid/store/mongoid_store.rb

Overview

OpenID Store class which uses Mongoid to store and access Association and Nonce data.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cleanupObject

Note:

Not run as part of the normal process, must be run manually if desired.

Cleans up any expired Nonce and Association data



15
16
17
18
# File 'lib/openid/store/mongoid_store.rb', line 15

def self.cleanup
  cleanup_nonces
  cleanup_associations
end

Instance Method Details

#get_association(server_url, handle = nil) ⇒ Object

Note:

Called internally by OpenID.

Gets the Association for the given server url and handle.

Parameters:

  • server_url (String)

    URL of the server making the request

  • handle (defaults to: nil)

    The handle associated with the Association



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/openid/store/mongoid_store.rb', line 24

def get_association(server_url, handle = nil)
  assns = query_associations(server_url, handle)

  assns.reverse.each do |assn|
    a = assn.from_record
    if a.expires_in == 0
      assn.destroy
    else
      return a
    end
  end if assns.any?

  return nil
end

#remove_association(server_url, handle) ⇒ Object



65
66
67
68
69
# File 'lib/openid/store/mongoid_store.rb', line 65

def remove_association(server_url, handle)
  Association.where(:server_url => server_url, :handle => handle).each do |assoc|
    assoc.destroy
  end
end

#store_association(server_url, assoc) ⇒ Object

Note:

Called internally by OpenID.

Stores an Association for the given server url and OpenID::Association.

Parameters:

  • server_url (String)

    URL of the server making the request

  • assoc (OpenID::Association)

    Object to use to create Association



43
44
45
46
47
48
49
50
51
52
# File 'lib/openid/store/mongoid_store.rb', line 43

def store_association(server_url, assoc)
  remove_association(server_url, assoc.handle)

  Association.create(:server_url => server_url,
                     :handle     => assoc.handle,
                     :secret     => Moped::BSON::Binary.new(:generic, assoc.secret),
                     :issued     => assoc.issued.to_i,
                     :lifetime   => assoc.lifetime,
                     :assoc_type => assoc.assoc_type)
end

#use_nonce(server_url, timestamp, salt) ⇒ Object

Creates a Nonce for the given information.

Parameters:

  • server_url (String)

    URL of the server making the request

  • timestamp

    Time the Nonce was created.

  • salt (String)

    Random string to uniquify Nonces.

Returns:

  • True if the given nonce has not been created before and the timestamp is valid, False otherwise.



59
60
61
62
63
# File 'lib/openid/store/mongoid_store.rb', line 59

def use_nonce(server_url, timestamp, salt)
  return false if any_nonces?(server_url, timestamp, salt) || delta_beyond_skew?(timestamp)
  Nonce.create(:server_url => server_url, :timestamp => timestamp, :salt => salt)
  return true
end