Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oid_introspection: add SetOIDCClaims #3311

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions filters/auth/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,7 @@ func (f *grantFilter) setupToken(token *oauth2.Token, tokeninfo map[string]inter

// By piggy-backing on the OIDC token container,
// we gain downstream compatibility with the oidcClaimsQuery filter.
ctx.StateBag()[oidcClaimsCacheKey] = tokenContainer{
OAuth2Token: token,
Subject: subject,
Claims: tokeninfo,
}
SetOIDCClaims(ctx, tokeninfo)
MustafaSaber marked this conversation as resolved.
Show resolved Hide resolved

// Set the tokeninfo also in the tokeninfoCacheKey state bag, so we
// can reuse e.g. the forwardToken() filter.
Expand Down
2 changes: 2 additions & 0 deletions filters/auth/grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func newAuthProxy(t *testing.T, config *auth.OAuthConfig, routes []*eskip.Route,
fr.Register(config.NewGrantCallback())
fr.Register(config.NewGrantClaimsQuery())
fr.Register(config.NewGrantLogout())
fr.Register(auth.NewOIDCQueryClaimsFilter())

pc := proxytest.Config{
RoutingOptions: routing.Options{
Expand Down Expand Up @@ -331,6 +332,7 @@ func TestGrantFlow(t *testing.T) {
config := newGrantTestConfig(tokeninfo.URL, provider.URL)

routes := eskip.MustParse(`* -> oauthGrant()
-> oidcClaimsQuery("/:sub")
-> status(204)
-> setResponseHeader("Backend-Request-Cookie", "${request.header.Cookie}")
-> <shunt>
Expand Down
8 changes: 8 additions & 0 deletions filters/auth/oidc_introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ func NewOIDCQueryClaimsFilter() filters.Spec {
}
}

// Sets OIDC claims in the state bag.
// Intended for use with the oidcClaimsQuery filter.
AlexanderYastrebov marked this conversation as resolved.
Show resolved Hide resolved
func SetOIDCClaims(ctx filters.FilterContext, claims map[string]interface{}) {
ctx.StateBag()[oidcClaimsCacheKey] = tokenContainer{
Claims: claims,
}
}

func (spec *oidcIntrospectionSpec) Name() string {
switch spec.typ {
case checkOIDCQueryClaims:
Expand Down
Loading