Skip to content

Commit

Permalink
gitlab oauth scope setting (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
JerrySentry authored Jun 12, 2024
1 parent 7bed118 commit ff7cbca
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion codecov/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@
GITLAB_REDIRECT_URI = get_config(
"gitlab", "redirect_uri", default="https://codecov.io/login/gitlab"
)

GITLAB_SCOPE = get_config("gitlab", "scope", default="api")
GITLAB_BOT_KEY = get_config("gitlab", "bot", "key")
GITLAB_TOKENLESS_BOT_KEY = get_config(
"gitlab", "bots", "tokenless", "key", default=GITLAB_BOT_KEY
Expand Down
2 changes: 1 addition & 1 deletion codecov_auth/tests/unit/views/test_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_get_gitlab_redirect(client, settings, mock_redis, mocker):
assert res.status_code == 302
assert (
res.url
== f"https://gitlab.com/oauth/authorize?response_type=code&client_id=testfiuozujcfo5kxgigugr5x3xxx2ukgyandp16x6w566uits7f32crzl4yvmth&redirect_uri=http%3A%2F%2Flocalhost%2Flogin%2Fgitlab&state={state}"
== f"https://gitlab.com/oauth/authorize?response_type=code&client_id=testfiuozujcfo5kxgigugr5x3xxx2ukgyandp16x6w566uits7f32crzl4yvmth&redirect_uri=http%3A%2F%2Flocalhost%2Flogin%2Fgitlab&state={state}&scope=api"
)


Expand Down
2 changes: 1 addition & 1 deletion codecov_auth/tests/unit/views/test_gitlab_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_get_gle_redirect(client, settings, mock_redis, mocker):
assert res.status_code == 302
assert (
res.url
== f"https://my.gitlabenterprise.com/oauth/authorize?response_type=code&client_id=testfiuozujcfo5kxgigugr5x3xxx2ukgyandp16x6w566uits7f32crzl4yvmth&redirect_uri=http%3A%2F%2Flocalhost%2Flogin%2Fgle&state={state}"
== f"https://my.gitlabenterprise.com/oauth/authorize?response_type=code&client_id=testfiuozujcfo5kxgigugr5x3xxx2ukgyandp16x6w566uits7f32crzl4yvmth&redirect_uri=http%3A%2F%2Flocalhost%2Flogin%2Fgle&state={state}&scope=api"
)
mock_get_config.assert_called_with("gitlab_enterprise", "url")

Expand Down
6 changes: 6 additions & 0 deletions codecov_auth/views/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from shared.torngit.exceptions import TorngitError

from codecov_auth.views.base import LoginMixin, StateMixin
from utils.config import get_config

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -40,11 +41,16 @@ def get_url_to_redirect_to(self):
redirect_info = self.redirect_info
base_url = urljoin(redirect_info["repo_service"].service_url, "oauth/authorize")
state = self.generate_state()

scope = settings.GITLAB_SCOPE
log.info(f"Gitlab oauth with scope: '{scope}'")

query = dict(
response_type="code",
client_id=redirect_info["client_id"],
redirect_uri=redirect_info["redirect_uri"],
state=state,
scope=scope,
)
query_str = urlencode(query)
return f"{base_url}?{query_str}"
Expand Down

0 comments on commit ff7cbca

Please sign in to comment.