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

Adjust authentication for Fedora and Github #1853

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions anitya/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
It provides login route as well as callback for OAuth2 calls.
"""

import logging

import flask
import flask_login

from anitya.db import Session, User

_log = logging.getLogger(__name__)


def create_auth_blueprint(oauth):
"""
Expand Down Expand Up @@ -44,14 +48,24 @@ def auth(name): # pragma: no cover
if client is None:
flask.abort(404)
token = client.authorize_access_token()
user_info = token.get("userinfo")
if not user_info:
user_info = client.userinfo()
if name == "fedora":
user_info = client.userinfo(token=token)
user_info["email"] = client.get("email", token=token)
elif name == "github":
user_info = token.get("user", token=token)
else:
user_info = token.get("userinfo")
if not user_info:
user_info = client.userinfo()

_log.debug("Obtained user_info from %s: %s", name, user_info)

# Check if the user exists
user = User.query.filter(User.email == user_info["email"]).first()
if not user:
new_user = User(email=user_info["email"], username=user_info["email"])
new_user = User(
email=user_info["email"], username=user_info["preferred_username"]
)
Session.add(new_user)
Session.commit()
user = new_user
Expand Down
Loading