Skip to content

Commit

Permalink
fix ISEs and oauth setup
Browse files Browse the repository at this point in the history
  • Loading branch information
amCap1712 committed May 25, 2023
1 parent f6089ff commit 3114810
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 30 deletions.
4 changes: 2 additions & 2 deletions metabrainz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
CONSUL_CONFIG_FILE_RETRY_COUNT = 10


def create_app(debug=None, config_path = None):
def create_app(debug=None, config_path=None):

app = CustomFlask(
import_name=__name__,
Expand All @@ -36,7 +36,7 @@ def create_app(debug=None, config_path = None):
# get rid of some really pesky warning. Remove this in April 2020, when it shouldn't be needed anymore.
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True

print("Starting metabrainz service with %s environment." % deploy_env);
print("Starting metabrainz service with %s environment." % deploy_env)

# This is used to run tests, but not for dev or deployment
if config_path:
Expand Down
2 changes: 1 addition & 1 deletion metabrainz/new_oauth/authorization_grant.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from authlib.oauth2.rfc6749 import grants

from metabrainz.new_oauth.models import db
from metabrainz.model import db
from metabrainz.new_oauth.models.code import OAuth2AuthorizationCode
from metabrainz.new_oauth.models.scope import get_scopes
from metabrainz.new_oauth.models.user import OAuth2User
Expand Down
2 changes: 1 addition & 1 deletion metabrainz/new_oauth/introspection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from authlib.oauth2.rfc7662 import IntrospectionEndpoint

from metabrainz.new_oauth.models import db
from metabrainz.model import db
from metabrainz.new_oauth.models.token import OAuth2Token


Expand Down
11 changes: 6 additions & 5 deletions metabrainz/new_oauth/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import declarative_base

db = SQLAlchemy()
Base = declarative_base()
from .client import OAuth2Client
from .code import OAuth2AuthorizationCode
from .relation_scope import OAuth2TokenScope, OAuth2CodeScope
from .scope import OAuth2Scope
from .token import OAuth2Token
from .user import OAuth2User
4 changes: 2 additions & 2 deletions metabrainz/new_oauth/models/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from sqlalchemy.orm import relationship


from metabrainz.new_oauth.models import Base
from metabrainz.model import db


class OAuth2Client(Base, ClientMixin):
class OAuth2Client(db.Model, ClientMixin):

__tablename__ = 'client'
__table_args__ = {
Expand Down
4 changes: 2 additions & 2 deletions metabrainz/new_oauth/models/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from sqlalchemy.orm import relationship
from sqlalchemy.sql.schema import Identity

from metabrainz.new_oauth.models import Base
from metabrainz.model import db
from metabrainz.new_oauth.models.client import OAuth2Client
from metabrainz.new_oauth.models.relation_scope import OAuth2CodeScope
from metabrainz.new_oauth.models.user import OAuth2User


class OAuth2AuthorizationCode(Base, AuthorizationCodeMixin):
class OAuth2AuthorizationCode(db.Model, AuthorizationCodeMixin):

__tablename__ = "code"
__table_args__ = {
Expand Down
8 changes: 3 additions & 5 deletions metabrainz/new_oauth/models/relation_scope.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
from sqlalchemy import Integer
from sqlalchemy.sql.schema import Identity, Column, ForeignKey, Table

from metabrainz.new_oauth.models import Base
from metabrainz.model import db


OAuth2TokenScope = Table(
OAuth2TokenScope = db.Table(
"l_token_scope",
Base.metadata,
Column("id", Integer, Identity(), primary_key=True),
Column("token_id", Integer, ForeignKey("oauth.token.id", ondelete="CASCADE"), nullable=False),
Column("scope_id", Integer, ForeignKey("oauth.scope.id", ondelete="CASCADE"), nullable=False),
schema="oauth"
)

OAuth2CodeScope = Table(
OAuth2CodeScope = db.Table(
"l_code_scope",
Base.metadata,
Column("id", Integer, Identity(), primary_key=True),
Column("code_id", Integer, ForeignKey("oauth.code.id", ondelete="CASCADE"), nullable=False),
Column("scope_id", Integer, ForeignKey("oauth.scope.id", ondelete="CASCADE"), nullable=False),
Expand Down
4 changes: 2 additions & 2 deletions metabrainz/new_oauth/models/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from sqlalchemy import Integer, Text
from sqlalchemy.sql.schema import Identity, Column

from metabrainz.new_oauth.models import Base
from metabrainz.model import db


class OAuth2Scope(Base):
class OAuth2Scope(db.Model):
__tablename__ = 'scope'
__table_args__ = {
'schema': 'oauth'
Expand Down
4 changes: 2 additions & 2 deletions metabrainz/new_oauth/models/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from sqlalchemy import func, Column, Integer, DateTime, Text, ForeignKey, Boolean, Identity
from sqlalchemy.orm import relationship

from metabrainz.new_oauth.models import Base, db
from metabrainz.model import db
from metabrainz.new_oauth.models.client import OAuth2Client
from metabrainz.new_oauth.models.relation_scope import OAuth2TokenScope
from metabrainz.new_oauth.models.user import OAuth2User


class OAuth2Token(Base, TokenMixin):
class OAuth2Token(db.Model, TokenMixin):
__tablename__ = "token"
__table_args__ = {
"schema": "oauth"
Expand Down
4 changes: 2 additions & 2 deletions metabrainz/new_oauth/models/user.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from flask_login import UserMixin
from sqlalchemy import Column, Integer, Identity, Text, DateTime, func, Date, Boolean

from metabrainz.new_oauth.models import Base
from metabrainz.model import db


class OAuth2User(Base, UserMixin):
class OAuth2User(db.Model, UserMixin):
__tablename__ = "user"
__table_args__ = {
"schema": "oauth"
Expand Down
2 changes: 1 addition & 1 deletion metabrainz/new_oauth/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from authlib.integrations.flask_oauth2 import AuthorizationServer

from metabrainz.new_oauth.introspection import OAuth2IntrospectionEndpoint
from metabrainz.new_oauth.models import db
from metabrainz.model import db
from metabrainz.new_oauth.models.client import OAuth2Client
from metabrainz.new_oauth.models.token import OAuth2Token, save_token

Expand Down
2 changes: 1 addition & 1 deletion metabrainz/new_oauth/refresh_grant.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from authlib.oauth2.rfc6749 import grants

from metabrainz.new_oauth.models import db
from metabrainz.model import db
from metabrainz.new_oauth.models.token import OAuth2Token
from metabrainz.new_oauth.models.user import OAuth2User

Expand Down
2 changes: 1 addition & 1 deletion metabrainz/new_oauth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from metabrainz.new_oauth.models.token import OAuth2Token
from metabrainz.new_oauth.models.user import OAuth2User
from metabrainz.new_oauth.provider import authorization_server
from metabrainz.new_oauth.models import db
from metabrainz.model import db
from metabrainz.utils import build_url
from werkzeug.security import gen_salt

Expand Down
5 changes: 2 additions & 3 deletions metabrainz/supporter/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from metabrainz.model.supporter import Supporter, InactiveSupporterException
from metabrainz.model.tier import Tier
from metabrainz.model.token import TokenGenerationLimitException
from metabrainz.new_oauth.models import db
from metabrainz.model import db
from metabrainz.new_oauth.models.user import OAuth2User
from metabrainz.users import musicbrainz_login, login_forbidden
from metabrainz.users.forms import CommercialSignUpForm, NonCommercialSignUpForm, CommercialSupporterEditForm, \
Expand Down Expand Up @@ -313,8 +313,7 @@ def regenerate_token():
@supporters_bp.route('/login')
@login_forbidden
def login():
login_user(db.session.query(OAuth2User).filter_by(name='test1').first())
return redirect(url_for('index.home'))
return render_template('users/mb-login.html')


@supporters_bp.route('/logout')
Expand Down

0 comments on commit 3114810

Please sign in to comment.