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

auth-node: refactor OAuth scope management #24743

Merged
merged 5 commits into from
Jun 11, 2024
Merged

auth-node: refactor OAuth scope management #24743

merged 5 commits into from
Jun 11, 2024

Conversation

Rugvip
Copy link
Member

@Rugvip Rugvip commented May 13, 2024

Hey, I just made a Pull Request!

This standardizes scope management across OAuth providers, and also aims to fix a couple of issues, especially providers that persist scopes. The overall goal of this is to be able to completely remove the need for bespoke auth APIs in the frontend, in particular for sign-in.

One issue that's been fixed is refreshing with scope persistence. In the current implementation the persisted scopes will always be used, which can break this client flow where a session is refreshed with requested scopes.

An issue that I'll be aiming to fix in followup usages of this is that many auth providers pass the scope option to the passport strategy. That only works if no scopes are requested by the client, because they are not merged. This aims to fix that by properly merging together required, additional, requested and granted scopes.

Will do updates for each provider in followups, so that we can get some eyes/testing of each individual update.

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

@Rugvip Rugvip requested review from a team as code owners May 13, 2024 11:38
@Rugvip Rugvip requested review from freben and vinzscam May 13, 2024 11:38
@github-actions github-actions bot added the auth label May 13, 2024
@backstage-goalie
Copy link
Contributor

backstage-goalie bot commented May 13, 2024

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage/plugin-auth-backend-module-atlassian-provider plugins/auth-backend-module-atlassian-provider minor v0.1.11-next.1
@backstage/plugin-auth-backend-module-bitbucket-provider plugins/auth-backend-module-bitbucket-provider patch v0.1.2-next.1
@backstage/plugin-auth-backend-module-github-provider plugins/auth-backend-module-github-provider patch v0.1.16-next.1
@backstage/plugin-auth-backend-module-gitlab-provider plugins/auth-backend-module-gitlab-provider patch v0.1.16-next.1
@backstage/plugin-auth-backend-module-google-provider plugins/auth-backend-module-google-provider patch v0.1.16-next.1
@backstage/plugin-auth-backend-module-microsoft-provider plugins/auth-backend-module-microsoft-provider patch v0.1.14-next.1
@backstage/plugin-auth-backend-module-oauth2-provider plugins/auth-backend-module-oauth2-provider minor v0.1.16-next.1
@backstage/plugin-auth-backend-module-oidc-provider plugins/auth-backend-module-oidc-provider minor v0.1.10-next.2
@backstage/plugin-auth-backend-module-okta-provider plugins/auth-backend-module-okta-provider patch v0.0.12-next.1
@backstage/plugin-auth-backend-module-pinniped-provider plugins/auth-backend-module-pinniped-provider patch v0.1.13-next.1
@backstage/plugin-auth-backend-module-vmware-cloud-provider plugins/auth-backend-module-vmware-cloud-provider minor v0.1.11-next.1
@backstage/plugin-auth-node plugins/auth-node patch v0.4.14-next.2

Copy link
Member

@freben freben left a comment

Choose a reason for hiding this comment

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

Lookin' awesome

@Rugvip Rugvip added merge-after-release This is a bit too scary to merge until after the next release and removed merge-after-release This is a bit too scary to merge until after the next release labels May 13, 2024
Copy link
Contributor

This PR has been automatically marked as stale because it has not had recent activity from the author. It will be closed if no further activity occurs. If the PR was closed and you want it re-opened, let us know and we'll re-open the PR so that you can continue the contribution!

@liununu
Copy link

liununu commented Jun 11, 2024

Hi @Rugvip , I wonder is that planned in this PR to remove some duplicated defaultScopes from different places and keep them in a standard way ?

defaultScopes = ['openid', 'email', 'profile', 'offline_access'],

const defaultScopes = 'openid profile email';

@Rugvip
Copy link
Member Author

Rugvip commented Jun 11, 2024

@liununu yep that's one of the goals of this refactor. Some of it will be in followup PRs though

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
@Rugvip
Copy link
Member Author

Rugvip commented Jun 11, 2024

There are quite a lot of reports coming in of issues that are fixed by this PR. I was aiming to have these changes go out a bit slower and per provider, but since this fixes a lot of known issues I think we're better off shipping this a bit faster and aim to have it put us in a better state than we are now. I've updated existing providers in 8efc6cf so this PR is not ready to go with hopefully not breakages of existing providers other than intentional ones.

@Rugvip Rugvip force-pushed the rugvip/scopes branch 3 times, most recently from ede645b to 4fe0416 Compare June 11, 2024 10:13
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
@Rugvip
Copy link
Member Author

Rugvip commented Jun 11, 2024

@liununu to follow up a bit more, it's not the goal of this PR to completely remove the default scopes in the frontend. We're keeping them around to ensure compatibility as these changes are rolled out. In theory it would be safe to remove them straight away based on our version skew policy, but in practice it's nice to give a bit of leeway where possible to avoid breaking deployments it tricky ways.

I'll follow up on this work in a later release to start consolidating the auth APIs in the frontend and remove duplicated declarations.

@@ -68,7 +65,7 @@ describe('authModuleOktaProvider', () => {
expect(startUrl.pathname).toBe('/oauth2/v1/authorize');
expect(Object.fromEntries(startUrl.searchParams)).toEqual({
response_type: 'code',
scope: combinedScopes,
scope: 'openid email profile offline_access groups phone',
Copy link
Member Author

Choose a reason for hiding this comment

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

With the latest updates this now properly merges scopes again, regarding #24743 (comment)

@Rugvip Rugvip merged commit ff3742d into master Jun 11, 2024
26 checks passed
@Rugvip Rugvip deleted the rugvip/scopes branch June 11, 2024 13:01
Copy link
Contributor

Thank you for contributing to Backstage! The changes in this pull request will be part of the 1.28.0 release, scheduled for Tue, 18 Jun 2024.

@freben freben mentioned this pull request Jun 24, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants