forked from smallstep/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provision.go
36 lines (32 loc) 路 1.21 KB
/
provision.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
package provision
import (
"github.com/smallstep/cli/jose"
"github.com/smallstep/cli/token"
)
// Token defines a one time use token that is intended to be exchanged
// for a newly provisioned certificate by an end entity. Token differs
// from BootstrapToken because it does not self contain networking information
// for connecting to the certificate authority or gatewayconsole.
//
// Token implements the Token interface.
type Token struct {
claims *token.Claims
}
// New returns a new unsigned One-Time-Token for authorizing a
// single request from a newly provisioned end-entity.
// The current implementation uses jwt.Token and is generated using sane defaults
// for the claims.
// See token/options.go for default claim definitions.
func New(subject string, opts ...token.Options) (*Token, error) {
o := append([]token.Options{token.WithSubject(subject)}, opts...)
c, err := token.NewClaims(o...)
if err != nil {
return nil, err
}
return &Token{claims: c}, nil
}
// SignedString implementation of the Token interface. It returns a JWT using
// the compact serialization.
func (t *Token) SignedString(sigAlg string, key interface{}) (string, error) {
return t.claims.Sign(jose.SignatureAlgorithm(sigAlg), key)
}