Skip to content

Commit

Permalink
Adjust authentication for Fedora and Github
Browse files Browse the repository at this point in the history
The response is different for each backend, we need to reflect that.

Signed-off-by: Michal Konecny <[email protected]>
  • Loading branch information
Zlopez committed Dec 5, 2024
1 parent 12df916 commit 9e728ae
Showing 1 changed file with 18 additions and 4 deletions.
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

0 comments on commit 9e728ae

Please sign in to comment.