-
Notifications
You must be signed in to change notification settings - Fork 0
feat: oidc middleware #2
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
Conversation
middlewarex/oidc.go
Outdated
| func OIDC(ctx context.Context, issuer string, opts ...OIDCMiddlewareOption) func(next http.Handler) http.Handler { | ||
| provider, err := oidc.NewProvider(ctx, issuer) | ||
| if err != nil { | ||
| panic(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we panic here or do it like
https://github.com/HGV/iam-api/commit/870634b0f39e3794edc49b43abf0dac9578ecbde
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would either panic or return the middleware as a struct and an error in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://go.dev/doc/effective_go#panic it’s acceptable to panic() in this case because the OIDC middleware can’t set itself up. But this could also be seen from another perspective: What if it isn’t a critical error for the app if the OIDC middleware fails. For example, it could fall back to another authentication mechanism. Just hypothesizing. In that case it would be better to return the error during setup instead of panic(). What’s your take on this?
middlewarex/oidc.go
Outdated
| return | ||
| } | ||
|
|
||
| ctx := contextWithIDToken(r.Context(), idToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two r.Context() calls could be stored in a variable instead.
middlewarex/oidc.go
Outdated
|
|
||
| return func(next http.Handler) http.Handler { | ||
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| authHeader := r.Header.Get("Authorization") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I would pass that function result directly to validateAuthHeader instead of creating a dedicated variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a mandatory audience check to avoid potential security issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. The middleware is well structured and also allows to pass custom HTTP handlers for authorization errors.
692f5f9 to
64e265d
Compare
64e265d to
928545e
Compare
No description provided.