oidc icon indicating copy to clipboard operation
oidc copied to clipboard

Change op.tokenHandler to follow the same pattern

Open muir opened this issue 3 years ago • 1 comments

Change op.tokenHandler to follow the same pattern as the rest of the endpoint handlers inside op: provide a standard endpoint handler that uses injected data to call an exported function.

I care because I'm not using gorilla/mux and I gave up trying to get gorilla/mux to play nicely with a prefix path when used inside nchi.

With this change, this is how I'm wrapping up the endpoint handlers. I'm using nchi instead. The plethora of interfaces makes things a bit more complex, but it's not too bad and nject will filter out the transformations that aren't needed on an endpoint-by-endpoint basis.

View the change with whitespace suppressed.

                zitadel := nject.Sequence("zitadel",
                        nject.Cacheable(func() op.OpenIDProvider { return o }),
                        nject.Cacheable(func(o op.OpenIDProvider) op.Configuration { return o }),
                        nject.Cacheable(func(o op.OpenIDProvider) op.Authorizer { return o }),
                        nject.Cacheable(func(o op.OpenIDProvider) op.Exchanger { return o }),
                        nject.Cacheable(func(o op.OpenIDProvider) op.Introspector { return o }),
                        nject.Cacheable(func(o op.OpenIDProvider) op.Revoker { return o }),
                        nject.Cacheable(func(o op.OpenIDProvider) op.UserinfoProvider { return o }),
                        nject.Cacheable(func(o op.OpenIDProvider) op.SessionEnder { return o }),
                        nject.Cacheable(func(o op.OpenIDProvider) op.KeyProvider { return o.Storage() }),
                        nject.Cacheable(func(o op.OpenIDProvider) op.Signer { return o.Signer() }),
                        nject.Cacheable(func(c op.Configuration, s op.Signer) *oidc.DiscoveryConfiguration {
                                return op.CreateDiscoveryConfig(c, s)
                        }),
                )
                router.Route("/auth/oidc/op/Customer", func(router *nchi.Mux) {
                        router.Use(
                                handlers.CORS(
                                        handlers.AllowCredentials(),
                                        handlers.AllowedHeaders([]string{"authorization", "content-type"}),
                                        handlers.AllowedOriginValidator(func(_ string) bool { return true }),
                                ),
                                )
                        // List of endpoints copied from https://github.com/zitadel/oidc/blob/fca6cf94339eacb7db9b4f5fc5c9b8e66781c495/pkg/op/op.go#L64
                        router.Get("/.well-known/openid-configuration", zitadel, op.Discover)
                        router.Post("/.well-known/openid-configuration", zitadel, op.Discover)

                        router.Get(o.AuthorizationEndpoint().Relative(), zitadel, op.Authorize)
                        router.Post(o.AuthorizationEndpoint().Relative(), zitadel, op.Authorize)

                        router.Get(o.AuthorizationEndpoint().Relative()+"/callback", zitadel, op.Authorize)
                        router.Post(o.AuthorizationEndpoint().Relative()+"/callback", zitadel, op.Authorize)

                        router.Get(o.TokenEndpoint().Relative(), zitadel, op.Exchange)
                        router.Post(o.TokenEndpoint().Relative(), zitadel, op.Exchange)

                        router.Get(o.IntrospectionEndpoint().Relative(), zitadel, op.Introspect)
                        router.Post(o.IntrospectionEndpoint().Relative(), zitadel, op.Introspect)

                        router.Get(o.UserinfoEndpoint().Relative(), zitadel, op.Userinfo)
                        router.Post(o.UserinfoEndpoint().Relative(), zitadel, op.Userinfo)

                        router.Get(o.RevocationEndpoint().Relative(), zitadel, op.Revoke)
                        router.Post(o.RevocationEndpoint().Relative(), zitadel, op.Revoke)

                        router.Get(o.EndSessionEndpoint().Relative(), zitadel, op.EndSession)
                        router.Post(o.EndSessionEndpoint().Relative(), zitadel, op.EndSession)

                        router.Get(o.KeysEndpoint().Relative(), zitadel, op.Keys)
                        router.Post(o.KeysEndpoint().Relative(), zitadel, op.Keys)
                })

muir avatar Sep 09 '22 01:09 muir

Codecov Report

Merging #210 (39c53f0) into main (0e7949b) will decrease coverage by 0.02%. The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #210      +/-   ##
==========================================
- Coverage   12.47%   12.44%   -0.03%     
==========================================
  Files          41       41              
  Lines        3263     3270       +7     
==========================================
  Hits          407      407              
- Misses       2845     2852       +7     
  Partials       11       11              
Impacted Files Coverage Δ
pkg/op/token_request.go 0.00% <0.00%> (ø)
pkg/oidc/userinfo.go 39.62% <0.00%> (-0.51%) :arrow_down:
pkg/oidc/introspection.go 0.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov[bot] avatar Sep 09 '22 01:09 codecov[bot]

:tada: This PR is included in version 1.9.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Sep 30 '22 05:09 github-actions[bot]