Переглянути джерело

feat: add external url for casdoor #603

Jacky 4 місяців тому
батько
коміт
835349c33f

+ 6 - 1
api/user/casdoor.go

@@ -87,11 +87,16 @@ func CasdoorCallback(c *gin.Context) {
 }
 
 func GetCasdoorUri(c *gin.Context) {
-	endpoint := settings.CasdoorSettings.Endpoint
 	clientId := settings.CasdoorSettings.ClientId
 	redirectUri := settings.CasdoorSettings.RedirectUri
 	state := settings.CasdoorSettings.Application
 
+	endpoint := settings.CasdoorSettings.Endpoint
+	// feature request #603
+	if settings.CasdoorSettings.ExternalUrl != "" {
+		endpoint = settings.CasdoorSettings.ExternalUrl
+	}
+
 	if endpoint == "" || clientId == "" || redirectUri == "" || state == "" {
 		c.JSON(http.StatusOK, gin.H{
 			"uri": "",

+ 7 - 0
docs/guide/config-casdoor.md

@@ -9,6 +9,13 @@ By integrating Casdoor, Nginx UI can leverage these features to improve security
 
 This is the Endpoint of the Casdoor server. You need to make sure that Nginx UI can access this URL.
 
+## ExternalUrl
+- Type: `string`
+- Version: `>= v2.0.0-beta.42`
+
+This is the external URL of the Casdoor server. It is used to generate the redirect URI.
+If this option is not configured, the Endpoint will be used as the base URL for the redirect URI.
+
 ## ClientId
 - Type: `string`
 

+ 6 - 0
docs/zh_CN/guide/config-casdoor.md

@@ -8,6 +8,12 @@ Casdoor 是一个强大的、全面的身份认证解决方案,支持 OAuth 2.
 
 这是 Casdoor 服务器的 URL。您需要确保 Nginx UI 可以访问此 URL。
 
+## ExternalUrl
+- 类型:`string`
+- 版本: `>= v2.0.0-beta.42`
+
+这是 Casdoor 服务器的外部 URL。它用于生成重定向 URI,在不配置次选项的情况下,将使用 Endpoint 作为重定向 URI 的基本 URL。
+
 ## ClientId
 - 类型:`string`
 

+ 6 - 0
docs/zh_TW/guide/config-casdoor.md

@@ -8,6 +8,12 @@ Casdoor 是一個強大的、全面的身份認證解決方案,支持 OAuth 2.
 
 這是 Casdoor 服務器的 URL。您需要確保 Nginx UI 可以訪問此 URL。
 
+## ExternalUrl
+- 種類:`string`
+- 版本: `>= v2.0.0-beta.42`
+
+這是 Casdoor 伺服器的外部 URL。它用於生成重定向 URI,在未配置此選項的情況下,將使用 Endpoint 作為重定向 URI 的基本 URL。
+
 ## ClientId
 - 類型:`string`
 

+ 2 - 9
settings/casdoor.go

@@ -2,6 +2,7 @@ package settings
 
 type Casdoor struct {
 	Endpoint        string `json:"endpoint" protected:"true"`
+	ExternalUrl     string `json:"external_url" protected:"true"`
 	ClientId        string `json:"client_id" protected:"true"`
 	ClientSecret    string `json:"client_secret" protected:"true"`
 	CertificatePath string `json:"certificate_path" protected:"true"`
@@ -10,12 +11,4 @@ type Casdoor struct {
 	RedirectUri     string `json:"redirect_uri" protected:"true"`
 }
 
-var CasdoorSettings = &Casdoor{
-	Endpoint:        "",
-	ClientId:        "",
-	ClientSecret:    "",
-	CertificatePath: "",
-	Organization:    "",
-	Application:     "",
-	RedirectUri:     "",
-}
+var CasdoorSettings = &Casdoor{}