mirror of
https://github.com/documize/community.git
synced 2025-08-08 06:55:28 +02:00
auth with cas
This commit is contained in:
parent
8c99977fc9
commit
8c2df6178d
150 changed files with 43682 additions and 24175 deletions
65
vendor/gopkg.in/cas.v2/logout_request.go
generated
vendored
Normal file
65
vendor/gopkg.in/cas.v2/logout_request.go
generated
vendored
Normal file
|
@ -0,0 +1,65 @@
|
|||
package cas
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/xml"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Represents the XML CAS Single Log Out Request data
|
||||
type logoutRequest struct {
|
||||
XMLName xml.Name `xml:"urn:oasis:names:tc:SAML:2.0:protocol LogoutRequest"`
|
||||
Version string `xml:"Version,attr"`
|
||||
IssueInstant time.Time `xml:"-"`
|
||||
RawIssueInstant string `xml:"IssueInstant,attr"`
|
||||
ID string `xml:"ID,attr"`
|
||||
NameID string `xml:"urn:oasis:names:tc:SAML:2.0:assertion NameID"`
|
||||
SessionIndex string `xml:"SessionIndex"`
|
||||
}
|
||||
|
||||
func parseLogoutRequest(data []byte) (*logoutRequest, error) {
|
||||
l := &logoutRequest{}
|
||||
if err := xml.Unmarshal(data, &l); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
t, err := time.Parse(time.RFC1123Z, l.RawIssueInstant)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
l.IssueInstant = t
|
||||
l.NameID = strings.TrimSpace(l.NameID)
|
||||
l.SessionIndex = strings.TrimSpace(l.SessionIndex)
|
||||
|
||||
return l, nil
|
||||
}
|
||||
|
||||
func newLogoutRequestId() string {
|
||||
const alphabet = "abcdef0123456789"
|
||||
|
||||
// generate 64 character string
|
||||
bytes := make([]byte, 64)
|
||||
rand.Read(bytes)
|
||||
|
||||
for k, v := range bytes {
|
||||
bytes[k] = alphabet[v%byte(len(alphabet))]
|
||||
}
|
||||
|
||||
return string(bytes)
|
||||
}
|
||||
|
||||
func xmlLogoutRequest(ticket string) ([]byte, error) {
|
||||
l := &logoutRequest{
|
||||
Version: "2.0",
|
||||
IssueInstant: time.Now().UTC(),
|
||||
ID: newLogoutRequestId(),
|
||||
NameID: "@NOT_USED@",
|
||||
SessionIndex: ticket,
|
||||
}
|
||||
|
||||
l.RawIssueInstant = l.IssueInstant.Format(time.RFC1123Z)
|
||||
|
||||
return xml.MarshalIndent(l, "", " ")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue