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

Implementation of Oauth of Github, Google and Microsoft #4298

Open
wants to merge 109 commits into
base: master
Choose a base branch
from

Conversation

feyruzb
Copy link
Collaborator

@feyruzb feyruzb commented Jul 18, 2024

fixes #4160

The right way it should look after logging in
Screenshot from 2024-07-18 17-38-29

new added button to log in with github
Screenshot from 2024-07-18 17-40-36

Changes:

  • added new buttons on login page for GitHub,Google Oauth authorization
  • added functions createLink and getOAuthToken into authentication.thrift
  • imported OAuth2Session in client.py
  • added a case for Oauth authorization in login_user function
  • added definition for thrift
  • imported OAuth2Session in authentication.py
  • added code to load the authentication configuration from
  • added oauth method for authentication in performLogin function
  • added oauth case in session manager
  • added fields for server_config file in the server_config.json
  • added oauth cases in auth.js
  • added reusable providers dict to server config to allow easier adding of new oauth providers
  • create a new function get_oauth_config for getting different providers configs in session manager
  • added documentation for configuration

@feyruzb feyruzb requested review from bruntib and vodorok as code owners July 18, 2024 15:47
@feyruzb feyruzb force-pushed the branch-2-backup branch 2 times, most recently from 5ce7f18 to 68eaf7b Compare July 25, 2024 11:05
@feyruzb feyruzb requested a review from dkrupp as a code owner July 29, 2024 15:14
@feyruzb feyruzb force-pushed the branch-2-backup branch 2 times, most recently from de2e213 to d3f6b29 Compare July 30, 2024 11:02
Copy link
Contributor

@vodorok vodorok left a comment

Choose a reason for hiding this comment

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

Please see my remarks.

I have some additional comments apart from the direct in code messages:

  • My major concern with the implementation is that the oauth related API and its implementation is not generalized enough. The configuration is good enough for the time being.
  • I am not sure if we are allowed to use the Git Hub logo in our repo.
  • Please invite @cservakt to review the JS and VueJS parts.

I did not do a thorough review of the oauth flow in authentication.py after you addressed the above issues I will do another round concentrating on that.

Thanks for the hard work!

@feyruzb feyruzb force-pushed the branch-2-backup branch 10 times, most recently from 12c68e7 to f064c2b Compare July 31, 2024 14:41
@feyruzb feyruzb requested a review from vodorok July 31, 2024 15:03
@feyruzb feyruzb force-pushed the branch-2-backup branch 3 times, most recently from b4d5a0a to d3847d6 Compare July 31, 2024 16:05
@feyruzb feyruzb force-pushed the branch-2-backup branch 4 times, most recently from f4d0556 to e661d1d Compare February 14, 2025 13:38
@feyruzb feyruzb force-pushed the branch-2-backup branch 4 times, most recently from 353e117 to 14f8ac2 Compare February 14, 2025 14:45
Copy link
Contributor

@bruntib bruntib left a comment

Choose a reason for hiding this comment

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

Thanks again for the huge work, well done! Most of my new comments are rather TODO for me to understand and discuss things.

#### OAuth Details per each provider <a name ="oauth-details-per-each-provider"></a>

* Important: `callback_url` must always match with the link specified in the
providers' settings when issuing an access token.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
providers' settings when issuing an access token.
providers' settings when issuing an OAuth application.

Copy link
Collaborator Author

@feyruzb feyruzb Feb 21, 2025

Choose a reason for hiding this comment

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

Fixed, used suggested change.

@@ -16,6 +16,9 @@ Table of Contents
* [<i>LDAP</i> authentication](#ldap-authentication)
* [Configuration options](#configuration-options)
* Membership in custom groups with [<i>regex_groups</i>](#regex_groups-authentication)
Copy link
Contributor

Choose a reason for hiding this comment

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

This regex link could be on the same level as "OAuth authentication"

Comment on lines +393 to +394
"localhost" not in \
user_info_url:
Copy link
Contributor

Choose a reason for hiding this comment

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

According to an earlier discussion this "localhost" is here because it's needed for a test code. I still don't agree distinguishing "localhost" here.

provider_cfg = self.__auth_config.get(
'method_oauth', {}).get("providers", {}).get(provider, {})

# turn off configuration if it is set to default values
Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't agree with hard-coding these example values. I would be interested in the other reviewer's reasons.

@@ -64,6 +66,10 @@ def setup_class_common():

codechecker.add_test_package_product(host_port_cfg, TEST_WORKSPACE)

subprocess.Popen(["python3", "oauth_server.py"],
cwd="tests/functional/authentication")
sleep(5)
Copy link
Contributor

Choose a reason for hiding this comment

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

I still think, we shouldn't operate with sleep(). We should find another way to check if the server is up. Actually, tests shouldn't start until mock server is ready.


The scope of access requested from the OAuth provider.

* `user_info_mapping`
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a feeling that this adds unnecessary extra complexity to the logic. Why do we want to use the e-mail address as user name? Why couldn't the auth provider decide what identifies the user? This way it wouldn't be needed to query the e-mail address at different API endpoints in GitHub. I can't see why e-mail address is important from authentication point of view. Let's discuss these questions in a separate meeting.

Comment on lines 211 to 213
raise codechecker_api_shared.ttypes.RequestFailed(
codechecker_api_shared.ttypes.ErrorCode.AUTH_DENIED,
"OAuth authentication is not enabled for provider:", provider)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does RequestFailed() work with 3 parameters? Is the 3rd parameter concatenated to the 2nd?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, used string formatting.

or not provider_db or not expires_at_db:
raise codechecker_api_shared.ttypes.RequestFailed(
codechecker_api_shared.ttypes.ErrorCode.AUTH_DENIED,
"Something went wrong. Please try again.")
Copy link
Contributor

Choose a reason for hiding this comment

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

A more informative message would be useful which tells that authentication is needed first.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, message now explains what went wrong.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The purpose of this check is to make sure that the data that was fetched is not empty and are actual values.

LOG.error("State, provider or expiery time mismatch.")
raise codechecker_api_shared.ttypes.RequestFailed(
codechecker_api_shared.ttypes.ErrorCode.AUTH_DENIED,
"Something went wrong. Please try again.")
Copy link
Contributor

Choose a reason for hiding this comment

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

A more informative message would be useful which tells what's wrong: is it the expiration date or something else?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, message now explains what went wrong.

self.token = token
self.user_name = user_name
self.groups = groups
self.description = description
self.can_expire = can_expire
self.last_access = datetime.now()
self.oauth_access_token = oauth_access_token
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's discuss the database schema in a meeting.

@feyruzb feyruzb force-pushed the branch-2-backup branch 9 times, most recently from 477c868 to c474887 Compare March 4, 2025 19:14
@feyruzb feyruzb force-pushed the branch-2-backup branch 3 times, most recently from 719771e to 868b7e5 Compare March 5, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenID Connect based authentication (oauth)
7 participants