(r *http.Request, level string)
| 73 | } |
| 74 | |
| 75 | func basicAuth(r *http.Request, level string) (username string, err error) { |
| 76 | |
| 77 | err = errors.New("User authentication failed") |
| 78 | |
| 79 | auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2) |
| 80 | |
| 81 | if len(auth) != 2 || auth[0] != "Basic" { |
| 82 | return |
| 83 | } |
| 84 | |
| 85 | payload, _ := base64.StdEncoding.DecodeString(auth[1]) |
| 86 | pair := strings.SplitN(string(payload), ":", 2) |
| 87 | |
| 88 | username = pair[0] |
| 89 | var password = pair[1] |
| 90 | |
| 91 | token, err := authentication.UserAuthentication(username, password) |
| 92 | |
| 93 | if err != nil { |
| 94 | return |
| 95 | } |
| 96 | |
| 97 | err = checkAuthorizationLevel(token, level) |
| 98 | |
| 99 | return |
| 100 | } |
| 101 | |
| 102 | func urlAuth(r *http.Request, requestType string) (err error) { |
| 103 | var level, token string |
no test coverage detected