A python authentication package to work with postgresql, inspired from devise gem for ruby.
Project description
AuthMe
A python authentication package to work with postgresql, inspired by devise from ruby.
PyPi Link - https://pypi.org/project/AuthMe/
Features
- Regular Auth Flows : Signup, Login, Logout, Password reset
- Invitations (coming soon)
Essential Things to keep handy, before using
- A postgresql database, ready to accept connections
- A secret token to encrypt all tokens
- All codes returned, are standard http response codes
Installation -
pip install AuthMe
Essential Setup
from AuthMe import AuthMe
db_config = {
'dbname': 'your-db-name',
'user': 'your-db-user',
'password': 'your-db-password',
'host': 'your-db-host',
'port': 'your-db-port',
}
auth = AuthMe(db_config, "your-secret-token")
To initialize the database with the necessary tables
auth.initialize_database()
Signup User
# Below are the necessary attributes. Add more attributes, as needed by your application, but first, add those columns in the database
user_attributes = {
'email': 'mail@example.com',
'password': 'Password1$',
'first_name': 'John',
'last_name': 'Doe'
}
origin_host = "localhost"
ip_address = "127.0.0.1"
auth.signup(user_attributes, origin_host, ip_address)
Response
Signup Success -
# A Python Object
namespace(code=200, token='eyJhb...Hg3TF4', message='Success')
Signup Failure -
# A Python Object
namespace(code=409, token=None, message='User already exists')
Login User
auth.login(email, password, origin_host, ip_address)
Response
Login Success -
# A Python Object
namespace(code=200, token='eyJhbGc...NAM_Gg', message='Success')
Login Failure -
# A Python Object
namespace(code=401, token=None, message='Invalid credentials')
Logout User
auth.logout(token)
Response
# A Python Object
namespace(code=200, token=None, message='Logout success')
Authenticate User
auth.authenticate(token, origin_host, ip_address)
Response
# Boolean
True || False
Current User
auth.current_user(token)
Response
# A Python Object containing all the details of user
namespace(id=1, email='mail@example.com', encrypted_password='f13...0b3', first_name='John', last_name='Doe', created_at=datetime.datetime(2024, 1, 7, 11, 45, 59, 628334), updated_at=datetime.datetime(2024, 1, 7, 11, 45, 59, 628334), reset_password_token=None, reset_password_sent_at=None, reset_password_at=datetime.datetime(2024, 1, 7, 11, 49, 40, 733419), active=True)
NOTE : Like devise, first authenticate the token, then check for current user always.
authenticate
method can be invoked as a dependency method, on all the protected routes (both Fast Api and Flask supportDepends
), and if it returnsFalse
, throw401 error
.
Generate Reset Password
auth.reset_password_token("mail@example.com")
Response
# A reset token, which can be sent out via mail or whatever seems convenient
eyJh...s4Ac
Generate Password from Reset Token
auth.reset_password(reset_token, "Password1$")
Response
# Boolean
True || False
Features under development -
- Config for AuthMe class object :
revoke_tokens_upon_password_reset
: True || False, Default : False
allow_multiple_sessions
: True || False, Default : True
auth_token_expiry
: n second, Default : 86400 second (1 day)
password_reset_token_expiry
: n second, Default : 86400 second (1 day) - Password update for loggedin user
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
AuthMe-0.1.5.tar.gz
(4.5 kB
view details)
File details
Details for the file AuthMe-0.1.5.tar.gz
.
File metadata
- Download URL: AuthMe-0.1.5.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07b3317fce7124658bbcfb873f8eecf02ea1c84cf98dd9b90913110d55fafe2c |
|
MD5 | 151acc63a80c74863cf905f54b713fbe |
|
BLAKE2b-256 | fa5e7510aed922aaebfa562d009985c4e6c54c094ce2fa73b39d41ce722e129f |