forked from xinsnake/go-http-digest-auth-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
www_authenticate.go
79 lines (65 loc) · 1.91 KB
/
www_authenticate.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package digest_auth_client
import (
"regexp"
"strings"
)
type wwwAuthenticate struct {
Algorithm string // unquoted
Domain string // quoted
Nonce string // quoted
Opaque string // quoted
Qop string // quoted
Realm string // quoted
Stale bool // unquoted
Charset string // quoted
Userhash bool // quoted
}
func newWwwAuthenticate(s string) *wwwAuthenticate {
var wa = wwwAuthenticate{}
algorithmRegex := regexp.MustCompile(`algorithm="([^ ,]+)"`)
algorithmMatch := algorithmRegex.FindStringSubmatch(s)
if algorithmMatch != nil {
wa.Algorithm = algorithmMatch[1]
}
domainRegex := regexp.MustCompile(`domain="(.+?)"`)
domainMatch := domainRegex.FindStringSubmatch(s)
if domainMatch != nil {
wa.Domain = domainMatch[1]
}
nonceRegex := regexp.MustCompile(`nonce="(.+?)"`)
nonceMatch := nonceRegex.FindStringSubmatch(s)
if nonceMatch != nil {
wa.Nonce = nonceMatch[1]
}
opaqueRegex := regexp.MustCompile(`opaque="(.+?)"`)
opaqueMatch := opaqueRegex.FindStringSubmatch(s)
if opaqueMatch != nil {
wa.Opaque = opaqueMatch[1]
}
qopRegex := regexp.MustCompile(`qop="(.+?)"`)
qopMatch := qopRegex.FindStringSubmatch(s)
if qopMatch != nil {
wa.Qop = qopMatch[1]
}
realmRegex := regexp.MustCompile(`realm="(.+?)"`)
realmMatch := realmRegex.FindStringSubmatch(s)
if realmMatch != nil {
wa.Realm = realmMatch[1]
}
staleRegex := regexp.MustCompile(`stale=([^ ,])"`)
staleMatch := staleRegex.FindStringSubmatch(s)
if staleMatch != nil {
wa.Stale = (strings.ToLower(staleMatch[1]) == "true")
}
charsetRegex := regexp.MustCompile(`charset="(.+?)"`)
charsetMatch := charsetRegex.FindStringSubmatch(s)
if charsetMatch != nil {
wa.Charset = charsetMatch[1]
}
userhashRegex := regexp.MustCompile(`userhash=([^ ,])"`)
userhashMatch := userhashRegex.FindStringSubmatch(s)
if userhashMatch != nil {
wa.Userhash = (strings.ToLower(userhashMatch[1]) == "true")
}
return &wa
}