@ -52,6 +52,23 @@ paths:
$ref: "#/components/responses/ValidationError"
"401":
$ref: "#/components/responses/AuthenticationError"
/whoami:
get:
summary: Get username for currently logged in user
responses:
"200":
description: Username of the currently logged in user
content:
application/json:
schema:
type: object
required:
- msg
properties:
msg:
type: string
/topics:
summary: Get a list of topics
@ -135,6 +135,7 @@ def includeme(config: Configurator) -> None:
with config.route_prefix_context("/api/beta"):
config.add_route("apibeta.login", "/login")
config.add_route("apibeta.whoami", "/whoami")
config.add_route("apibeta.topics", "/topics")
config.add_route("apibeta.topic", "/topic/{topic_id36}")
config.add_route("apibeta.user", "/user/{username}")
@ -109,3 +109,16 @@ def login(request: Request) -> dict:
token = jwt_policy.create_jwt_token(user.user_id)
return {"token": token}
@view_config(route_name="apibeta.whoami", openapi=True, renderer="json")
def whoami(request: Request) -> dict:
"""Endpoint to let a user verify that they are authenticated."""
user = request.user
if not user:
msg = "You are not logged in"
else:
msg = f"You are logged in as {user.username}"
return {"msg": msg}