Skip to content

Commit

Permalink
feat: add 2 new .rest files for API testing using VS Code REST Client…
Browse files Browse the repository at this point in the history
… plugin
  • Loading branch information
authcompanion committed Apr 13, 2024
1 parent 43a4e86 commit 65fb652
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
102 changes: 102 additions & 0 deletions tools/admin_api_requests.rest
Original file line number Diff line number Diff line change
@@ -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}}
78 changes: 78 additions & 0 deletions tools/auth_api_requests.rest
Original file line number Diff line number Diff line change
@@ -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}}

{}

0 comments on commit 65fb652

Please sign in to comment.