Skip to main content

fastapi-jwt-auth simple jwt token authentication

Project description

soildx-jwt-auth

This is a fastapi jwt simple authentication.

Installation

  • Here are some prerequisites for installing soildx-fastapi-jwt-auth packages:

    pip install python-jose[cryptography]
    
    pip install passlib[bcrypt]
    
  • Install with pip:

        pip install soildx-fastapi-jwt-auth
    

Usage

* Endpoint for generating a token
from  fastapi  import  APIRouter, Depends, Request, status, HTTPException

#soildx_fastapi_jwt_auth package import
from  soildx_fastapi_jwt_auth.jwt_auth  import  create_token, check_access_token, get_hashed_password, verify_password

# Endpoint for generating a token
@router.post("/auth_token")
async  def  login(info: Request):
    req_info = await  info.json()
    email = req_info.get('email')
    password = req_info.get('password')
    #check if user and password match in db in Authenticate function
    user = await  Authenticate(email, password)
    if  user  is  None:
        raise  HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid email or password")
    return {"access_token": create_token(user), "token_type": "Bearer token"}
* test auth view
#test auth view. You need to pass headers = {"Authorization": f"Bearer {token}"}
@router.get("/test_auth_view", dependencies=[Depends(check_access_token)])
async  def  test():
	return {"Granted": True}
* Authenticate function
async  def  Authenticate(email:str, password:str) -> dict:
	SQL = f"SELECT email FROM users WHERE email = :email AND password = :password;"
	res = await  db_get('db_name', SQL, {"email":email, "password":password})
	rows = [r._mapping  for  r  in  res]
	return  rows[0]['email'] if  rows  else  None

What Am I Working Next?

I will be working on the issues below. Anyone is welcome to contribute.

  • hash password.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

soildx_fastapi_jwt_auth-0.0.6.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

soildx_fastapi_jwt_auth-0.0.6-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file soildx_fastapi_jwt_auth-0.0.6.tar.gz.

File metadata

  • Download URL: soildx_fastapi_jwt_auth-0.0.6.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for soildx_fastapi_jwt_auth-0.0.6.tar.gz
Algorithm Hash digest
SHA256 e37894fa1c46cb31b8ef3183d34d599165939a9697e1f454fa0ceccf02378435
MD5 606966a3b25c565b789d82a523863fe4
BLAKE2b-256 66f1b60133135a95613b387cf094f0da3b8f9c925e24b3b15790e0b49a320281

See more details on using hashes here.

File details

Details for the file soildx_fastapi_jwt_auth-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for soildx_fastapi_jwt_auth-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 13ea248d8e6686db31a1eb6740682d60a140e8d37e89f077fe069fb0bd6f37f2
MD5 b4c47cf234a70b032eb360e146ff9758
BLAKE2b-256 ce838679f2f084394302b7ea9ebca7c26612b57044ab65c5117b6e0ddf3c02f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page