Skip to content

Commit dc4e1a4

Browse files
authored
Merge pull request #36 from linuxfoundation/fix/auth0-custom-domain-jwt-audience
Fix JWT audience validation for Auth0 custom domains
2 parents 2171472 + 01e28b1 commit dc4e1a4

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

charts/lfx-v2-auth-service/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ app:
138138
value: null
139139
AUTH0_AUDIENCE:
140140
value: null
141+
AUTH0_MANAGEMENT_AUDIENCE:
142+
value: null
141143
# Auth0 LFX Profile Client configuration (Regular Web Application for passwordless flows)
142144
## Required when using passwordless email linking flow
143145
AUTH0_LFX_PROFILE_CLIENT_ID:

internal/infrastructure/auth0/jwt_parser.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import (
1010
"fmt"
1111
"log/slog"
1212
"net/http"
13+
"os"
14+
"strings"
1315

16+
"github.com/linuxfoundation/lfx-v2-auth-service/pkg/constants"
1417
"github.com/linuxfoundation/lfx-v2-auth-service/pkg/errors"
1518
"github.com/linuxfoundation/lfx-v2-auth-service/pkg/httpclient"
1619
jwtparser "github.com/linuxfoundation/lfx-v2-auth-service/pkg/jwt"
@@ -122,6 +125,9 @@ func NewJWTVerificationConfig(ctx context.Context, domain string, httpClient *ht
122125

123126
expectedIssuer := fmt.Sprintf("https://%s/", domain)
124127
expectedAudience := fmt.Sprintf("https://%s/api/v2/", domain)
128+
if override := strings.TrimSpace(os.Getenv(constants.Auth0ManagementAudienceEnvKey)); override != "" {
129+
expectedAudience = override
130+
}
125131

126132
slog.InfoContext(ctx, "JWT signature verification enabled",
127133
"issuer", expectedIssuer,

pkg/constants/global.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ const (
5757
// Auth0AudienceEnvKey is the environment variable key for the Auth0 audience
5858
Auth0AudienceEnvKey = "AUTH0_AUDIENCE"
5959

60+
// Auth0ManagementAudienceEnvKey is the environment variable key for the Auth0 Management API audience override
61+
Auth0ManagementAudienceEnvKey = "AUTH0_MANAGEMENT_AUDIENCE"
62+
6063
// Auth0 LFX Profile Client configuration (Regular Web Application for passwordless flows)
6164
// Auth0LFXProfileClientIDEnvKey is the environment variable key for the LFX Profile Auth0 client ID
6265
Auth0LFXProfileClientIDEnvKey = "AUTH0_LFX_PROFILE_CLIENT_ID"

0 commit comments

Comments
 (0)