Skip to content

Commit

Permalink
Store license token in LicenseInfo (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
anjalshireesh authored Jun 12, 2024
1 parent 51764ab commit f61fd5c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions licverifier/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type LicenseVerifier struct {

// LicenseInfo holds customer metadata present in the license key.
type LicenseInfo struct {
LicenseToken string // License token
LicenseID string // Unique id of the license
Email string // Email of the license key requestor
Organization string // Subnet organization name
Expand Down Expand Up @@ -115,7 +116,7 @@ func NewLicenseVerifier(pemBytes []byte) (*LicenseVerifier, error) {

// toLicenseInfo extracts LicenseInfo from claims. It returns an error if any of
// the claim values are invalid.
func toLicenseInfo(token jwt.Token) (LicenseInfo, error) {
func toLicenseInfo(license string, token jwt.Token) (LicenseInfo, error) {
claims, err := token.AsMap(context.Background())
if err != nil {
return LicenseInfo{}, err
Expand Down Expand Up @@ -158,6 +159,7 @@ func toLicenseInfo(token jwt.Token) (LicenseInfo, error) {
isTrial, _ := claims[trial].(bool)

return LicenseInfo{
LicenseToken: license,
LicenseID: licID,
Email: token.Subject(),
Organization: orgName,
Expand All @@ -180,5 +182,5 @@ func (lv *LicenseVerifier) Verify(license string, options ...jwt.ParseOption) (L
return LicenseInfo{}, fmt.Errorf("failed to verify license: %s", err)
}

return toLicenseInfo(token)
return toLicenseInfo(license, token)
}

0 comments on commit f61fd5c

Please sign in to comment.