This commit is contained in:
parent
075fd9670f
commit
859ed0015f
|
@ -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
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#coding=utf-8
|
||||||
|
#
|
||||||
class OschinaController < ApplicationController
|
class OschinaController < ApplicationController
|
||||||
|
|
||||||
CLIENT_ID = 'e5da9855f89bc724a335d100cb63cf02a03a592bd3151bbc84acf7b2e222ddb8'
|
CLIENT_ID = 'e5da9855f89bc724a335d100cb63cf02a03a592bd3151bbc84acf7b2e222ddb8'
|
||||||
|
|
Loading…
Reference in New Issue