-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclaims.go
More file actions
37 lines (27 loc) · 856 Bytes
/
claims.go
File metadata and controls
37 lines (27 loc) · 856 Bytes
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
// Copyright (C) 2021 Creditor Corp. Group.
// See LICENSE for copying information.
package goauth
import (
"bytes"
"encoding/json"
"github.com/zeebo/errs"
)
// ClaimsError is an error class for Claims errors.
var ClaimsError = errs.Class("admin auth claims error")
// Claims represents data signed by server and used for authentication.
type Claims map[string]string
// 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(), ClaimsError.Wrap(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, ClaimsError.Wrap(err)
}
return claims, nil
}