๐ก๏ธ This repository houses the backend for BagIt. BagIt a mobile application that improves the grocery shopping experience, by allowing users to easily create and share shopping lists.
The BagIt backend is shown below (highlighted in red).
The backend consists of three(3) main components:
-
User Authentication API - Users must first register and login to be able to access the SignalR Hub. Clients that are successfully authenticated receive a JSON Web Token (JWT) that can then use to access the Hub. The API is deploy on Microsoft Azure and can ge accessed here:
https://bag-it-api.azurewebsites.net/api/user
The endpoints for the API are as follows:/api/user
: Test that the user endpoint works
-
/api/user/register
: Create new user- Body:
Username: String
(optional): The username of the userEmail: String
(required): The email address of the userPassword: String
(required): The password of the user
- Body:
-
/api/user/login
: Sign user in- Body:
Email: String
(required): The email address of the userPassword: String
(required): The password of the user
- Body:
-
SignalR Hub - The Hub allows for real-time client-to-server (and server-to-client) communication. The former means that users receive shopping list updates in real-time. Unauthorized clients are not able to invoke Hub methods. The Hub is deploy on Microsoft Azure and can ge accessed here, assuming the valid jwt is supplied (see 3. below) :
https://bag-it-api.azurewebsites.net/listHub
-
SQLite Database - This self-contained database stores all the list information and users. See the ERD diagram below.
Clone this repository:
git clone [email protected]:jsam07/bag-it-api.git
dotnet run
The server is now running on https://localhost:7210
. You can now make API requests, e.g. https://localhost:7210/api/user.
Recall, you can only access the Hub by providing a valid jwt (generated after successful login). See below for an example:
The jwt token can be obtained by authenticating via the api/user/login
route specified above - the response shape is as follows:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYiLCJleHAiOjE2NDkwNjA4MzksImlzcyI6Imh0dHBzOi8vYmFnLWl0LWFwaS5henVyZXdlYnNpdGVzLm5ldCIsImF1ZCI6Imh0dHBzOi8vYmFnLWl0LWFwaS5henVyZXdlYnNpdGVzLm5ldCJ9.GscRb0fipj79Abl3aUQoT6zUpjxn6oIV0v_SI6t7RME",
"expiration": "2022-04-04T08:27:19Z"
}
Use the test-client
example project in the root directory to test Hub invocations:
let jwt = "token_here"
const connection = new signalR.HubConnectionBuilder()
.withUrl("https://localhost:7210/listHub", { accessTokenFactory: () => jwt })
.withAutomaticReconnect()
.build();