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

OAuth: Refactor OAuth parameters handling to support obtaining refresh tokens for Google OAuth #58782

Merged
merged 6 commits into from Nov 18, 2022

Conversation

mgyongyosi
Copy link
Contributor

@mgyongyosi mgyongyosi commented Nov 15, 2022

What is this feature?
These changes make sure that Grafana does get a refresh token from Google OAuth each time the user logs in to Grafana using Google as an OAuth IdP. To make this happen the responsibility to specify custom query string parameters (that are sent to the authorize endpoint) have moved to the separate OAuth connectors.

This functionality is only available when the accessTokenExpirationCheck feature toggle is enabled.

Why do we need this feature?
We discovered that without the prompt=consent parameter the refresh token is only returned when the user first logs into Grafana through Google OAuth.

Who is this feature for?

Special notes for your reviewer:

* Extract access token validity check to a function
@grafanabot
Copy link
Contributor

@mgyongyosi mgyongyosi changed the title OAuth: Add ApprovalForce to AuthCodeOptions WIP OAuth: Add ApprovalForce to AuthCodeOptions Nov 16, 2022
@mgyongyosi mgyongyosi changed the title WIP OAuth: Add ApprovalForce to AuthCodeOptions [WIP]OAuth: Add ApprovalForce to AuthCodeOptions Nov 16, 2022
@grafanabot
Copy link
Contributor

@grafanabot
Copy link
Contributor

@mgyongyosi mgyongyosi force-pushed the mgyongyosi/oauth-rt-improv branch 3 times, most recently from 1bc556f to 645bc1f Compare November 17, 2022 09:36
@grafanabot
Copy link
Contributor

@mgyongyosi mgyongyosi added this to the 9.3.0 milestone Nov 17, 2022
@mgyongyosi mgyongyosi changed the title [WIP]OAuth: Add ApprovalForce to AuthCodeOptions OAuth: Refactor OAuth parameters handling to support obtaining refresh tokens for Google OAuth Nov 17, 2022
@mgyongyosi mgyongyosi self-assigned this Nov 17, 2022
@mgyongyosi mgyongyosi marked this pull request as ready for review November 17, 2022 10:14
@mgyongyosi mgyongyosi requested review from a team as code owners November 17, 2022 10:14
@mgyongyosi mgyongyosi requested review from sakjur, papagian and ying-jeanne and removed request for a team November 17, 2022 10:14
@mgyongyosi mgyongyosi removed the request for review from a team November 17, 2022 10:14
@grafanabot
Copy link
Contributor

pkg/api/login_oauth.go Outdated Show resolved Hide resolved
pkg/login/social/social.go Outdated Show resolved Hide resolved
@grafanabot
Copy link
Contributor

// FIXME: access_type is a Google OAuth2 specific thing, consider refactoring this and moving to google_oauth.go
opts := []oauth2.AuthCodeOption{oauth2.AccessTypeOffline}

var opts []oauth2.AuthCodeOption
Copy link
Contributor

Choose a reason for hiding this comment

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

With these last changes, the extra AuthCodeOptions that were added to gitlab,github and azure will be removed regardless of the feature flag.

From our discussion I think that's fine since it's not used by these providers but it's a small increase in risk compared to the previous version that we should be aware of

@grafanabot
Copy link
Contributor

Copy link
Contributor

@kalleep kalleep left a comment

Choose a reason for hiding this comment

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

LGTM

@mgyongyosi mgyongyosi merged commit 9c98314 into main Nov 18, 2022
@mgyongyosi mgyongyosi deleted the mgyongyosi/oauth-rt-improv branch November 18, 2022 09:12
grafanabot pushed a commit that referenced this pull request Nov 18, 2022
…h tokens for Google OAuth (#58782)

* Add ApprovalForce to AuthCodeOptions

* Extract access token validity check to a function

* Refactor

* Oauth: set options internally instead of exposing new function

* Align tests

* Remove unused function

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
(cherry picked from commit 9c98314)
mgyongyosi added a commit that referenced this pull request Nov 18, 2022
…ng refresh tokens for Google OAuth (#58940)

OAuth: Refactor OAuth parameters handling to support obtaining refresh tokens for Google OAuth (#58782)

* Add ApprovalForce to AuthCodeOptions

* Extract access token validity check to a function

* Refactor

* Oauth: set options internally instead of exposing new function

* Align tests

* Remove unused function

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
(cherry picked from commit 9c98314)

Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>
GuYounes pushed a commit to paul-wurth/BIXpert that referenced this pull request Feb 8, 2023
…ng refresh tokens for Google OAuth (grafana#58940)

OAuth: Refactor OAuth parameters handling to support obtaining refresh tokens for Google OAuth (grafana#58782)

* Add ApprovalForce to AuthCodeOptions

* Extract access token validity check to a function

* Refactor

* Oauth: set options internally instead of exposing new function

* Align tests

* Remove unused function

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
(cherry picked from commit 9c98314)

Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants