feat: support third-party application to login with SAML rather than only Casdoor itself (#350)

Signed-off-by: Yixiang Zhao <seriouszyx@foxmail.com>
This commit is contained in:
Yixiang Zhao
2021-12-10 00:23:04 +08:00
committed by GitHub
parent 70a550d8bc
commit b73b9a65b6
5 changed files with 63 additions and 16 deletions

View File

@ -15,6 +15,7 @@
package controllers
import (
"encoding/base64"
"encoding/json"
"fmt"
"net/url"
@ -369,8 +370,14 @@ func (c *ApiController) GetSamlLogin() {
func (c *ApiController) HandleSamlLogin() {
relayState := c.Input().Get("RelayState")
samlResponse := c.Input().Get("SAMLResponse")
decode, err := base64.StdEncoding.DecodeString(relayState)
if err != nil {
c.ResponseError(err.Error())
}
slice := strings.Split(string(decode), "&")
relayState = url.QueryEscape(relayState)
samlResponse = url.QueryEscape(samlResponse)
targetUrl := fmt.Sprintf("%s/callback/saml?replayState=%s&samlResponse=%s",
beego.AppConfig.String("samlRequestOrigin"), relayState, samlResponse)
targetUrl := fmt.Sprintf("%s?relayState=%s&samlResponse=%s",
slice[4], relayState, samlResponse)
c.Redirect(targetUrl, 303)
}