1
package utils
2

3
import (
4
    "encoding/base64"
5
    "strings"
6
)
7

8
// BasicAuthEncode encodes a key-secret pair to be used in a HTTP Basic Authentication
9
//      strategy (HTTP Request Header)
10 1
func BasicAuthEncode(key, secret string) string {
11 1
    token := key + ":" + secret
12 1
    return base64.StdEncoding.EncodeToString([]byte(token))
13
}
14

15
// BasicAuthDecode decodes a key-secret pair from a token string, originally used in a
16
//      HTTP Basic Authentication strategy (HTTP Request Header)
17 1
func BasicAuthDecode(token string) (string, string) {
18 1
    bytes, _ := base64.StdEncoding.DecodeString(token)
19 1
    values := strings.Split(string(bytes), ":")
20 1
    return values[0], values[1]
21
}

Read our documentation on viewing source code .

Loading