Guest User

Untitled

a guest
Oct 18th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. func (r *Request) SetBasicAuth(username, password string) {
  2. 507 s := username + ":" + password
  3. 508 r.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(s)))
  4. 509 }
  5.  
  6. //This is in the standard lib, printed it for you. I then call this on the daemon end.
  7.  
  8. username, password := decode(request.Header.Get("Authorization"))
  9.  
  10. //which calls this next function
  11.  
  12. func decode(tmpAuth string) (username string, password string) {
  13. tmpAuthArray := strings.Split(tmpAuth, " ")
  14.  
  15. authValues , error := base64.StdEncoding.DecodeString(tmpAuthArray[1])
  16. printError("ERROR: Failed to decode encoded auth settings in allocate list request.", error)
  17.  
  18. authValuesArray := strings.Split(string(authValues), ":")
  19. username = authValuesArray[0]
  20. password = authValuesArray[1]
  21.  
  22. return
  23. }
Add Comment
Please, Sign In to add comment