This authentication Service is a RESTful API that handles user credentials. It allows user to create, update and delete login credentials.
The microservice provides the following functionality:
-
User registration: allows new users to create login credentials e.g password.
-
Generate access token: allows users to generate access token that can be used to access other services such as user service.
-
User access token invalidation: invalidate unexpired user token
To ensure the functionality and reliability of the microservice, it is recommended to perform the following types of testing.
- Unit tests: we ensure that each component and function of the microservice works correctly in isolation, by mocking dependencies and input/output parameters.
- Integration tests: we ensure that the microservice can interact with other services or systems, such as databases, messaging systems, or APIs, and produce the expected results.
- End-to-end tests: we ensure that the microservice can handle user requests and responses correctly, by simulating user interactions and testing different scenarios and edge cases.
This project follows the PEP 8
We use pycodestyle to enforce these style guidelines. However there is an exception in utils module where line 55 > 79 chars
To use this User Management service,ย please follow these steps:
- 1. Clone the repository and install the dependencies:
terminal@terminal$ git clone https://github.com/Adeleye080/transafe_authentication_service.git
terminal@terminal$ cd transafe_authentication_service
terminal@terminal$ pip3 install -r requirement.txt
- 2. Configure the service settings:
In the .env file, you can set the environment variables for the service, such as the port number, the database connection string, and other options.
username=<you mongodb username>
password=<you mongodb password>
database=<your database name>
collection=<your mongodb collection>
cluster_uri=<your mongodb clutser uri>
issuer=<your token issuer>
jwt_secret_key=<your secret key>
cookie_name=<cookie name>
- 3. Start the service:
terminal@terminal$ python3 -m app
This will start the service on the specified port, and it will listen for incoming requests.
-
4. Use the microservice API: You can use a tool like Postman or cURL to send requests to the API endpoints and receive responses. The API endpoints follow the RESTful principles and use the HTTP methods and status codes to indicate the actions and results.
-
POST /api/v1/auth/register
: retrieves the user profile with the specified ID.
terminal@terminal:~/transafe_authentication_service$ curl http://localhost:5000/api/v1/auth/register -H "Content-Type: application/json" -X POST -d '{"email": "[email protected]", "password": "Testing123", "id": "75fef700-2834-4342-aa06-4f8dd1891356"}'
{
"msg": "credentials created",
"status": "success"
}
terminal@terminal:~/transafe_authentication_service$
POST /api/v1/auth/login
: generate user access token. if rememberMe is set totrue
cookies will be saved to user browser
terminal@terminal:~/transafe_authentication_service$ curl http://localhost:5000/api/v1/auth/login -H "Content-Type: application/json" -X POST -d '{"email": "[email protected]", "password": "Testing123", "rememberMe": true}'
{
"status": "success",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmcmVzaCI6ZmFsc2UsImlhdCI6MTY4MjMyODEyNywianRpIjoiZGNlZWZlNjItZjhjYi00MjJhLWFiNTEtM2Q4Mjc5ZGVjODEzIiwidHlwZSI6ImFjY2VzcyIsInN1YiI6Ijc1ZmVmNzAwLTI4MzQtNDM0Mi1hYTA2LTRmOGRkMTg5MTM1NiIsIm5iZiI6MTY4MjMyODEyNywiZXhwIjoxNjgyNzYwMTI3LCJyb2xlIjoidXNlciIsImlzcyI6IlRSQU5TQUZFIFRPS0VOIElTU1VFUiJ9.wMwLyo0nK3E-X0VxyNjl-JnROLI3QBcHJ-uN0M8uYpM"
}
terminal@terminal:~/transafe_authentication_service$
GET /api/v1/auth/logout
: deletes user token stored in cookies and (future feature:invalidate unexpired user token).
terminal@terminal:~/transafe_authentication_service$ curl http://localhost:5000/api/v1/auth/logout -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmcmVzaCI6ZmFsc2UsImlhdCI6MTY4MjMyODEyNywianRpIjoiZGNlZWZlNjItZjhjYi00MjJhLWFiNTEtM2Q4Mjc5ZGVjODEzIiwidHlwZSI6ImFjY2VzcyIsInN1YiI6Ijc1ZmVmNzAwLTI4MzQtNDM0Mi1hYTA2LTRmOGRkMTg5MTM1NiIsIm5iZiI6MTY4MjMyODEyNywiZXhwIjoxNjgyNzYwMTI3LCJyb2xlIjoidXNlciIsImlzcyI6IlRSQU5TQUZFIFRPS0VOIElTU1VFUiJ9.wMwLyo0nK3E-X0VxyNjl-JnROLI3QBcHJ-uN0M8uYpM"
{
"msg": "logged out successfully",
"status": "success"
}
terminal@terminal:~/transafe_authentication_service$
assuming cookie_name
=session
terminal@terminal:~/transafe_authentication_service$ curl http://localhost:5000/api/v1/auth/logout -b "session=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmcmVzaCI6ZmFsc2UsImlhdCI6MTY4MjMyODEyNywianRpIjoiZGNlZWZlNjItZjhjYi00MjJhLWFiNTEtM2Q4Mjc5ZGVjODEzIiwidHlwZSI6ImFjY2VzcyIsInN1YiI6Ijc1ZmVmNzAwLTI4MzQtNDM0Mi1hYTA2LTRmOGRkMTg5MTM1NiIsIm5iZiI6MTY4MjMyODEyNywiZXhwIjoxNjgyNzYwMTI3LCJyb2xlIjoidXNlciIsImlzcyI6IlRSQU5TQUZFIFRPS0VOIElTU1VFUiJ9.wMwLyo0nK3E-X0VxyNjl-JnROLI3QBcHJ-uN0M8uYpM"
{
"msg": "logged out successfully",
"status": "success"
}
terminal@terminal:~/transafe_authentication_service$
- User token invalidation: invalidate user access token based on user logout or account security issues
- MIT LICENSE This service is licensed under the MIT License. See the LICENSE file for more information.