Make access tokens belong to user not client app
This commit is contained in:
parent
3fc0f64c56
commit
7c75eb5901
6 changed files with 13 additions and 9 deletions
|
|
@ -1,9 +1,7 @@
|
|||
class OAuthApplication < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
|
||||
validates :user_id, presence: true
|
||||
validates :client_id, presence: true, uniqueness: true
|
||||
validates :client_secret, presence: true
|
||||
|
||||
has_many :tokens
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class Token < ActiveRecord::Base
|
||||
belongs_to :o_auth_application
|
||||
belongs_to :user
|
||||
|
||||
before_validation :setup, on: :create
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ class User < ActiveRecord::Base
|
|||
has_many :reports
|
||||
|
||||
has_many :o_auth_applications
|
||||
has_many :tokens
|
||||
|
||||
before_save :guard_unconfirmed_email,
|
||||
:save_person!
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ class CreateOAuthApplications < ActiveRecord::Migration
|
|||
t.belongs_to :user, index: true
|
||||
t.string :client_id
|
||||
t.string :client_secret
|
||||
t.string :name
|
||||
t.string :redirect_uris
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
class CreateTokens < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :tokens do |t|
|
||||
t.belongs_to :o_auth_application, index: true
|
||||
t.belongs_to :user, index: true
|
||||
t.string :token
|
||||
t.datetime :expires_at
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
|
|
|
|||
12
db/schema.rb
12
db/schema.rb
|
|
@ -240,6 +240,8 @@ ActiveRecord::Schema.define(version: 20151003142048) do
|
|||
t.integer "user_id", limit: 4
|
||||
t.string "client_id", limit: 255
|
||||
t.string "client_secret", limit: 255
|
||||
t.string "name", limit: 255
|
||||
t.string "redirect_uris", limit: 255
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
|
@ -539,14 +541,14 @@ ActiveRecord::Schema.define(version: 20151003142048) do
|
|||
add_index "tags", ["name"], name: "index_tags_on_name", unique: true, length: {"name"=>191}, using: :btree
|
||||
|
||||
create_table "tokens", force: :cascade do |t|
|
||||
t.integer "o_auth_application_id", limit: 4
|
||||
t.string "token", limit: 255
|
||||
t.integer "user_id", limit: 4
|
||||
t.string "token", limit: 255
|
||||
t.datetime "expires_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "tokens", ["o_auth_application_id"], name: "index_tokens_on_o_auth_application_id", using: :btree
|
||||
add_index "tokens", ["user_id"], name: "index_tokens_on_user_id", using: :btree
|
||||
|
||||
create_table "user_preferences", force: :cascade do |t|
|
||||
t.string "email_type", limit: 255
|
||||
|
|
|
|||
Loading…
Reference in a new issue