Skip to content

Commit

Permalink
Fix/disable site when change code (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazywoola authored Aug 8, 2023
1 parent a8d5ef9 commit 3d19478
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 4 additions & 3 deletions api/controllers/web/passport.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
class PassportResource(Resource):
"""Base resource for passport."""
def get(self):
app_id = request.headers.get('X-App-Code')
if app_id is None:
app_code = request.headers.get('X-App-Code')
if app_code is None:
raise Unauthorized('X-App-Code header is missing.')

# get site from db and check if it is normal
site = db.session.query(Site).filter(
Site.code == app_id,
Site.code == app_code,
Site.status == 'normal'
).first()
if not site:
Expand All @@ -41,6 +41,7 @@ def get(self):
"iss": site.app_id,
'sub': 'Web API Passport',
'app_id': site.app_id,
'app_code': app_code,
'end_user_id': end_user.id,
}

Expand Down
6 changes: 5 additions & 1 deletion api/controllers/web/wraps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from werkzeug.exceptions import NotFound, Unauthorized

from extensions.ext_database import db
from models.model import App, EndUser
from models.model import App, EndUser, Site
from libs.passport import PassportService

def validate_jwt_token(view=None):
Expand Down Expand Up @@ -35,9 +35,13 @@ def decode_jwt_token():
if auth_scheme != 'bearer':
raise Unauthorized('Invalid Authorization header format. Expected \'Bearer <api-key>\' format.')
decoded = PassportService().verify(tk)

app_model = db.session.query(App).filter(App.id == decoded['app_id']).first()
site = db.session.query(Site).filter(Site.code == decoded['app_code']).first()
if not app_model:
raise NotFound()
if not site:
raise Unauthorized('Site URL is no longer valid.')
if app_model.enable_site is False:
raise Unauthorized('Site is disabled.')
end_user = db.session.query(EndUser).filter(EndUser.id == decoded['end_user_id']).first()
Expand Down

0 comments on commit 3d19478

Please sign in to comment.