forked from Gitlink/forgeplus
fix: set redirect_uri
This commit is contained in:
parent
f732b0374c
commit
1153bd5ab6
|
@ -40,13 +40,9 @@ class Oauth::EducoderController < Oauth::BaseController
|
|||
begin
|
||||
code = params['code'].to_s.strip
|
||||
tip_exception("code不能为空") if code.blank?
|
||||
redirect_uri = [request.protocol, request.host_with_port, '/api/auth/educoder/callback'].join('')
|
||||
Rails.logger.info redirect_uri
|
||||
redirect_uri = 'https://testforgeplus.trustie.net/api/auth/educoder/callback'
|
||||
Rails.logger.info redirect_uri
|
||||
|
||||
new_user = false
|
||||
result = EducoderOauth::Service.access_token(code, redirect_uri)
|
||||
result = EducoderOauth::Service.access_token(code)
|
||||
result = EducoderOauth::Service.user_info(result[:access_token])
|
||||
|
||||
# 存在该用户
|
||||
|
|
|
@ -44,7 +44,7 @@ class SettingsController < ApplicationController
|
|||
@third_party = []
|
||||
@third_party << {
|
||||
name: 'educoder',
|
||||
url: EducoderOauth.oauth_url([request.protocol, request.host_with_port, '/api/auth/educoder/callback'].join(''))
|
||||
url: EducoderOauth.oauth_url
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module EducoderOauth
|
||||
class << self
|
||||
attr_accessor :client_id, :client_secret, :base_url
|
||||
attr_accessor :client_id, :client_secret, :base_url, :redirect_uri
|
||||
|
||||
def logger
|
||||
@_logger ||= STDOUT
|
||||
|
@ -10,7 +10,7 @@ module EducoderOauth
|
|||
@_logger = l
|
||||
end
|
||||
|
||||
def oauth_url(redirect_uri)
|
||||
def oauth_url
|
||||
"#{base_url}/oauth2?call_url=/oauth/authorize?client_id=#{client_id}&redirect_uri=#{URI.encode_www_form_component(redirect_uri)}&response_type=code"
|
||||
end
|
||||
|
||||
|
|
|
@ -19,12 +19,12 @@ module EducoderOauth::Service
|
|||
end
|
||||
end
|
||||
|
||||
def access_token(code, redirect_uri)
|
||||
def access_token(code)
|
||||
begin
|
||||
Rails.logger.info("[EducoderOauth] [code] #{code} ")
|
||||
Rails.logger.info("[EducoderOauth] [redirect_uri] #{redirect_uri} ")
|
||||
Rails.logger.info("[EducoderOauth] [redirect_uri] #{EducoderOauth.redirect_uri} ")
|
||||
client = OAuth2::Client.new(EducoderOauth.client_id, EducoderOauth.client_secret, site: EducoderOauth.base_url)
|
||||
result = client.auth_code.get_token(code, redirect_uri: redirect_uri).to_hash
|
||||
result = client.auth_code.get_token(code, redirect_uri: EducoderOauth.redirect_uri).to_hash
|
||||
return result
|
||||
rescue Exception => e
|
||||
raise Educoder::TipException.new(e.message)
|
||||
|
|
|
@ -47,6 +47,7 @@ default: &default
|
|||
client_id: 'e9ce4d5ba1698d6f7d01d8ee2959776c7a6d743ebe94da2341e288fd2fbf60aa'
|
||||
client_secret: '6ff84dd75eddd859c5bd0e7a791b58bc5ad1ba4fbb30bc9db37cb0baf9f33012'
|
||||
base_url: 'https://test-data.educoder.net'
|
||||
redirect_uri: 'https://testforgeplus.trustie.net/api/auth/educoder/callback'
|
||||
|
||||
gitea:
|
||||
access_key_id: 'root'
|
||||
|
|
|
@ -13,3 +13,4 @@ end
|
|||
EducoderOauth.client_id = oauth_config['client_id']
|
||||
EducoderOauth.client_secret = oauth_config['client_secret']
|
||||
EducoderOauth.base_url = oauth_config['base_url']
|
||||
EducoderOauth.redirect_uri = oauth_config['redirect_uri']
|
||||
|
|
Loading…
Reference in New Issue