-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsicas.go
44 lines (35 loc) · 976 Bytes
/
sicas.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
package gouncer
import (
"net/http"
"regexp"
)
const (
sicasPattern = "(?i)^Sicas\\s+([a-z0-9+-_=]+)$"
)
func (creds *Credentials) ParseSicasAuth(authHeader string) (bool, []string) {
rxp := regexp.MustCompile(sicasPattern)
// Check if Authorization header matches
if match := rxp.FindStringSubmatch(authHeader); match != nil {
// Base64Url decode matching string
if decoded, err := creds.DecodeBase64(match[1]); err == nil {
// Split decoded string at colon
if segs, err := creds.SplitBasicAuth(decoded); err == nil {
return true, segs
}
}
}
return false, nil
}
type SicasResponse struct {
Status int
Reason string
Success bool
}
func (creds *Credentials) sicasValidate(host string, uuid string, captcha string) (SicasResponse, error) {
httpRes, err := http.Get(host + "/validate/" + uuid + "?string=" + captcha)
var jsonDoc SicasResponse
if err == nil {
err = DecodeJsonRequest(httpRes.Body, &jsonDoc)
}
return jsonDoc, err
}