diff --git a/app/controllers/oauth/ci4s_controller.rb b/app/controllers/oauth/ci4s_controller.rb index 7ccc444bb..543466563 100644 --- a/app/controllers/oauth/ci4s_controller.rb +++ b/app/controllers/oauth/ci4s_controller.rb @@ -2,6 +2,10 @@ class Oauth::Ci4sController < Oauth::BaseController include RegisterHelper + def oauth_url + Ci4s::Service.oauth_url(code) + end + # 需要educoder那边设置回调地址 def create begin diff --git a/app/libs/ci4s/service.rb b/app/libs/ci4s/service.rb index 57cd753b3..c67ccf5b9 100644 --- a/app/libs/ci4s/service.rb +++ b/app/libs/ci4s/service.rb @@ -23,6 +23,9 @@ module Ci4s::Service config.dig("oauth", "ci4s", "redirect_uri") end + def oauth_url + "#{base_url}/oauth/authorize?client_id=#{client_id}&redirect_uri=#{URI.encode_www_form_component(redirect_uri)}&response_type=code&grant_type=authorization_code" + end def request(method, url, params) begin diff --git a/config/routes.rb b/config/routes.rb index 6a8677322..3e9145ae7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,6 +26,7 @@ Rails.application.routes.draw do get 'auth/failure', to: 'oauth/base#auth_failure' get 'auth/cas/callback', to: 'oauth/cas#create' get 'auth/acge/callback', to: "oauth/acge#create" + get 'oauth_ci4s', to: "oauth/ci4s#oauth_url" get 'auth/ci4s/callback', to: "oauth/ci4s#create" get 'auth/acge/refer', to: "oauth/acge#refer" get 'auth/:provider/callback', to: 'oauth/callbacks#create'