replace access_token url parameter with authorization header

issue #66
This commit is contained in:
Morgan McMillian 2023-07-04 09:33:24 -07:00
parent 1a5c9d84b0
commit 84f3882466

View file

@ -65,9 +65,11 @@ def query_alias(alias):
else: else:
abort(401) abort(401)
url = app.config['MATRIX_HOST'] + '/_matrix/client/api/v1/createRoom?access_token=' url = app.config['MATRIX_HOST'] + '/_matrix/client/api/v1/createRoom'
url += app.config['MATRIX_AS_TOKEN'] headers = {
headers = {"Content-Type":"application/json"} "Content-Type": "application/json",
"Authorization": "Bearer " + app.config['MATRIX_AS_TOKEN']
}
r = requests.post(url, headers=headers, data=json.dumps(room)) r = requests.post(url, headers=headers, data=json.dumps(room))
if r.status_code == 200: if r.status_code == 200:
pnutpy.api.subscribe_channel(channel_id) pnutpy.api.subscribe_channel(channel_id)
@ -80,6 +82,12 @@ def query_alias(alias):
db_session.add(rr) db_session.add(rr)
db_session.commit() db_session.commit()
else:
logger.error("Unable to create room")
logger.error(r.status_code)
logger.error(r.text)
abort(400)
except pnutpy.errors.PnutPermissionDenied: except pnutpy.errors.PnutPermissionDenied:
abort(401) abort(401)
@ -438,9 +446,11 @@ def create_room(channel, user):
else: else:
abort(401) abort(401)
url = app.config['MATRIX_HOST'] + '/_matrix/client/api/v1/createRoom?access_token=' url = app.config['MATRIX_HOST'] + '/_matrix/client/api/v1/createRoom'
url += app.config['MATRIX_AS_TOKEN'] headers = {
headers = {"Content-Type":"application/json"} "Content-Type": "application/json",
"Authorization": "Bearer " + app.config['MATRIX_AS_TOKEN']
}
r = requests.post(url, headers=headers, data=json.dumps(room)) r = requests.post(url, headers=headers, data=json.dumps(room))
if r.status_code == 200: if r.status_code == 200:
@ -453,8 +463,12 @@ def create_room(channel, user):
) )
db_session.add(rr) db_session.add(rr)
db_session.commit() db_session.commit()
logger.debug(r.status_code)
logger.debug(r) else:
logger.error("Unable to create room")
logger.error(r.status_code)
logger.error(r.text)
abort(400)
def new_matrix_user(username): def new_matrix_user(username):
matrix_api = MatrixHttpApi(app.config['MATRIX_HOST'], matrix_api = MatrixHttpApi(app.config['MATRIX_HOST'],