Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Fix bugs encountered with Auth flow #37

Merged
merged 2 commits into from
Dec 4, 2019
Merged

Fix bugs encountered with Auth flow #37

merged 2 commits into from
Dec 4, 2019

Conversation

schottra
Copy link
Contributor

@schottra schottra commented Dec 4, 2019

We weren't setting CORS headers for the /me endpoint. In attempting to implement that, I found myself duplicating some code and went in search for a better way to handle CORS.

I removed the custom CORS logic and replaced it with a simpler middleware-based implementation from gorilla. It still pulls in the allowed headers and origins lists, but implements the origin matching in a way that is compatible with credentials and specifying multiple domains.

This will also apply CORS to all future endpoints we add, since it's done at the level above the mux.

katrogan
katrogan previously approved these changes Dec 4, 2019
Copy link
Contributor

@katrogan katrogan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making this change!

// Enable CORS if necessary on the gateway mux by adding a handler for all OPTIONS requests.
if cfg.Security.AllowCors {
globPattern := server.GetGlobPattern()
decorator := auth.GetCorsDecorator(ctx, cfg.Security.AllowedOrigins, cfg.Security.AllowedHeaders)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does it handle OPTIONS calls if this bit is removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Cors middleware wraps the mux and processes all requests, passing them through to the mux unless there's an error of some sort (disallowed origin, etc). It will handle all OPTIONS requests and add the appropriate headers based on the configuration.

@schottra schottra merged commit ab750a8 into master Dec 4, 2019
eapolinario pushed a commit that referenced this pull request Sep 6, 2023
* Simplifying our CORS implementation to use a global middleware

* Making content-type header a default, using a less strict version constraint for gorilla
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants