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

added Seznam SSO provider #194

Merged
merged 6 commits into from
Sep 21, 2024

Conversation

TomasKoutek
Copy link
Contributor

@TomasKoutek TomasKoutek commented Sep 13, 2024

Added support for authentication using Seznam.cz.

Docs: https://vyvojari.seznam.cz/oauth/doc

Summary by CodeRabbit

  • New Features

    • Added Seznam as a new login provider, enhancing user authentication options.
    • Introduced a FastAPI application example for Seznam SSO integration, providing endpoints for login and callback.
  • Documentation

    • Updated README to include Seznam in the list of login providers, improving user awareness of available options.
  • Tests

    • Expanded test suite to include the Seznam SSO provider, enhancing coverage of authentication integrations.

Copy link

coderabbitai bot commented Sep 13, 2024

Walkthrough

The pull request introduces the Seznam Single Sign-On (SSO) integration into a FastAPI application. It updates the README.md to include Seznam as a login provider, adds an example implementation in examples/seznam.py, and introduces the SeznamSSO class in fastapi_sso/sso/seznam.py for handling OAuth authentication. Additionally, it updates the test suite in tests/test_providers.py to include tests for the new Seznam SSO provider.

Changes

Files Change Summary
README.md Added entry for Seznam login provider (by Tomas Koutek).
examples/seznam.py Introduced FastAPI application for Seznam SSO with /auth/login and /auth/callback endpoints.
fastapi_sso/sso/seznam.py Added SeznamSSO class for OAuth integration, including methods for discovery document and response processing.
tests/test_providers.py Updated to include SeznamSSO in the list of SSO providers for testing.

Poem

In the garden where bunnies play,
A new login blooms today! 🌼
Seznam hops into the scene,
With SSO magic, swift and keen.
Now users can log in with glee,
Thanks to Tomas and the team, hoppy as can be! 🐇✨


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3be5d2e and dbede07.

Files selected for processing (1)
  • fastapi_sso/sso/seznam.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • fastapi_sso/sso/seznam.py

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai generate interesting stats about this repository and render them as a table.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6c8ed47 and cfb5002.

Files selected for processing (4)
  • README.md (1 hunks)
  • examples/seznam.py (1 hunks)
  • fastapi_sso/sso/seznam.py (1 hunks)
  • tests/test_providers.py (2 hunks)
Additional comments not posted (7)
examples/seznam.py (1)

23-27: LGTM!

The auth_init function is implemented correctly and follows the expected flow for initiating the Seznam authentication process. It uses the get_login_redirect method of the SeznamSSO instance to handle the redirection logic and is decorated with the appropriate endpoint.

fastapi_sso/sso/seznam.py (3)

18-23: LGTM!

The class attributes are correctly defined:

  • provider is set to "seznam".
  • base_url is specified for API interactions.
  • scope outlines the permissions requested during the OAuth flow.

25-31: LGTM!

The get_discovery_document method correctly constructs a dictionary containing URLs for authorization, token exchange, and user information retrieval based on the defined base_url.


33-43: LGTM!

The openid_from_response method correctly processes the response from Seznam after user authentication, extracting user details such as email, first name, last name, display name, user ID, and avatar URL. It returns an OpenID object populated with the extracted user information.

README.md (1)

79-79: LGTM!

The new entry for the Seznam login provider is consistent with the format used for other contributed providers. It provides relevant information and credits the contributor appropriately.

tests/test_providers.py (2)

27-27: LGTM!

The import statement for SeznamSSO is correctly written and is necessary to include it in the list of tested providers.


55-55: LGTM!

Adding SeznamSSO to the tested_providers tuple ensures that all the tests defined in this file are run against the SeznamSSO provider. This change is consistent with the objective of expanding the test coverage for the new SSO provider.

Comment on lines 30 to 35
@app.get("/auth/callback")
async def auth_callback(request: Request):
"""Verify login"""
with sso:
user = await sso.verify_and_process(request, params={"client_secret": CLIENT_SECRET})
return user
Copy link

Choose a reason for hiding this comment

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

Verify the login implementation and consider filtering sensitive information.

The auth_callback function is implemented correctly and follows the expected flow for verifying the login credentials. It uses the verify_and_process method of the SeznamSSO instance to process the request and is decorated with the appropriate endpoint.

However, passing the client_secret as a parameter to the verify_and_process method and directly returning the user object could potentially expose sensitive information. Consider filtering out any sensitive fields from the user object before returning it to the client.

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.

Hi @TomasKoutek and thanks for the contribution! I've attached a single comment, may I ask you to either explain it to me or change it if it's not necessary?

Nenapadlo by mě, že bude poptávka po Seznam SSO! 😁 Díky!

async def auth_callback(request: Request):
"""Verify login"""
with sso:
user = await sso.verify_and_process(request, params={"client_secret": CLIENT_SECRET})
Copy link
Owner

Choose a reason for hiding this comment

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

Is passing the client secret explicitly in params neccessary? I would guess oauthlib adds the client secret to the request uri when doing prepare_token_request in verify_login method of SSOBase 🤔 If this is specific to Seznam, I'd probably also add it to documentation, or maybe emphasize it in the comment here so that users who come to documented examples actually notice that this is some specialty :)

Copy link
Contributor Author

@TomasKoutek TomasKoutek Sep 14, 2024

Choose a reason for hiding this comment

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

Yes, unfortunately it is needed. It took me a while to figure it out, but it's also described in the documentation - "2. Převod kódu na token" contains a "client_secret" field. Without it, Seznam API returns the response "{'error': 'invalid_client'}".

I added a comment to the example - 3be5d2e

Copy link

codecov bot commented Sep 14, 2024

Codecov Report

Attention: Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.

Project coverage is 94.80%. Comparing base (6c8ed47) to head (cfb5002).

Files with missing lines Patch % Lines
fastapi_sso/sso/seznam.py 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #194      +/-   ##
==========================================
- Coverage   94.82%   94.80%   -0.03%     
==========================================
  Files          20       21       +1     
  Lines         483      500      +17     
==========================================
+ Hits          458      474      +16     
- Misses         25       26       +1     
Files with missing lines Coverage Δ
fastapi_sso/sso/seznam.py 94.11% <94.11%> (ø)

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 a lot! Could you please make sure the pipeline passes? You could try ruff, most of the problems are IMHO auto-fixable.

Copy link
Contributor Author

@TomasKoutek TomasKoutek left a comment

Choose a reason for hiding this comment

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

Ok, done...but I dont like "one-line" imports :-)

@tomasvotava
Copy link
Owner

Why is that so? I don't think I've ever seen this, black, isort, ruff, flake, they all seem to make the imports more concise, this is probably the first time I see the tendency to do otherwise :)

@TomasKoutek
Copy link
Contributor Author

Why is that so? I don't think I've ever seen this, black, isort, ruff, flake, they all seem to make the imports more concise, this is probably the first time I see the tendency to do otherwise :)

It's probably just personal preference and it's pycharm's default behavior (ctrl+o).

@tomasvotava tomasvotava merged commit 989ce0c into tomasvotava:master Sep 21, 2024
13 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