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

fix(gitlab): added support for on-premise gitlab, first name and last name #145

Merged
merged 5 commits into from
Apr 3, 2024

Conversation

akimrx
Copy link
Contributor

@akimrx akimrx commented Apr 1, 2024

Hello!

The current Gitlab implementation does not support the use of authentication via on-premise Gitlab.

In order not to make patches on the client side, I'm making a small edit that adds only one parameter for init the provider with the default value.

Copy link

codecov bot commented Apr 2, 2024

Codecov Report

Merging #145 (3748d01) into master (0062371) will increase coverage by 0.18%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #145      +/-   ##
==========================================
+ Coverage   94.48%   94.66%   +0.18%     
==========================================
  Files          20       20              
  Lines         453      469      +16     
==========================================
+ Hits          428      444      +16     
  Misses         25       25              
Files Coverage Δ
fastapi_sso/sso/gitlab.py 100.00% <100.00%> (ø)

Copy link
Owner

@tomasvotava tomasvotava left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Could you please take another look? ❤️

self,
client_id: str,
client_secret: str,
base_endpoint_url: Optional[Union[pydantic.AnyHttpUrl, str]] = None,
Copy link
Owner

Choose a reason for hiding this comment

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

Could you please move the new argument to the end of the argument list? Also, I'm not super sure about the pydantic.AnyHttpUrl, we are not using the url in any pydantic model, so this feel a little bit odd, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll move the param to end.

As for pydantic.AnyHttpUrl, I was just focusing on the current implementation and added this so that the code would be in the style of the project.

Examples where AnyHttpUrl is used:

Copy link
Owner

Choose a reason for hiding this comment

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

Oh, I haven't even noticed it's already there, then no problem, use it here as well 👌 Thanks!

Comment on lines 43 to 45
"authorization_endpoint": f"{self.base_endpoint_url}/oauth/authorize",
"token_endpoint": f"{self.base_endpoint_url}/oauth/token",
"userinfo_endpoint": f"{self.base_endpoint_url}/api/v4/user",
Copy link
Owner

Choose a reason for hiding this comment

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

I'd prefer using urljoin or r-stripping any potential trailing slash from the base_endpoint_url before concatenating it (to remove the responsibility to know they should not add trailing slash from the users).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comment, I will add urljoin.

I will send this change in one push, after discussing about AnyHttp

@akimrx akimrx changed the title fix(gitlab): added support for on-premise gitlab fix(gitlab): added support for on-premise gitlab, first name and last name Apr 3, 2024
@akimrx
Copy link
Contributor Author

akimrx commented Apr 3, 2024

@tomasvotava

A few important comments on the improvements.

  1. I took into account the comments above, but I still had to specify the type str (instead Union[pydantic.AnyHttpUrl, str]) for base_endpoint_url in order to make friends with mypy with a minimum number of edits.
  2. At the same time, I added the extraction of the first and last name, which works safely in all scenarios, even if the name is empty in the profile. Previously, the provider ignored the fullname — which is not very good.
  3. I needed to slightly change the parameterization of the tests so that several scenarios could be described for one provider. This is done in order to cover the Gitlab provider completely. The main change is that I have abandoned the dictionary in favor of tuples (more flexible).

And of course I tested it in a production environment on my Gitlab:

{
    "id": "2",
    "email": "[email protected]",
    "first_name": "Akim",
    "last_name": "Jordobeck Jurmajohn",
    "display_name": "akimrx",
    "picture": "https://gitlab.xxxxx.net/uploads/-/system/user/avatar/2/avatar.png",
    "provider": "gitlab"
}

@tomasvotava tomasvotava merged commit 0b2a0b4 into tomasvotava:master Apr 3, 2024
14 checks passed
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.

2 participants