ecloud oauth2认证

dev_SaaS
guange 6 years ago
parent befe1381c5
commit defbbe1c84

@ -17,9 +17,10 @@ class EcloudController < ApplicationController
def trustie_login
end
CLIENT_ID = 'e5da9855f89bc724a335d100cb63cf02a03a592bd3151bbc84acf7b2e222ddb8'
CLIENT_SECRET = '4f2f291fac1d3dae338c18a3e3544814be5a1c4ade9e72d62f45ceab914c89f5'
CLIENT_ID = '1022'
CLIENT_SECRET = '2112037a-6d7a-432b-9081-feb1153d8668'
ROOT_URl = 'http://localhost:3000'
SERVER_URL = "https://221.176.54.92:9081/restful/services/"
def oschina_login
# 根据session看看有没有存access_token去刷新下。
@ -29,6 +30,10 @@ class EcloudController < ApplicationController
redirect_to "https://gitee.com/oauth/authorize?client_id=#{CLIENT_ID}&redirect_uri=#{ROOT_URl}/oschina/login_cb&response_type=code"
end
# 企业开通
# ecordercode 唯一标志一个企业的订购关系
def bs_new
@ -91,16 +96,12 @@ class EcloudController < ApplicationController
def ecloud_login_callback
#获取code
#
#
logger.debug params
url = "https://221.176.54.92:9081/restful/services/oauth2/authorization?grant_type=authorization_code" +
logger.info "oauth2 login_callback: #{params}"
url = "#{SERVER_URL}/oauth2/authorization?grant_type=authorization_code" +
"&client_id=#{CLIENT_ID}&scope=&redirect_uri=&code=#{params[:code]}"
# url = "https://gitee.com/oauth/token?grant_type=authorization_code"+
# "&code=#{params[:code]}&client_id=#{CLIENT_ID}&redirect_uri=#{ROOT_URl}/oschina/login_cb&client_secret=#{CLIENT_SECRET}"
res = post(url)
logger.debug res
logger.info "oauth2 authorization resp: #{res}"
body = decode(res)
#{"access_token":"21a80f20ff736b54aecd002b60210943","token_type":"bearer","expires_in":86400,"refresh_token":"be92e2c137a8c6dd22f0d8c4a622b3aeceb054087a95d293130f04ec60fd3e3f","scope":"user_info","created_at":1542684088}
@ -110,17 +111,18 @@ class EcloudController < ApplicationController
#获取此用户信息
# res = get("https://gitee.com/api/v5/user?access_token=#{body["access_token"]}")
res = get("https://221.176.54.92:9081/restful/services/user/info?access_token=#{body["access_token"]}&userid=%7bUSERID%7d")
logger.debug res
res = get("#{SERVER_URL}/user/info?access_token={ACCESS_TOKEN}&userid={USERID}")
logger.info "oauth2 get user info: #{res}"
info = decode(res)
user = User.find_by_oschina_user_id(info["id"])
unless user
user = User.create_with_oschina!(info)
end
@current_user = user
# 同步用户
# info = decode(res)
#
# user = User.find_by_oschina_user_id(info["id"])
# unless user
# user = User.create_with_oschina!(info)
# end
#
# @current_user = user
render :index
end

@ -33,7 +33,7 @@ RedmineApp::Application.routes.draw do ## oauth相关
match 'oauth/cb', to: 'oauth#test_callback', :via => :get
match 'oauth/userinfo', to: 'oauth#get_userinfo', :via => :get
match 'ecloud/ecloud_login_callback', to: 'ecloud#ecloud_login_callback', :via => :get
match 'ecloud/ecloud_login', to: 'ecloud#ecloud_login_callback', :via => :get
match 'ecloud/bs_new', to: 'ecloud#bs_new', :via => :post
match 'ecloud/bs_edit', to: 'ecloud#bs_edit', :via => :post
match 'ecloud/ps_new', to: 'ecloud#ps_new', :via => :post

Loading…
Cancel
Save