Created
September 12, 2012 21:49
-
-
Save collinvandyck/3710185 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getDecodedAuthorizationHeader(headers http.Header) (aType string, aValue string, err error) { | |
| auth := strings.Split(headers.Get("Authorization"), " ") | |
| if len(auth) != 2 { | |
| return aType, aValue, errors.New("Bad auth header") | |
| } | |
| if auth[0] == "Basic" { | |
| reader := base64.NewDecoder(base64.StdEncoding, strings.NewReader(auth[1])) | |
| bytes, err := ioutil.ReadAll(reader) | |
| if err != nil { | |
| return aType, aValue, err | |
| } | |
| auth[1] = string(bytes) | |
| } | |
| return auth[0], auth[1], nil | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment