Skip to content

Commit

Permalink
changed syntaxis to much the rest of the file, added a check for defa…
Browse files Browse the repository at this point in the history
…ult oauth values
  • Loading branch information
feyruzb committed Sep 23, 2024
1 parent d5c9a8c commit 92c880e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions web/server/codechecker_server/api/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def createLink(self, provider):
# print("manager", self.__manager)
# print("config_database", self.__config_db)
oauth_config = self.__manager.get_oauth_config(provider)
if not oauth_config.get("enabled"):
if not oauth_config.get('enabled'):
raise codechecker_api_shared.ttypes.RequestFailed(
codechecker_api_shared.ttypes.ErrorCode.AUTH_DENIED,
"OAuth authentication is not enabled.")
Expand Down Expand Up @@ -216,7 +216,7 @@ def performLogin(self, auth_method, auth_string):
provider, url = auth_string.split("@")

oauth_config = self.__manager.get_oauth_config(provider)
if not oauth_config.get("enabled"):
if not oauth_config.get('enabled'):
LOG.error("OAuth authentication is not enabled for provider: %s", provider)
raise codechecker_api_shared.ttypes.RequestFailed(
codechecker_api_shared.ttypes.ErrorCode.AUTH_DENIED,
Expand Down
10 changes: 10 additions & 0 deletions web/server/codechecker_server/session_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,16 @@ def get_oauth_providers(self):
return result

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

if provider_cfg.get("oauth_client_secret", "ExampleClientSecret") == "ExampleClientSecret" \
or provider_cfg.get("oauth_client_id", "ExampleClientID") == "ExampleClientID":
self.__auth_config["method_oauth"]["providers"][provider]["enabled"] = False

LOG.warning("OAuth configuration was set to default values. " + \
"Disabling oauth provider: %s", provider)

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

Expand Down
6 changes: 3 additions & 3 deletions web/server/config/server_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"github" : {
"enabled" : false,
"oauth_client_id" : "ExampleClientID",
"oauth_client_secret": "exampleClientSecret",
"oauth_client_secret": "ExampleClientSecret",
"oauth_authorization_uri": "https://github.com/login/oauth/authorize",
"oauth_redirect_uri": "http://path_To_CodeChecker_Login_Page",
"oauth_token_uri": "https://github.com/login/oauth/access_token",
Expand All @@ -81,7 +81,7 @@
"google": {
"enabled" : false,
"oauth_client_id" : "ExampleClientID",
"oauth_client_secret" : "exampleClientSecret",
"oauth_client_secret" : "ExampleClientSecret",
"oauth_authorization_uri" : "https://accounts.google.com/o/oauth2/auth",
"oauth_redirect_uri" : "http://path_To_CodeChecker_Login_Page",
"oauth_token_uri" : "https://accounts.google.com/o/oauth2/token",
Expand All @@ -99,7 +99,7 @@
"microsoft": {
"enabled": true,
"oauth_client_id": "ExampleClientID",
"oauth_client_secret": "exampleClientSecret",
"oauth_client_secret": "ExampleClientSecret",
"oauth_authorization_uri": "https://login.microsoftonline.com/92e84ceb-fbfd-47ab-be52-080c6b87953f/oauth2/v2.0/authorize",
"oauth_redirect_uri": "http://path_To_CodeChecker_Login_Page",
"oauth_token_uri": "https://login.microsoftonline.com/92e84ceb-fbfd-47ab-be52-080c6b87953f/oauth2/v2.0/token",
Expand Down

0 comments on commit 92c880e

Please sign in to comment.