This commit is contained in:
guange 2018-11-22 11:15:49 +08:00
parent 075fd9670f
commit 859ed0015f
2 changed files with 24 additions and 2 deletions

View File

@ -1,6 +1,6 @@
class OauthController < ApplicationController class OauthController < ApplicationController
before_filter :user_setup before_filter :user_setup
before_filter :require_login, only: [:authorize] before_filter :require_login, only: [:authorize, :token]
# 客户端申请认证的URI包含以下参数 # 客户端申请认证的URI包含以下参数
# #
@ -76,9 +76,29 @@ class OauthController < ApplicationController
# refresh_token表示更新令牌用来获取下一次的访问令牌可选项。 # refresh_token表示更新令牌用来获取下一次的访问令牌可选项。
# scope表示权限范围如果与客户端申请的范围一致此项可省略。 # scope表示权限范围如果与客户端申请的范围一致此项可省略。
def token def token
if params[:grant_type] == 'authorization_code' if params[:grant_type] == 'authorization_code'
raise "code必传" unless params["code"]
raise "client_id必传" unless params["client_id"]
raise "client_secret必传" unless params["client_secret"]
raise "code错误或已超时" unless Oauth.code_valid?(params["code"])
oauth = Oauth.auth(params["code"], params["client_id"], params["client_secret"])
raise "认证不通过" unless oauth
## 生成 token
#
oauth.gen_token(User.current.id)
{
access_token: oauth.access_token,
token_type: 'bearer',
expires_in: oauth.token_expires_in,
refresh_token: oauth.refresh_token
}
end end
end end

View File

@ -1,3 +1,5 @@
#coding=utf-8
#
class OschinaController < ApplicationController class OschinaController < ApplicationController
CLIENT_ID = 'e5da9855f89bc724a335d100cb63cf02a03a592bd3151bbc84acf7b2e222ddb8' CLIENT_ID = 'e5da9855f89bc724a335d100cb63cf02a03a592bd3151bbc84acf7b2e222ddb8'