Method: Rack::OAuth2::Server::AccessToken.create_token_for

Defined in:
lib/rack/oauth2/models/access_token.rb

.create_token_for(client, scope, identity = nil, expires = nil) ⇒ Object

Creates a new AccessToken for the given client and scope.



37
38
39
40
41
42
43
44
45
46
# File 'lib/rack/oauth2/models/access_token.rb', line 37

def create_token_for(client, scope, identity = nil, expires = nil)
  expires_at = Time.now.to_i + expires if expires && expires != 0
  token = { :_id=>Server.secure_random, :scope=>scope,
            :client_id=>client.id, :created_at=>Time.now.to_i,
            :expires_at=>expires_at, :revoked=>nil }
  token[:identity] = identity if identity
  collection.insert token
  Client.collection.update({ :_id=>client.id }, { :$inc=>{ :tokens_granted=>1 } })
  Server.new_instance self, token
end