forked from brianolson/go-openid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxrds.go
62 lines (54 loc) · 1.37 KB
/
xrds.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2010 Florian Duraffourg. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package openid
import (
"encoding/xml"
"io"
"strings"
)
type XRDSIdentifier struct {
XMLName xml.Name "Service"
Type []string
URI string
LocalID string
}
type XRD struct {
XMLName xml.Name "XRD"
Service XRDSIdentifier
}
type XRDS struct {
XMLName xml.Name "XRDS"
XRD XRD
}
// Parse a XRDS document provided through a io.Reader
// Return the OP EndPoint and, if found, the Claimed Identifier
func ParseXRDS(r io.Reader) (string, string) {
XRDS := new(XRDS)
decoder := xml.NewDecoder(r)
err := decoder.Decode(XRDS)
if err != nil {
//fmt.Printf(err.String())
return "", ""
}
XRDSI := XRDS.XRD.Service
XRDSI.URI = strings.TrimSpace(XRDSI.URI)
XRDSI.LocalID = strings.TrimSpace(XRDSI.LocalID)
//fmt.Printf("%v\n", XRDSI)
if StringTableContains(XRDSI.Type, "http://specs.openid.net/auth/2.0/server") {
//fmt.Printf("OP Identifier Element found\n")
return XRDSI.URI, ""
} else if StringTableContains(XRDSI.Type, "http://specs.openid.net/auth/2.0/signon") {
//fmt.Printf("Claimed Identifier Element found\n")
return XRDSI.URI, XRDSI.LocalID
}
return "", ""
}
func StringTableContains(t []string, s string) bool {
for _, v := range t {
if v == s {
return true
}
}
return false
}