Skip to main content

AuthMe

A python authentication package to work with postgresql, inspired by devise from ruby.

PyPi Link - https://pypi.org/project/AuthMe/

Features

  1. Regular Auth Flows : Signup, Login, Logout, Password reset
  2. Invitations (coming soon)

Essential Things to keep handy, before using

  1. A postgresql database, ready to accept connections
  2. A secret token to encrypt all tokens
  3. 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 support Depends), and if it returns False, throw 401 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 -

  1. 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)
  2. Password update for loggedin user

Metadata

Release files for AuthMe 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for AuthMe 0.1.5
File Size Uploaded Provenance
AuthMe-0.1.5.tar.gz 4.5 kB Without provenance Details

Release files / AuthMe-0.1.5.tar.gz

Download URL AuthMe-0.1.5.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
07b3317fce7124658bbcfb873f8eecf02ea1c84cf98dd9b90913110d55fafe2c
BLAKE2b-256 checksum
How to use checksums
fa5e7510aed922aaebfa562d009985c4e6c54c094ce2fa73b39d41ce722e129f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.1

Security for AuthMe 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.5 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page