Make access tokens belong to user not client app

This commit is contained in:
theworldbright 2015-07-08 16:46:31 +09:00 committed by theworldbright
parent 3fc0f64c56
commit 7c75eb5901
6 changed files with 13 additions and 9 deletions

View file

@ -1,9 +1,7 @@
class OAuthApplication < ActiveRecord::Base class OAuthApplication < ActiveRecord::Base
belongs_to :user belongs_to :user
validates :user_id, presence: true
validates :client_id, presence: true, uniqueness: true validates :client_id, presence: true, uniqueness: true
validates :client_secret, presence: true validates :client_secret, presence: true
has_many :tokens
end end

View file

@ -1,5 +1,5 @@
class Token < ActiveRecord::Base class Token < ActiveRecord::Base
belongs_to :o_auth_application belongs_to :user
before_validation :setup, on: :create before_validation :setup, on: :create

View file

@ -77,6 +77,7 @@ class User < ActiveRecord::Base
has_many :reports has_many :reports
has_many :o_auth_applications has_many :o_auth_applications
has_many :tokens
before_save :guard_unconfirmed_email, before_save :guard_unconfirmed_email,
:save_person! :save_person!

View file

@ -4,6 +4,8 @@ class CreateOAuthApplications < ActiveRecord::Migration
t.belongs_to :user, index: true t.belongs_to :user, index: true
t.string :client_id t.string :client_id
t.string :client_secret t.string :client_secret
t.string :name
t.string :redirect_uris
t.timestamps null: false t.timestamps null: false
end end

View file

@ -1,9 +1,10 @@
class CreateTokens < ActiveRecord::Migration class CreateTokens < ActiveRecord::Migration
def self.up def self.up
create_table :tokens do |t| create_table :tokens do |t|
t.belongs_to :o_auth_application, index: true t.belongs_to :user, index: true
t.string :token t.string :token
t.datetime :expires_at t.datetime :expires_at
t.timestamps null: false t.timestamps null: false
end end
end end

View file

@ -240,6 +240,8 @@ ActiveRecord::Schema.define(version: 20151003142048) do
t.integer "user_id", limit: 4 t.integer "user_id", limit: 4
t.string "client_id", limit: 255 t.string "client_id", limit: 255
t.string "client_secret", 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 "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end 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 add_index "tags", ["name"], name: "index_tags_on_name", unique: true, length: {"name"=>191}, using: :btree
create_table "tokens", force: :cascade do |t| create_table "tokens", force: :cascade do |t|
t.integer "o_auth_application_id", limit: 4 t.integer "user_id", limit: 4
t.string "token", limit: 255 t.string "token", limit: 255
t.datetime "expires_at" t.datetime "expires_at"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end 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| create_table "user_preferences", force: :cascade do |t|
t.string "email_type", limit: 255 t.string "email_type", limit: 255