Files
nomad/helper/joseutil/joseutil.go
Michael Schurter 0e22fc1a0b identity: add support for multiple identities + audiences (#18123)
Allows for multiple `identity{}` blocks for tasks along with user-specified audiences. This is a building block to allow workload identities to be used with Consul, Vault and 3rd party JWT based auth methods.

Expiration is still unimplemented and is necessary for JWTs to be used securely, so that's up next.

---------

Co-authored-by: Tim Gross <tgross@hashicorp.com>
2023-08-15 09:11:53 -07:00

24 lines
501 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package joseutil
import (
"errors"
"github.com/go-jose/go-jose/v3/jwt"
)
var ErrNoKeyID = errors.New("missing key ID header")
// KeyID returns the KeyID header for a JWT or ErrNoKeyID if a key id could not
// be found. No clue why jose makes this so awkward.
func KeyID(token *jwt.JSONWebToken) (string, error) {
for _, h := range token.Headers {
if h.KeyID != "" {
return h.KeyID, nil
}
}
return "", ErrNoKeyID
}