Moved BLENDER_ID_ENDPOINT to config setting
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
import random
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@@ -7,12 +7,12 @@ from datetime import datetime
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from flask import g
|
from flask import g
|
||||||
from flask import request
|
from flask import request
|
||||||
from flask import url_for
|
|
||||||
from flask import abort
|
|
||||||
from eve.methods.post import post_internal
|
from eve.methods.post import post_internal
|
||||||
|
|
||||||
from application import app
|
from application import app
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SystemUtility():
|
class SystemUtility():
|
||||||
def __new__(cls, *args, **kwargs):
|
def __new__(cls, *args, **kwargs):
|
||||||
@@ -23,8 +23,7 @@ class SystemUtility():
|
|||||||
"""Gets the endpoint for the authentication API. If the env variable
|
"""Gets the endpoint for the authentication API. If the env variable
|
||||||
is defined, it's possible to override the (default) production address.
|
is defined, it's possible to override the (default) production address.
|
||||||
"""
|
"""
|
||||||
return os.environ.get(
|
return app.config['BLENDER_ID_ENDPOINT']
|
||||||
'BLENDER_ID_ENDPOINT', "https://www.blender.org/id").rstrip('/')
|
|
||||||
|
|
||||||
|
|
||||||
def validate(token):
|
def validate(token):
|
||||||
@@ -35,6 +34,8 @@ def validate(token):
|
|||||||
- valid: a boolean, stating if the token is valid
|
- valid: a boolean, stating if the token is valid
|
||||||
- user: a dictionary with information regarding the user
|
- user: a dictionary with information regarding the user
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
log.debug("Validating token %s", token)
|
||||||
payload = dict(
|
payload = dict(
|
||||||
token=token)
|
token=token)
|
||||||
try:
|
try:
|
||||||
@@ -44,7 +45,7 @@ def validate(token):
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
print('HTTP error %i validating token:\n%s' % (r.status_code, r.content))
|
log.info('HTTP error %i validating token: %s', r.status_code, r.content)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return r.json()
|
return r.json()
|
||||||
@@ -72,9 +73,10 @@ def validate_token():
|
|||||||
lookup = {'token': token, 'expire_time': {"$gt": datetime.now()}}
|
lookup = {'token': token, 'expire_time': {"$gt": datetime.now()}}
|
||||||
db_token = tokens_collection.find_one(lookup)
|
db_token = tokens_collection.find_one(lookup)
|
||||||
if not db_token:
|
if not db_token:
|
||||||
# If no valid token is found in our local database, we issue a new request to the Blender ID
|
# If no valid token is found in our local database, we issue a new
|
||||||
# server to verify the validity of the token passed via the HTTP header. We will get basic user info if
|
# request to the Blender ID server to verify the validity of the token
|
||||||
# the user is authorized, and we will store the token in our local database.
|
# passed via the HTTP header. We will get basic user info if the user
|
||||||
|
# is authorized, and we will store the token in our local database.
|
||||||
validation = validate(token)
|
validation = validate(token)
|
||||||
if validation is None or validation.get('status', '') != 'success':
|
if validation is None or validation.get('status', '') != 'success':
|
||||||
return False
|
return False
|
||||||
@@ -86,7 +88,8 @@ def validate_token():
|
|||||||
|
|
||||||
if not db_user:
|
if not db_user:
|
||||||
# We don't even know this user; create it on the fly.
|
# We don't even know this user; create it on the fly.
|
||||||
user_id = create_new_user(email, username, validation['data']['user']['id'])
|
user_id = create_new_user(
|
||||||
|
email, username, validation['data']['user']['id'])
|
||||||
groups = None
|
groups = None
|
||||||
else:
|
else:
|
||||||
user_id = db_user['_id']
|
user_id = db_user['_id']
|
||||||
|
@@ -6,6 +6,10 @@ class Development(object):
|
|||||||
RFC1123_DATE_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
|
RFC1123_DATE_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
|
||||||
BUGSNAG_API_KEY = ''
|
BUGSNAG_API_KEY = ''
|
||||||
|
|
||||||
|
# Authentication settings
|
||||||
|
BLENDER_ID_ENDPOINT = os.environ.get(
|
||||||
|
'BLENDER_ID_ENDPOINT', "https://www.blender.org/id").rstrip("/")
|
||||||
|
|
||||||
# Settings for storage
|
# Settings for storage
|
||||||
STORAGE_DIR = '/data/storage/pillar'
|
STORAGE_DIR = '/data/storage/pillar'
|
||||||
SHARED_DIR = '/data/storage/shared'
|
SHARED_DIR = '/data/storage/shared'
|
||||||
|
Reference in New Issue
Block a user