Skip to content

Commit

Permalink
feat: add external url for casdoor #603
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed Dec 15, 2024
1 parent 6f90464 commit 835349c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
7 changes: 6 additions & 1 deletion api/user/casdoor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
7 changes: 7 additions & 0 deletions docs/guide/config-casdoor.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
6 changes: 6 additions & 0 deletions docs/zh_CN/guide/config-casdoor.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
6 changes: 6 additions & 0 deletions docs/zh_TW/guide/config-casdoor.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
11 changes: 2 additions & 9 deletions settings/casdoor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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{}

0 comments on commit 835349c

Please sign in to comment.