-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removes social_auth_sqlalchemy references as the social_auth tables are no longer needed with authlib. All tests are now passing. Signed-off-by: Michal Konecny <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,576 additions
and
1,988 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,59 @@ | ||
import flask | ||
import flask_login | ||
|
||
from anitya.db import User, Session | ||
from anitya.db import Session, User | ||
|
||
|
||
def create_oauth_blueprint(oauth): | ||
oauth_blueprint = flask.Blueprint('oauth', __name__) | ||
oauth_blueprint = flask.Blueprint("oauth", __name__) | ||
|
||
@oauth_blueprint.route("/oauthlogin/<name>") | ||
def oauthlogin(name): | ||
client = oauth.create_client(name) | ||
if client is None: | ||
flask.abort(400) | ||
redirect_uri = flask.url_for('.auth', name=name, _external=True) | ||
redirect_uri = flask.url_for(".auth", name=name, _external=True) | ||
return client.authorize_redirect(redirect_uri) | ||
|
||
|
||
@oauth_blueprint.route("/auth/<name>") | ||
def auth(name): | ||
client = oauth.create_client(name) | ||
if client is None: | ||
flask.abort(400) | ||
id_token = flask.request.values.get('id_token') | ||
if flask.request.values.get('code'): | ||
id_token = flask.request.values.get("id_token") | ||
if flask.request.values.get("code"): | ||
token = client.authorize_access_token() | ||
if id_token: | ||
token['id_token'] = id_token | ||
token["id_token"] = id_token | ||
elif id_token: | ||
token = {'id_token': id_token} | ||
token = {"id_token": id_token} | ||
|
||
# for Google | ||
if 'id_token' in token: | ||
if "id_token" in token: | ||
user_info = client.parse_id_token(token) | ||
# for Github | ||
else: | ||
client.response = client.get('user', token=token) | ||
client.response = client.get("user", token=token) | ||
user_info = client.response.json() | ||
if user_info['email'] is None: | ||
resp = client.get('user/emails', token=token) | ||
if user_info["email"] is None: | ||
resp = client.get("user/emails", token=token) | ||
resp.raise_for_status() | ||
data = resp.json() | ||
user_info['email'] = next(email['email'] for email in data if email['primary']) | ||
user_info["email"] = next( | ||
email["email"] for email in data if email["primary"] | ||
) | ||
|
||
# Check if the user exists | ||
user = User.query.filter(User.email == user_info['email']).first() | ||
user = User.query.filter(User.email == user_info["email"]).first() | ||
if not user: | ||
|
||
# TODO: Should create the user (and openid connections) if it does not exist | ||
new_user = User(email=user_info['email'], username=user_info['email']) | ||
new_user = User(email=user_info["email"], username=user_info["email"]) | ||
Session.add(new_user) | ||
Session.commit() | ||
user = new_user | ||
flask_login.login_user(user) | ||
|
||
# TODO: Process next not to just redirect with the main page | ||
return flask.redirect('/') | ||
return flask.redirect("/") | ||
|
||
return oauth_blueprint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.