EncodeToken returns an opaque token that contains the given connection information and optionally the provided password.
(password string, ci blob.ConnectionInfo)
| 24 | // EncodeToken returns an opaque token that contains the given connection information |
| 25 | // and optionally the provided password. |
| 26 | func EncodeToken(password string, ci blob.ConnectionInfo) (string, error) { |
| 27 | ti := &tokenInfo{ |
| 28 | Version: "1", |
| 29 | Storage: ci, |
| 30 | Password: password, |
| 31 | } |
| 32 | |
| 33 | v, err := json.Marshal(ti) |
| 34 | if err != nil { |
| 35 | return "", errors.Wrap(err, "marshal token") |
| 36 | } |
| 37 | |
| 38 | return base64.RawURLEncoding.EncodeToString(v), nil |
| 39 | } |
| 40 | |
| 41 | // DecodeToken decodes the provided token and returns connection info and password if persisted. |
| 42 | func DecodeToken(token string) (blob.ConnectionInfo, string, error) { |
no outgoing calls