2016-01-19 14:01:26 +00:00
|
|
|
from flask import current_app
|
2016-01-15 16:22:03 +00:00
|
|
|
from client.authentication import create_jwt_token
|
|
|
|
|
|
2016-01-19 12:07:00 +00:00
|
|
|
from app.dao.api_key_dao import get_unsigned_secret
|
2016-01-15 16:22:03 +00:00
|
|
|
|
|
|
|
|
|
2016-01-19 14:01:26 +00:00
|
|
|
def create_authorization_header(path, method, request_body=None, service_id=None):
|
|
|
|
|
if service_id:
|
|
|
|
|
client_id = service_id
|
|
|
|
|
secret = get_unsigned_secret(service_id)
|
|
|
|
|
else:
|
|
|
|
|
client_id = current_app.config.get('ADMIN_CLIENT_USER_NAME')
|
|
|
|
|
secret = current_app.config.get('ADMIN_CLIENT_SECRET')
|
|
|
|
|
|
2016-01-15 16:22:03 +00:00
|
|
|
if request_body:
|
|
|
|
|
token = create_jwt_token(
|
|
|
|
|
request_method=method,
|
|
|
|
|
request_path=path,
|
2016-01-19 14:01:26 +00:00
|
|
|
secret=secret,
|
|
|
|
|
client_id=client_id,
|
2016-01-15 16:22:03 +00:00
|
|
|
request_body=request_body)
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
token = create_jwt_token(request_method=method,
|
|
|
|
|
request_path=path,
|
2016-01-19 14:01:26 +00:00
|
|
|
secret=secret,
|
|
|
|
|
client_id=client_id)
|
2016-01-15 16:22:03 +00:00
|
|
|
|
|
|
|
|
return 'Authorization', 'Bearer {}'.format(token)
|