Skip to content

Commit

Permalink
Remove old ouath stuff, minor touch-ups, ready for first full test drive
Browse files Browse the repository at this point in the history
  • Loading branch information
amCap1712 committed Aug 17, 2023
1 parent 513ecba commit c261c1e
Show file tree
Hide file tree
Showing 25 changed files with 170 additions and 623 deletions.
25 changes: 0 additions & 25 deletions admin/sql/create_foreign_keys.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,4 @@ ALTER TABLE access_log
REFERENCES token (value) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;

ALTER TABLE oauth_client
ADD CONSTRAINT oauth_client_supporter_fkey FOREIGN KEY (supporter_id)
REFERENCES supporter (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE;

ALTER TABLE oauth_grant
ADD CONSTRAINT oauth_grant_oauth_client_fkey FOREIGN KEY (client_id)
REFERENCES oauth_client (client_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE;

ALTER TABLE oauth_grant
ADD CONSTRAINT oauth_grant_supporter_fkey FOREIGN KEY (supporter_id)
REFERENCES supporter (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE;

ALTER TABLE oauth_token
ADD CONSTRAINT oauth_token_oauth_client_fkey FOREIGN KEY (client_id)
REFERENCES oauth_client (client_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE;

ALTER TABLE oauth_token
ADD CONSTRAINT oauth_token_supporter_fkey FOREIGN KEY (supporter_id)
REFERENCES supporter (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE;

COMMIT;
4 changes: 1 addition & 3 deletions admin/sql/create_primary_keys.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
BEGIN;

ALTER TABLE "user" ADD CONSTRAINT user_pkey PRIMARY KEY (id);
ALTER TABLE tier ADD CONSTRAINT tier_pkey PRIMARY KEY (id);
ALTER TABLE supporter ADD CONSTRAINT supporter_pkey PRIMARY KEY (id);
ALTER TABLE token ADD CONSTRAINT token_pkey PRIMARY KEY (value);
ALTER TABLE token_log ADD CONSTRAINT token_log_pkey PRIMARY KEY (token_value, "timestamp", action);
ALTER TABLE access_log ADD CONSTRAINT access_log_pkey PRIMARY KEY (token, "timestamp");
ALTER TABLE payment ADD CONSTRAINT payment_pkey PRIMARY KEY (id);
ALTER TABLE oauth_client ADD CONSTRAINT oauth_client_pkey PRIMARY KEY (client_id);
ALTER TABLE oauth_grant ADD CONSTRAINT oauth_grant_pkey PRIMARY KEY (id);
ALTER TABLE oauth_token ADD CONSTRAINT oauth_token_pkey PRIMARY KEY (id);
ALTER TABLE dataset ADD CONSTRAINT dataset_pkey PRIMARY KEY (id);
ALTER TABLE dataset_supporter ADD CONSTRAINT dataset_supporter_pkey PRIMARY KEY (id);

Expand Down
42 changes: 12 additions & 30 deletions admin/sql/create_tables.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
BEGIN;

CREATE TABLE "user" (
id INTEGER GENERATED BY DEFAULT AS IDENTITY,
name TEXT NOT NULL,
password TEXT NOT NULL,
email TEXT,
unconfirmed_email TEXT,
member_since TIMESTAMP WITH TIME ZONE,
last_login_at TIMESTAMP WITH TIME ZONE,
last_updated TIMESTAMP WITH TIME ZONE,
deleted BOOLEAN
);

CREATE TABLE tier (
id SERIAL NOT NULL, -- PK
name CHARACTER VARYING NOT NULL,
Expand Down Expand Up @@ -94,34 +106,4 @@ CREATE TABLE payment (
invoice_number INTEGER
);

CREATE TABLE oauth_client (
client_id CHARACTER VARYING, -- PK
client_secret CHARACTER VARYING NOT NULL,
redirect_uri CHARACTER VARYING NOT NULL,
user_id INTEGER NOT NULL, -- FK, user
name CHARACTER VARYING NOT NULL,
description CHARACTER VARYING NOT NULL,
website CHARACTER VARYING NOT NULL
);

CREATE TABLE oauth_grant (
id SERIAL NOT NULL, -- PK
client_id CHARACTER VARYING NOT NULL, -- FK, oauth_client
user_id INTEGER NOT NULL, -- FK, user
redirect_uri CHARACTER VARYING NOT NULL,
code CHARACTER VARYING NOT NULL,
expires TIMESTAMP WITH TIME ZONE NOT NULL,
scopes CHARACTER VARYING
);

CREATE TABLE oauth_token (
id SERIAL NOT NULL, -- PK
client_id CHARACTER VARYING NOT NULL, -- FK, oauth_client
access_token CHARACTER VARYING NOT NULL,
user_id INT NOT NULL, -- FK, user
refresh_token CHARACTER VARYING NOT NULL,
expires TIMESTAMP WITH TIME ZONE NOT NULL,
scopes CHARACTER VARYING
);

COMMIT;
30 changes: 10 additions & 20 deletions metabrainz/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
import os
import pprint
import sys
from time import sleep

import stripe
from brainzutils.flask import CustomFlask
from authlib.oauth2.rfc6749 import ImplicitGrant
from authlib.oauth2.rfc7636 import CodeChallenge
from brainzutils import sentry
from brainzutils.flask import CustomFlask
from flask import send_from_directory, request
from flask_bcrypt import Bcrypt
from metabrainz.admin.quickbooks.views import QuickBooksView
from time import sleep

from metabrainz.admin.quickbooks.views import QuickBooksView
from metabrainz.oauth.authorization_grant import AuthorizationCodeGrant
from metabrainz.oauth.authorization_grant import AuthorizationCodeGrant
from metabrainz.oauth.provider import authorization_server, revoke_token
from metabrainz.oauth.refresh_grant import RefreshTokenGrant
from metabrainz.utils import get_global_props

from metabrainz.new_oauth.authorization_grant import AuthorizationCodeGrant
from metabrainz.new_oauth.provider import authorization_server, revoke_token

from authlib.oauth2.rfc6749 import ImplicitGrant
from authlib.oauth2.rfc7636 import CodeChallenge

from metabrainz.new_oauth.authorization_grant import AuthorizationCodeGrant
from metabrainz.new_oauth.refresh_grant import RefreshTokenGrant


# Check to see if we're running under a docker deployment. If so, don't second guess
# the config file setup and just wait for the correct configuration to be generated.
deploy_env = os.environ.get('DEPLOY_ENV', '')
Expand Down Expand Up @@ -145,9 +141,7 @@ def create_app(debug=None, config_path=None):

from flask_uploads import configure_uploads
from metabrainz.admin.forms import LOGO_UPLOAD_SET
configure_uploads(app, upload_sets=[
LOGO_UPLOAD_SET,
])
configure_uploads(app, upload_sets=[LOGO_UPLOAD_SET])

config_oauth(app)

Expand Down Expand Up @@ -227,12 +221,8 @@ def _register_blueprints(app):

from metabrainz.oauth.views import oauth_bp
app.register_blueprint(oauth_bp, url_prefix='/oauth')
from metabrainz.new_oauth.views import new_oauth_bp
app.register_blueprint(new_oauth_bp, url_prefix='/new-oauth')
from metabrainz.api.views.index import api_index_bp
app.register_blueprint(api_index_bp, url_prefix='/api')
from metabrainz.api.views.supporter import api_supporter_bp
app.register_blueprint(api_supporter_bp, url_prefix='/api/supporter')
from metabrainz.api.views.musicbrainz import api_musicbrainz_bp
app.register_blueprint(api_musicbrainz_bp, url_prefix='/api/musicbrainz')

Expand Down
14 changes: 0 additions & 14 deletions metabrainz/api/views/supporter.py

This file was deleted.

9 changes: 4 additions & 5 deletions metabrainz/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from flask import render_template, jsonify
from metabrainz.oauth.exceptions import OAuthError
from flask import render_template


def init_error_handlers(app):
Expand All @@ -24,6 +23,6 @@ def internal_server_error(error):
def service_unavailable(error):
return render_template('errors/503.html', error=error), 503

@app.errorhandler(OAuthError)
def oauth_error_handler(error):
return jsonify(error=error.code, description=error.desc), error.status
# @app.errorhandler(OAuthError)
# def oauth_error_handler(error):
# return jsonify(error=error.code, description=error.desc), error.status
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from sqlalchemy import Column, Text, ForeignKey, Integer, ARRAY, Identity, DateTime, func
from sqlalchemy.orm import relationship


from metabrainz.model import db
from metabrainz.model.user import User

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from sqlalchemy.sql.schema import Identity

from metabrainz.model import db
from metabrainz.new_oauth.models import OAuth2Scope
from metabrainz.new_oauth.models.client import OAuth2Client
from metabrainz.new_oauth.models.relation_scope import OAuth2CodeScope
from metabrainz.model.oauth.client import OAuth2Client
from metabrainz.model.oauth.relation_scope import OAuth2CodeScope
from metabrainz.model.oauth.scope import OAuth2Scope
from metabrainz.model.user import User


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from sqlalchemy import Integer
from sqlalchemy.sql.schema import Identity, Column, ForeignKey, Table
from sqlalchemy.sql.schema import Identity, Column, ForeignKey

from metabrainz.model import db


OAuth2TokenScope = db.Table(
"l_token_scope",
Column("id", Integer, Identity(), primary_key=True),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from sqlalchemy.orm import relationship

from metabrainz.model import db
from metabrainz.new_oauth.models.client import OAuth2Client
from metabrainz.new_oauth.models.relation_scope import OAuth2TokenScope
from metabrainz.model.oauth.client import OAuth2Client
from metabrainz.model.oauth.relation_scope import OAuth2TokenScope
from metabrainz.model.user import User


Expand Down
5 changes: 0 additions & 5 deletions metabrainz/new_oauth/models/__init__.py

This file was deleted.

20 changes: 0 additions & 20 deletions metabrainz/new_oauth/provider.py

This file was deleted.

125 changes: 0 additions & 125 deletions metabrainz/new_oauth/views.py

This file was deleted.

3 changes: 0 additions & 3 deletions metabrainz/oauth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from metabrainz.oauth.provider import MetaBrainzAuthorizationProvider

oauth_provider = MetaBrainzAuthorizationProvider()
Loading

0 comments on commit c261c1e

Please sign in to comment.