Commit 54025fc
Changed files (5)
app
models
views
db
migrate
app/models/token.rb
@@ -1,16 +1,18 @@
+# frozen_string_literal: true
+
class Token < ApplicationRecord
enum token_type: { access: 0, refresh: 1 }
belongs_to :authorization
belongs_to :subject, polymorphic: true
belongs_to :audience, polymorphic: true
- scope :expired, ->{ where('expired_at < ?', Time.now) }
- scope :revoked, ->{ where('revoked_at < ?', Time.now) }
+ scope :expired, -> { where('expired_at < ?', Time.now) }
+ scope :revoked, -> { where('revoked_at < ?', Time.now) }
after_initialize do |x|
x.uuid = SecureRandom.uuid if x.uuid.nil?
if x.expired_at.nil?
- x.expired_at = access? ? 1.hour.from_now : 1.day.from_now
+ x.expired_at = access? ? 1.hour.from_now : 1.day.from_now
end
end
app/views/oauths/bad_request.json.jbuilder
@@ -1,1 +1,3 @@
+# frozen_string_literal: true
+
json.error t('.invalid_request')
app/views/oauths/token.json.jbuilder
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
json.access_token @access_token.to_jwt
json.token_type 'Bearer'
json.expires_in 1.hour.to_i
db/migrate/20180909173139_create_tokens.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class CreateTokens < ActiveRecord::Migration[5.2]
def change
create_table :tokens do |t|