From 65fb6526273fbdc1c5c498bf80191baa592946c8 Mon Sep 17 00:00:00 2001 From: authcompanion Date: Fri, 12 Apr 2024 23:00:15 -0400 Subject: [PATCH] feat: add 2 new .rest files for API testing using VS Code REST Client plugin --- .vscode/extensions.json | 2 +- README.md | 3 +- tools/admin_api_requests.rest | 102 ++++++++++++++++++++++++++++++++++ tools/auth_api_requests.rest | 78 ++++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 tools/admin_api_requests.rest create mode 100644 tools/auth_api_requests.rest diff --git a/.vscode/extensions.json b/.vscode/extensions.json index d1987c7..d181dd6 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -4,7 +4,7 @@ // List of extensions which should be recommended for users of this workspace. "recommendations": [ - + "humao.rest-client" ], // List of extensions recommended by VS Code that should not be recommended for users of this workspace. "unwantedRecommendations": [ diff --git a/README.md b/README.md index 2028755..336857f 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,8 @@ ## Hot topics -- New Support for Postgres + New Login & Registration Web Form Style - [#22](https://github.com/authcompanion/authcompanion2/pull/22) [Done] +- Our documentation now includes 2 new [.rest files](https://github.com/authcompanion/authcompanion2/tree/main/tools) that utilize the VS Code [REST Client plugin](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) to simplify API testing and provide clear examples of Authcompanion's admin and authentication APIs. +- New Support for Postgres when storing user accounts + New Login & Registration Web Form Styling - [#22](https://github.com/authcompanion/authcompanion2/pull/22) [Done] - A Refresh of the Admin Dashboard Design - [#21](https://github.com/authcompanion/authcompanion2/pull/21) [Done] ## Introduction diff --git a/tools/admin_api_requests.rest b/tools/admin_api_requests.rest new file mode 100644 index 0000000..98bd99c --- /dev/null +++ b/tools/admin_api_requests.rest @@ -0,0 +1,102 @@ +// REST Client is a tool that allows you to make HTTP requests directly within Visual Studio Code. +// https://marketplace.visualstudio.com/items?itemName=humao.rest-client +// This file includes all requests available in AuthCompanion's Admin API +@host = 127.0.0.1:3002/v1/admin +@admin_email = admin@localhost +// admin password can be found in ./adminkey file by default (on first startup) +@admin_password = +@access_token = {{login.response.body.data.attributes.access_token}} +@refresh_token = {{login.response.body.data.attributes.refresh_token}} +@admin_id = {{login.response.body.data.id}} + + +### Login to the admin account +# @name login +POST http://{{host}}/login +content-type: application/json + +{ + "data": { + "type": "users", + "attributes": { + "email": "{{admin_email}}", + "password": "{{admin_password}}" + } + } +} + +### Create a user account +# @name createdUser +POST http://{{host}}/users +content-type: application/json +Authorization: Bearer {{access_token}} + +{ + "data": { + "type": "users", + "attributes": { + "name": "Authy Person", + "email": "testuser_1@authcompanion.com", + "password": "supersecretpassword", + "metadata": { + "tenant": "1234" + }, + "appdata": { + "tenant": "5678" + }, + "active": true, + "isAdmin": false + } + } +} + +### Update a user account +@user_id = {{createdUser.response.body.data.id}} +PATCH http://{{host}}/users/{{user_id}} +content-type: application/json +Authorization: Bearer {{access_token}} + +{ + "data": { + "type": "users", + "attributes": { + "name": "Authy Person", + "email": "testuser_1_Updated@authcompanion.com", + "password": "supersecretpassword", + "metadata": { + "tenant": "1234" + }, + "appdata": { + "tenant": "5678" + }, + "active": true, + "isAdmin": false + } + } +} + +### List the user accounts +GET http://{{host}}/users?page[number]=1 +content-type: application/json +Authorization: Bearer {{access_token}} + + +### Delete a user account +@user_id = {{createdUser.response.body.data.id}} +DELETE http://{{host}}/users/{{user_id}} +content-type: application/json +Authorization: Bearer {{access_token}} + +### Regenerate admins's refresh token +POST http://{{host}}/refresh +content-type: application/json + +{ + "refreshToken": "{{refresh_token}}" +} + +### Logout of admin account +@user_id = {{createdUser.response.body.data.id}} +DELETE http://{{host}}/logout/{{admin_id}} +content-type: application/json +Authorization: Bearer {{access_token}} \ No newline at end of file diff --git a/tools/auth_api_requests.rest b/tools/auth_api_requests.rest new file mode 100644 index 0000000..c6ed942 --- /dev/null +++ b/tools/auth_api_requests.rest @@ -0,0 +1,78 @@ +// REST Client is a tool that allows you to make HTTP requests directly within Visual Studio Code. +// https://marketplace.visualstudio.com/items?itemName=humao.rest-client +// This file includes all requests available in AuthCompanion's Authentication API +@host = 127.0.0.1:3002/v1/auth +@user_email = testuser@authcompanion.com +@user_password = supersecretpassword + +### Register a new user account +POST http://{{host}}/register +content-type: application/json + +{ + "data": { + "type": "users", + "attributes": { + "name": "Authy Person", + "email": "{{user_email}}", + "password": "{{user_password}}", + "metadata": { + "tenantID": "1234" + } + } + } +} + +### Login to the user account +# @name login +POST http://{{host}}/login +content-type: application/json + +{ + "data": { + "type": "users", + "attributes": { + "email": "{{user_email}}", + "password": "{{user_password}}" + } + } +} + +### Update the user account +@access_token = {{login.response.body.data.attributes.access_token}} +@refresh_token = {{login.response.headers.set-cookie}} +POST http://{{host}}/users/me +content-type: application/json +Authorization: Bearer {{access_token}} +Cookie: {{refresh_token}} + +{ + "data": { + "type": "users", + "attributes": { + "name": "Authy Person_updated_name" + } + } +} + +### Recover a user account +POST http://{{host}}/recovery +content-type: application/json + +{ + "email": "{{user_email}}" +} + +### Regenerate user's refresh token +POST http://{{host}}/refresh +content-type: application/json +Cookie: {{refresh_token}} + +{} + +### Delete user's refresh token +DELETE http://{{host}}/refresh +content-type: application/json +Cookie: {{refresh_token}} + +{}