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

feat: provide the request info in Context for all Storage() callbacks #325

Closed
muir opened this issue Mar 13, 2023 · 3 comments
Closed

feat: provide the request info in Context for all Storage() callbacks #325

muir opened this issue Mar 13, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@muir
Copy link
Contributor

muir commented Mar 13, 2023

Is your feature request related to a problem? Please describe.

Several times I've needed information that is present in the original http.Request when implementing op.Storage APIs or even Client APIS.

Describe the solution you'd like

Capture the original http.Request and request body and put them into context.Context so any op.Storage API can get that information if it needs it.

Describe alternatives you've considered

Change all of the op.Storage APIs to include additional information.

@muhlemmer
Copy link
Collaborator

I'm not sure if we would want something like this, so I will take it up with my colleagues. Meanwhile. you could easily achieve this by creating your own middleware:

type ReqKeyT int

const ReqKey ReqKeyT = 0

func requestToCtx(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		ctx := context.WithValue(r.Context(), ReqKey, r)
		next.ServeHTTP(w, r.WithContext(ctx))
	})
}
	handler, err := op.NewOpenIDProvider(issuer, config, storage,
		//we must explicitly allow the use of the http issuer
		op.WithAllowInsecure(),
		// as an example on how to customize an endpoint this will change the authorization_endpoint from /authorize to /auth
		op.WithCustomAuthEndpoint(op.NewEndpoint("auth")),
		op.WithHttpInterceptors(requestToCtx),
	)

@hifabienne hifabienne moved this to 🧐 Investigating in Product Management Mar 17, 2023
@muhlemmer
Copy link
Collaborator

Closing as this is the alternative solution to #326. Also discussed in discord.

@github-project-automation github-project-automation bot moved this from 🧐 Investigating to ✅ Done in Product Management Apr 22, 2023
@muir
Copy link
Contributor Author

muir commented Apr 24, 2023

@muhlemmer There are other situations where the entire request is useful. In my implementation, I'm passing the request through to the storage layer (using Context) for /authorize, /revoke, and /end_session. We can solve those individually, but it seems like a general solution is warranted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants