Files
tasks/common/authorization/audience_mapper.go
Travis McChesneyandGitHub e8a75c57b5 Add audience configuration and wire up to JWT audience validation (#8067)
## What changed?
An Audience configuration was added and wired into the server using
.WithAudienceGetter() so that if an audience is configured, it will be
validated against the audience in the JWT.

## Why?
The JWT audience should almost always be validated against an expected
audience value to ensure JWT validity.

## How did you test it?
- [x] built
- [x] run locally and tested manually
- [ ] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)
2025-09-02 10:50:36 -07:00

30 lines
982 B
Go

package authorization
import (
"context"
"go.temporal.io/server/common/config"
"google.golang.org/grpc"
)
// AudienceMapper is a simple implementation of JWTAudienceMapper that returns the configured audience string.
type AudienceMapper struct {
JwtAudience string
}
// Audience returns the configured audience string.
func (m *AudienceMapper) Audience(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo) string {
return m.JwtAudience
}
// NewAudienceMapper returns a JWTAudienceMapper that always returns the given audience string.
func NewAudienceMapper(audience string) JWTAudienceMapper {
return &AudienceMapper{JwtAudience: audience}
}
// GetAudienceMapperFromConfig returns a JWTAudienceMapper based on the provided Authorization config.
// Currently, it returns a static audience mapper using the Audience field.
func GetAudienceMapperFromConfig(cfg *config.Authorization) (JWTAudienceMapper, error) {
return NewAudienceMapper(cfg.Audience), nil
}