diff --git a/tildes/openapi_beta.yaml b/tildes/openapi_beta.yaml index d526502..c77ecb3 100644 --- a/tildes/openapi_beta.yaml +++ b/tildes/openapi_beta.yaml @@ -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: get: summary: Get a list of topics diff --git a/tildes/tildes/routes.py b/tildes/tildes/routes.py index b394530..33edbde 100644 --- a/tildes/tildes/routes.py +++ b/tildes/tildes/routes.py @@ -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}") diff --git a/tildes/tildes/views/api/beta/auth.py b/tildes/tildes/views/api/beta/auth.py index 64b3280..bb12890 100644 --- a/tildes/tildes/views/api/beta/auth.py +++ b/tildes/tildes/views/api/beta/auth.py @@ -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}