Class: Doorkeeper::AccessToken
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Doorkeeper::AccessToken
- Includes:
- Models::MongoMapper::Revocable, Models::Mongoid::Revocable, Models::Mongoid::Scopes, Models::Scopes, OAuth::Helpers, MongoMapper::Document, Mongoid::Document, Mongoid::Timestamps
- Defined in:
- lib/doorkeeper/models/access_token.rb,
lib/doorkeeper/models/mongoid2/access_token.rb,
lib/doorkeeper/models/mongoid3/access_token.rb,
lib/doorkeeper/models/couchbase/access_token.rb,
lib/doorkeeper/models/mongo_mapper/access_token.rb,
lib/doorkeeper/models/active_record/access_token.rb
Instance Attribute Summary collapse
-
#use_refresh_token ⇒ Object
Returns the value of attribute use_refresh_token.
Class Method Summary collapse
- .authenticate(token) ⇒ Object
- .by_refresh_token(refresh_token) ⇒ Object
- .create_indexes ⇒ Object
- .last ⇒ Object
- .matching_token_for(application, resource_owner_or_id, scopes) ⇒ Object
- .revoke_all_for(application_id, resource_owner) ⇒ Object
- .where_owner_id(id) ⇒ Object
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #expires_in ⇒ Object
- #refresh_token ⇒ Object
- #scopes=(value) ⇒ Object
- #token_type ⇒ Object
- #use_refresh_token? ⇒ Boolean
Methods included from Models::MongoMapper::Revocable
Methods included from Models::Mongoid::Scopes
Methods included from Models::Mongoid::Revocable
Methods included from Models::Scopes
Instance Attribute Details
#use_refresh_token ⇒ Object
Returns the value of attribute use_refresh_token.
14 15 16 |
# File 'lib/doorkeeper/models/access_token.rb', line 14 def use_refresh_token @use_refresh_token end |
Class Method Details
.authenticate(token) ⇒ Object
26 27 28 |
# File 'lib/doorkeeper/models/access_token.rb', line 26 def self.authenticate(token) find(token) end |
.by_refresh_token(refresh_token) ⇒ Object
34 35 36 |
# File 'lib/doorkeeper/models/access_token.rb', line 34 def self.by_refresh_token(refresh_token) by_refresh_token({:key => refresh_token}) end |
.create_indexes ⇒ Object
46 47 48 49 |
# File 'lib/doorkeeper/models/mongo_mapper/access_token.rb', line 46 def self.create_indexes ensure_index :token, :unique => true ensure_index [[:refresh_token, 1]], :unique => true, :sparse => true end |
.last ⇒ Object
22 23 24 |
# File 'lib/doorkeeper/models/mongo_mapper/access_token.rb', line 22 def self.last self.sort(:created_at).last end |
.matching_token_for(application, resource_owner_or_id, scopes) ⇒ Object
42 43 44 45 46 |
# File 'lib/doorkeeper/models/access_token.rb', line 42 def self.matching_token_for(application, resource_owner_or_id, scopes) resource_owner_id = resource_owner_or_id.respond_to?(:to_key) ? resource_owner_or_id.id : resource_owner_or_id token = (application, resource_owner_id) token if token end |
.revoke_all_for(application_id, resource_owner) ⇒ Object
38 39 40 |
# File 'lib/doorkeeper/models/access_token.rb', line 38 def self.revoke_all_for(application_id, resource_owner) AccessToken.find(*by_application_id_and_resource_owner_id({:key => [application_id, resource_owner]})).delete end |
.where_owner_id(id) ⇒ Object
30 31 32 |
# File 'lib/doorkeeper/models/access_token.rb', line 30 def self.where_owner_id(id) Application.find(*by_resource_owner_id({:key => id})) end |
Instance Method Details
#as_json(options = {}) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/doorkeeper/models/access_token.rb', line 56 def as_json(={}) { :resource_owner_id => self.resource_owner_id, :scopes => self.scopes, :expires_in_seconds => self.expires_at - Time.now, :application => { :uid => self.application.id } } end |
#expires_in ⇒ Object
21 22 23 |
# File 'lib/doorkeeper/models/access_token.rb', line 21 def expires_in 30 end |
#refresh_token ⇒ Object
37 38 39 |
# File 'lib/doorkeeper/models/mongoid2/access_token.rb', line 37 def refresh_token self[:refresh_token] end |
#scopes=(value) ⇒ Object
18 19 20 |
# File 'lib/doorkeeper/models/mongo_mapper/access_token.rb', line 18 def scopes=(value) write_attribute :scopes, value if value.present? end |
#token_type ⇒ Object
48 49 50 |
# File 'lib/doorkeeper/models/access_token.rb', line 48 def token_type "bearer" end |
#use_refresh_token? ⇒ Boolean
52 53 54 |
# File 'lib/doorkeeper/models/access_token.rb', line 52 def use_refresh_token? self.use_refresh_token end |