Skip to content

Instantly share code, notes, and snippets.

@collinvandyck
Created September 12, 2012 21:49
Show Gist options
  • Select an option

  • Save collinvandyck/3710185 to your computer and use it in GitHub Desktop.

Select an option

Save collinvandyck/3710185 to your computer and use it in GitHub Desktop.
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