Coder Social home page Coder Social logo

rohteemie / authentication-service Goto Github PK

View Code? Open in Web Editor NEW

This project forked from oluadepe/transafe_authentication_service

1.0 0.0 0.0 39 KB

This repository provides a secure authentication service to authenticate a user with registered account. This service uses a token-based authentication with token issuance for use.

License: MIT License

Python 100.00%

authentication-service's Introduction

Transafe Authentication service

This authentication Service is a RESTful API that handles user credentials. It allows user to create, update and delete login credentials.

Functionality

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

Testing

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.

Style Guide

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

How to Use

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 to true 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$

Future features:

  • User token invalidation: invalidate user access token based on user logout or account security issues

License

  • MIT LICENSE This service is licensed under the MIT License. See the LICENSE file for more information.

Authors

Owolabi Rotimi
Ajiboye Adeleye
Olusegun Mayungbe

authentication-service's People

Contributors

adeleye080 avatar rohteemie avatar oluadepe avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.