27 lines
461 B
Go
27 lines
461 B
Go
package service
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type TokenSource struct {
|
|
}
|
|
|
|
func NewTokenSource() TokenSource {
|
|
return TokenSource{}
|
|
}
|
|
|
|
func (s TokenSource) CreateApplicationToken() (string, error) {
|
|
cryptoRand := make([]byte, 128) //nolint:mnd
|
|
_, err := rand.Read(cryptoRand)
|
|
if err != nil {
|
|
return "", errors.WithMessage(err, "crypto/rand read")
|
|
}
|
|
random := hex.EncodeToString(cryptoRand)
|
|
|
|
return random, nil
|
|
}
|