Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: endpoint challenge #33

Merged
merged 6 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified requirements.txt
Binary file not shown.
29 changes: 29 additions & 0 deletions src/controllers/_authentication_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,32 @@ def login_handler():
except Exception as e:
print("SOAP Error:", str(e))
return {"msg": "Internal error", "error": str(e)}, 500


def challenge():
try:
data = request.json

if not data:
return {"msg": "No JSON data provided in the request"}, 400

token = data.get("jwt")

if not token:
return {"msg": "Token is missing in JSON data"}, 400

# SOAP
response = soap_client.service.auth_refresh({"token": token})

if response.code == 200:
# Successfully updated JWT token
new_token = response.auth.token
return {"msg": "JWT refreshed successfully", "jwt": new_token}, 200
elif response.code == 401:
return {"msg": "Token has expired and couldn't be refreshed"}, 401
else:
return {"msg": "Unauthorized"}, 401

except Exception as e:
print("Error:", str(e))
return {"msg": "Internal error", "error": str(e)}, 500
5 changes: 5 additions & 0 deletions src/views/_authentication_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
@views.route("/auth_login", methods=["POST"])
def auth_login():
return _authentication_controllers.login_handler()


@views.route("/auth_refresh", methods=["POST"])
def auth_refresh():
return _authentication_controllers.challenge()