-
Notifications
You must be signed in to change notification settings - Fork 394
/
claims.go
41 lines (31 loc) · 888 Bytes
/
claims.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package consoleauth
import (
"bytes"
"encoding/json"
"time"
"storj.io/common/uuid"
)
// TODO: change to JWT or Macaroon based auth
// Claims represents data signed by server and used for authentication.
type Claims struct {
ID uuid.UUID `json:"id"`
Email string `json:"email,omitempty"`
Expiration time.Time `json:"expires,omitempty"`
}
// JSON returns json representation of Claims.
func (c *Claims) JSON() ([]byte, error) {
buffer := bytes.NewBuffer(nil)
err := json.NewEncoder(buffer).Encode(c)
return buffer.Bytes(), err
}
// FromJSON returns Claims instance, parsed from JSON.
func FromJSON(data []byte) (*Claims, error) {
claims := new(Claims)
err := json.NewDecoder(bytes.NewReader(data)).Decode(claims)
if err != nil {
return nil, err
}
return claims, nil
}