Skip to content

Commit

Permalink
feat: app instead of audience in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
tdeshong committed Dec 3, 2024
1 parent de7203b commit 2f663f2
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

type auth struct {
appID string
audience string
app *App
client *ClientWithResponses
jwksCacheSet jwk.Set
}
Expand All @@ -29,14 +29,9 @@ func newAuth(appID string, app *App, client *ClientWithResponses) (*auth, error)
return nil, fmt.Errorf("Failed to fetch JWKS: %w", err)
}

aud, err := app.getExpectedAudienceValue()
if err != nil {
return nil, fmt.Errorf("Failed to get audience")
}

auth := auth{
appID: appID,
audience: aud,
app: app,
client: client,
jwksCacheSet: jwk.NewCachedSet(cache, url),
}
Expand Down Expand Up @@ -75,8 +70,12 @@ func (a *auth) ValidateJWT(authToken string) (string, error) {
return "", errors.New("Failed to find sub claim in JWT")
}

audience, err := a. app.getExpectedAudienceValue()
if err != nil {
return "", fmt.Errorf("Failed to get audience")
}

if !claims.VerifyAudience(a.audience, true) {
if !claims.VerifyAudience(audience, true) {
return "", errors.New("Failed audience varifiation in JWT")
}

Expand Down

0 comments on commit 2f663f2

Please sign in to comment.