Skip to content

fix: remove refresh oauth logic on OIDC login #8950

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

Merged
merged 5 commits into from
Aug 8, 2023

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Aug 7, 2023

apiKeyMiddlewareOptional was being used to log out users if they convert to OIDC. However this logic was also doing an OIDC refresh if the original token expired. This was a mistake. That logic should just pull the APIKey for logging out, and do not do anything else.

To fix this I just refactored ExtractAPIKey into a helper func to call and not do the refresh logic.

A unit test was added that fails on main and is now fixed. It matches the behavior of the reports.

Closes #8537

@@ -142,6 +142,56 @@ func ExtractAPIKeyMW(cfg ExtractAPIKeyConfig) func(http.Handler) http.Handler {
}
}

func APIKeyFromRequest(ctx context.Context, db database.Store, sessionTokenFunc func(r *http.Request) string, r *http.Request) (*database.APIKey, codersdk.Response, bool) {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of this could you have just added a field to the opts struct above "NoRefreshToken" or something?

Copy link
Member Author

Choose a reason for hiding this comment

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

I could yea, but I didn't want to keep using that middleware for just the key extraction. It could evolve more features overtime and the use case in this situation doesn't ever change/evovle.

@Emyrk Emyrk merged commit 5339a31 into main Aug 8, 2023
@Emyrk Emyrk deleted the stevenmasley/token_not_active branch August 8, 2023 15:05
@github-actions github-actions bot locked and limited conversation to collaborators Aug 8, 2023
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.

"Token not active" error when logging in via OIDC
2 participants