Class: Rack::OAuth2::Server::Issuer

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/oauth2/models/issuer.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_idObject (readonly) Also known as: identifier

The unique identifier of this Issuer. String or URI



35
36
37
# File 'lib/rack/oauth2/models/issuer.rb', line 35

def _id
  @_id
end

#hmac_secretObject (readonly)

shared secret used for verifying HMAC signatures



38
39
40
# File 'lib/rack/oauth2/models/issuer.rb', line 38

def hmac_secret
  @hmac_secret
end

#notesObject (readonly)

notes about this Issuer



42
43
44
# File 'lib/rack/oauth2/models/issuer.rb', line 42

def notes
  @notes
end

#public_keyObject (readonly)

public key used for verifying RSA signatures



40
41
42
# File 'lib/rack/oauth2/models/issuer.rb', line 40

def public_key
  @public_key
end

Class Method Details

.collectionObject



28
29
30
31
# File 'lib/rack/oauth2/models/issuer.rb', line 28

def collection
  prefix = Server.options[:collection_prefix]
  Server.database["#{prefix}.issuers"]
end

.create(args) ⇒ Object

Create a new Issuer.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rack/oauth2/models/issuer.rb', line 15

def create(args)
  fields = {}
  [:hmac_secret, :public_key, :notes].each do |key|
    fields[key] = args[key] if args.has_key?(key)
  end
  fields[:created_at] = Time.now.to_i
  fields[:updated_at] = Time.now.to_i
  fields[:_id] = args[:identifier]
  collection.insert(fields, :safe=>true)
  Server.new_instance self, fields
end

.from_identifier(identifier) ⇒ Object

returns the Issuer object for the given identifier



10
11
12
# File 'lib/rack/oauth2/models/issuer.rb', line 10

def from_identifier(identifier)
  Server.new_instance self, collection.find_one({:_id=>identifier})
end

Instance Method Details

#update(args) ⇒ Object



45
46
47
48
49
# File 'lib/rack/oauth2/models/issuer.rb', line 45

def update(args)
  fields = [:hmac_secret, :public_key, :notes].inject({}) {|h,k| v = args[k]; h[k] = v if v; h}
  self.class.collection.update({:_id => identifier }, {:$set => fields})
  self.class.from_identifier(identifier)
end