Class: SsoProvyder::AccessGrant

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/sso_provyder/access_grant.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.authenticate_with(args = {}) ⇒ Object



11
12
13
# File 'app/models/sso_provyder/access_grant.rb', line 11

def self.authenticate_with(args = {})
  where(args).first
end

.prune!Object



7
8
9
# File 'app/models/sso_provyder/access_grant.rb', line 7

def self.prune!
  delete_all(["created_at < ?", 3.days.ago])
end

Instance Method Details

#generate_tokensObject



15
16
17
# File 'app/models/sso_provyder/access_grant.rb', line 15

def generate_tokens
  self.code, self.access_token, self.refresh_token = SecureRandom.hex(16), SecureRandom.hex(16), SecureRandom.hex(16)
end

#redirect_uri_for(redirect_uri) ⇒ Object



19
20
21
22
# File 'app/models/sso_provyder/access_grant.rb', line 19

def redirect_uri_for(redirect_uri)
  redirect_uri.match(/(\?.*)$/)
  redirect_uri + "#{ !!$1 ? $1+'&' : '?' }code=#{code}&response_type=code&state=#{state}"
end

#start_expiry_period!Object

Note: This is currently configured through Devise, backed up by default value in SsoProvyder config



26
27
28
29
30
# File 'app/models/sso_provyder/access_grant.rb', line 26

def start_expiry_period!
  _expires_at = Time.now + (Devise.timeout_in || SsoProvyder.timeout_in)
  self.update_attribute(:access_token_expires_at, _expires_at)
  return self
end