Skip to content

A JWT based authentication service written Rust

Notifications You must be signed in to change notification settings

clundstrom/rust-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust authentication service

Description

This is a simple authentication service written in Rust. It uses the actix-web framework.

Usage

Running the service

To run the service, you need to have Rust installed. You can install Rust by following the instructions here.

Once you have Rust installed, you can run the service by executing the following command:

Environment variables

The service uses the following environment variables:

Required

JWT_SECRET_KEY=your_secret_key
JWT_EXPIRATION_TIME_SECONDS=3600
JWT_COMPANY="Example AB"
LDAP_URL=ldap://localhost:389

# HTTP Server
HTTP_BIND_ADDRESS=0.0.0.0
HTTP_PORT=8080

# Base directory for the LDAP search
AD_BASE_DN=ou=people,dc=example,dc=com
AD_FILTER_FORMAT=(&(objectClass=*))
AD_FILTER_ATTRS=*,memberOf

Optional

# Log Level Settings
# Possible values: trace, debug, info, warn, error (default: info)
# Can be set to a specific crate, e.g. RUST_LOG=debug,my_crate=info
RUST_LOG=debug
cargo run

Running the tests

To run the tests, you can execute the following command:

cargo test

Building the documentation

To build the documentation, you can execute the following command:

cargo doc

Running the benchmarks

To run the benchmarks, you can execute the following command:

cargo bench

Testing the service

You can test the service by sending a POST request to the /login endpoint with a JSON body containing the username and password fields.

Example:

curl -X POST -H "Content-Type: application/json" -d '{"username": "user", "password": "password"}' http://localhost:8080/login

The service will respond with a JWT token if the credentials are correct.

This token can then be used to access the /validate_request endpoint.

Example:

curl -X GET -H "Authorization: Bearer <token>" http://localhost:8080/validate_request

On successful validation, the service will respond with a 200 OK status code and the body Token valid.

Proof of concept

For a proof of concept, you can use the provided run.sh script to start a series of containers with the following services:

  • OpenLDAP
  • Authio service
  • FastAPI service
  • Client performing requests to the services
./run.sh -b

About

A JWT based authentication service written Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published