以下似乎完成了我的要求:
type Logout struct {
SP *samlsp.Middleware
}
func (l *Logout) ServeHTTP(w http.ResponseWriter, r *http.Request) {
//Get the JWT information
session, err := l.SP.Session.GetSession(r)
if err != nil {
WebErrorWarn("error get signouturl session: "+err.Error(), http.StatusForbidden, w)
return
}
//Get the JWT information part 2
attr := session.(samlsp.JWTSessionClaims)
if err != nil {
WebErrorWarn("error get signouturl session claims: "+err.Error(), http.StatusForbidden, w)
return
}
//use this as the name for the logout request
url, err := l.SP.ServiceProvider.MakeRedirectLogoutRequest(attr.Subject, "")
if err != nil {
WebErrorWarn("error get signouturl: "+err.Error(), http.StatusInternalServerError, w)
return
}
//delete the session token from teh browser
err = l.SP.Session.DeleteSession(w, r)
if err != nil {
WebErrorWarn("error get signouturl: "+err.Error(), http.StatusInternalServerError, w)
return
}
//redirect to the IDP Single log out URLwith the SAMLRequests for logout embedded
http.Redirect(w, r, url.String(), http.StatusFound)
}
我创建自己的注销 URL 以提供此服务
http.Handle("/logout", samlSP.RequireAccount(&Logout{samlSP}))
最后,IDP 将客户端重定向回 SLO URL,它在元数据文件中发送,并且在 crampjam/gosaml 中也默认为 /saml/slo。我只是在该 URL 上有一个处理程序,以向用户确认他们不再登录。
http.Handle("/saml/slo", &SLOHandle{})
注意/saml/slo URL 不应受到 SAML 保护,否则您将再次触发 SAML 登录。