File: provision.go

package info (click to toggle)
golang-github-smallstep-cli 0.15.16%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,404 kB
  • sloc: sh: 512; makefile: 99
file content (36 lines) | stat: -rw-r--r-- 1,235 bytes parent folder | download | duplicates (2)
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)
}