-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate alist with casdoor (#1453)
* feat: integrate alist with casdoor * fix: casdoor as an option for login Co-authored-by: wenxuan70 <[email protected]>
- Loading branch information
Showing
13 changed files
with
449 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package bootstrap | ||
|
||
import ( | ||
"github.com/Xhofe/alist/conf" | ||
"github.com/casdoor/casdoor-go-sdk/casdoorsdk" | ||
log "github.com/sirupsen/logrus" | ||
"strings" | ||
) | ||
|
||
type AuthConfig struct { | ||
OrganizationName string `json:"organization_name"` | ||
ApplicationName string `json:"application_name"` | ||
Endpoint string `json:"endpoint"` | ||
ClientId string `json:"client_id"` | ||
ClientSecret string `json:"client_secret"` | ||
JwtPublicKey string `json:"jwt_public_key"` | ||
} | ||
|
||
// InitAuth init auth | ||
func InitAuth() { | ||
log.Infof("init auth...") | ||
enableCasdoor := conf.GetBool("Enable Casdoor") | ||
if !enableCasdoor { | ||
return | ||
} | ||
auth := readAuthConfig() | ||
if !CheckAuthConfig(auth) { | ||
panic("invalid auth config") | ||
} | ||
casdoorsdk.InitConfig(strings.TrimRight(auth.Endpoint, "/"), auth.ClientId, auth.ClientSecret, auth.JwtPublicKey, auth.OrganizationName, auth.ApplicationName) | ||
} | ||
|
||
func readAuthConfig() AuthConfig { | ||
return AuthConfig{ | ||
OrganizationName: conf.GetStr("Casdoor Organization name"), | ||
ApplicationName: conf.GetStr("Casdoor Application name"), | ||
Endpoint: conf.GetStr("Casdoor Endpoint"), | ||
ClientId: conf.GetStr("Casdoor Client id"), | ||
ClientSecret: conf.GetStr("Casdoor Client secret"), | ||
JwtPublicKey: conf.GetStr("Casdoor Jwt Public Key"), | ||
} | ||
} | ||
|
||
func CheckAuthConfig(authConfig AuthConfig) bool { | ||
return authConfig.Endpoint != "" && | ||
authConfig.ClientId != "" && | ||
authConfig.ClientSecret != "" && | ||
authConfig.OrganizationName != "" && | ||
authConfig.ApplicationName != "" && | ||
authConfig.JwtPublicKey != "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.