diff --git a/app/controllers/oauth_controller.rb b/app/controllers/oauth_controller.rb index 7a21b11ba..c8be77e45 100644 --- a/app/controllers/oauth_controller.rb +++ b/app/controllers/oauth_controller.rb @@ -4,7 +4,7 @@ class OauthController < ApplicationController include ApplicationHelper before_filter :user_setup - before_filter :require_login, only: [:authorize, :token] + before_filter :require_login, only: [:authorize] skip_before_filter :verify_authenticity_token, only: [:token] @@ -49,7 +49,8 @@ class OauthController < ApplicationController ## 检查通过,生成code oauth = Oauth.create!(client_id: config.client_id, client_secret: config.client_secret, - redirect_uri: config.redirect_uri + redirect_uri: config.redirect_uri, + user_id: User.current.id ) code = oauth.gen_code @@ -110,7 +111,7 @@ class OauthController < ApplicationController ## 生成 token # - oauth.gen_token(User.current.id) + oauth.gen_token oauth.reload diff --git a/app/models/oauth.rb b/app/models/oauth.rb index 163ff3e34..d00c798aa 100644 --- a/app/models/oauth.rb +++ b/app/models/oauth.rb @@ -14,7 +14,7 @@ class Oauth < ActiveRecord::Base code end - def gen_token(user_id) + def gen_token access_token = Digest::MD5.hexdigest "#{Time.now}-#{Random.new_seed}" refresh_token = Digest::MD5.hexdigest "#{Random.new_seed}-#{Time.now}-#{Random.new_seed}" @@ -22,7 +22,6 @@ class Oauth < ActiveRecord::Base refresh_token: refresh_token, token_created_at: Time.now.to_i, token_expires_in: Time.now.to_i + 24*60*60, - user_id: user_id ) end