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

Rework the Bitbucket Server oauth token validation #673

Merged
merged 4 commits into from
Apr 8, 2024
Merged

Conversation

vinokurig
Copy link
Contributor

@vinokurig vinokurig commented Mar 27, 2024

What does this PR do?

  • Change the validation API request to get current user request. The /rest/api/1.0/application-properties request is irrelevant as it does not require a token.
  • Pass oath token to the getPersonalAccessToken() API request in order to avoid circular getToken() request.

Screenshot/screencast of this PR

What issues does this PR fix or reference?

fixes eclipse-che/che#22836

How to test this PR?

  1. Deploy che with the PR image: quay.io/eclipse/che-server:pr-673
  2. Setup a Bitbucket-Server instance.
  3. Configure oauth2 for the Bitbucket-Server instance.
  4. Start a workspace from a repository with a devfile from the Bitbucket-Server, consent the authorisation request.
  5. Go to dashboard -> User Preferences -> Git Services and see that the provider has Authorised state.
  6. Go to the Bitbucket-Server user account page and revoke the authorisation.
  7. Go back to the Git Services tab, refresh the page.

See: The provider's authorisation state is Unauthorised.

PR Checklist

As the author of this Pull Request I made sure that:

Reviewers

Reviewers, please comment how you tested the PR when approving it.

Signed-off-by: ivinokur <ivinokur@redhat.com>
@vinokurig
Copy link
Contributor Author

/retest

2 similar comments
@vinokurig
Copy link
Contributor Author

/retest

@vinokurig
Copy link
Contributor Author

/retest

Comment on lines 137 to 138
bitbucketServerApiClient.getPersonalAccessToken(
personalAccessToken.getScmTokenId(), personalAccessToken.getToken());
Copy link
Contributor

Choose a reason for hiding this comment

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

It is hard to understand, why to retrieve personal access token we have to pass personal access token.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, the PersonalAccessToken interface has a bit misleading name. In this case we implement an oauth token, but not a PAT.

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 Bitbucket Server oauth works in a bit different way: it uses the oauth token to create a PAT and then uses the PAT for all other operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tolusha Do you think we need to rename the PersonalAccessToken interface to AccessToken in order to avoid such confusion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a javadoc with a TODO.

@vinokurig vinokurig marked this pull request as ready for review March 28, 2024 12:18
@vinokurig
Copy link
Contributor Author

/retest

@openshift-ci openshift-ci bot added the lgtm label Apr 4, 2024
@dmytro-ndp dmytro-ndp self-requested a review April 5, 2024 08:15
Copy link
Contributor

@dmytro-ndp dmytro-ndp left a comment

Choose a reason for hiding this comment

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

I have followed test scenario from PR description and, at the end, after revoking of BitBucket Server OAuth 2 application and refreshing 'User Preferences' Dashboard page the 'Authorization' indicator was turned off, and provider's authorization state was Unauthorized.

Test screencast:
screencast-bpconcjcammlapcogcnnelfmaeghhagj-2024.04.05-21_49_42.webm

PR seems to be fixing the target issue eclipse-che/che#22836 regarding BitBucket Server, as expected.

P.S. @vinokurig: so that test scenario in description mentioned BitBucket Server OAuth 2 only, the issue eclipse-che/che#22836 could be still actual to OAuth 1, coudn't it?
If so, I would suggest changing PR title to "Rework the Bitbucket Server oauth 2 token validation" to make the fact obvious.

Copy link

openshift-ci bot commented Apr 5, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dmytro-ndp, tolusha, vinokurig

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@vinokurig
Copy link
Contributor Author

@dmytro-ndp

P.S. @vinokurig: so that test scenario in description mentioned BitBucket Server OAuth 2 only, the issue eclipse-che/che#22836 could be still actual to OAuth 1, coudn't it?
If so, I would suggest changing PR title to "Rework the Bitbucket Server oauth 2 token validation" to make the fact obvious.

The pull request is relevant for both oauth1 and oauth2 standarts.

@vinokurig vinokurig merged commit 2cfce05 into main Apr 8, 2024
28 checks passed
@vinokurig vinokurig deleted the che-22836 branch April 8, 2024 06:30
@devstudio-release
Copy link

Build 3.14 :: server_3.x/333: Console, Changes, Git Data

@dmytro-ndp
Copy link
Contributor

@vinokurig : thanks for the answer.
In that case, the "How to test this PR?" section in description has been missing steps to check the PR with BitBucket Server oauth1.

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

Build 3.14 :: server_3.x/333: SUCCESS

Upstream sync done; /DS_CI/sync-to-downstream_3.x/6443 triggered

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

@devstudio-release
Copy link

Build 3.14 :: get-sources-rhpkg-container-build_3.x/6405: FAILURE

devspaces-operator-bundle : 3.x :: Failed in 60320346 : BREW:BUILD/STATUS:UNKNOWN
FAILURE:; copied to quay

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.

After revoke OAuth application the 'Authorization' indicator is still turned in 'User Preferences' Dashboard
4 participants