This project is a Flask-based centralized authentication service that provides user registration, login, and email confirmation functionalities. It uses the database-service
as database schema.
- User registration with email confirmation
- User login with password hashing
- Email token generation and validation for account confirmation
- Email and password changes
- Password reset management
- Redirect URLs for seamless UX
- API Key management (creation and verification)
- User management frontend to give the user full control about his account
- Data export
- No user account deletion
- Flask
- Flask-SQLAlchemy
- Werkzeug
- python-dotenv
-
Clone the repository:
git clone https://github.com/timonrieger/auth-service.git cd auth-service
-
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Create a
.env
file in the root directory and add your configuration settings. Use the database URL provided by your hosting service. Ensure the connection string matches the one used in the database:SECRET_KEY=your_secret_key DB_URI=your_database_uri
-
Run the application:
python3 -m main
Send a POST request to /register
with the following parameters:
email
password
username
then
(URL to redirect after account confirmation)
data = {"email": email, "password": password, "username": username, "then": "https://YOURDOMAIN/login"}
response = requests.post(f"{AUTH_URL}/register", json=data)
Send a POST request to /login
with the following parameters:
email
password
data = {"email": email, "password": password}
response = requests.post(url=AUTH_URL, json=data)
Send a POST request to /apikey/create
with the following parameters:
id
(user ID)
data = {"id": id}
response = requests.post(url=f"{AUTH_URL}/apikey/create", json=data)
Send a GET request to /apikey/verify
with the authorization header:
Authorization
(no Bearer prefix)
headers = {'Authorization': token}
response = requests.get(url=f"{AUTH_URL}/apikey/verify", headers=headers)
Returns status code 200 on success. Anything else is considered to be an error. The response also always contains a message.
response.status_code
response.json()['message']
Your code might look like this for logging a user in (using flask and flask_login):
response = requests.post(url=f"{AUTH_URL}/login", json=data)
if response.status_code == 200:
flash(response.json()['message'], "success")
login_user(user)
return redirect(url_for("home"))
flash(response.json()['message'], "error")
You will have to change the email content in utils.py
by updating the urls and my name. You can update anything else as well.
This project is licensed under the MIT License. See the LICENSE file for details.