def index( schema: AuthRequestSchema, dbcontext: DbContext = Depends(get_dbcontext) ): try: token: str = AuthService(dbcontext).authenticate(schema.username, schema.password) return AuthResponseSchema(token_type="Bearer", access_token=token) except ValueError as e: raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
def __init__(self): self.resellerService = ResellerService() self.authService = AuthService()
def get_auth_service(database: Database = Depends(get_database), user_service: UserService = Depends( get_user_service)) -> Generator: auth_service = AuthService(database, user_service) yield auth_service
import logging import traceback from services.auth_service import AuthService from settings import BASE_ROUTE from flask import Blueprint, jsonify FORMAT = "[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s" logging.basicConfig(format=FORMAT, level=logging.INFO) auth_blueprint = Blueprint('auth_blueprint', 'auth_blueprint') auth_service = AuthService() @auth_blueprint.route(f'/{BASE_ROUTE}/token', methods=['GET']) def get_token(): try: res = auth_service.get_token() return jsonify(res), 200 except Exception as error: logging.error(f'Error while getting exchange rate {str(error)}') logging.error(traceback.format_exc()) return jsonify({'message': str(error)}), 500
def get_auth_service(): from services.auth_service import AuthService return AuthService()
private_key = PKCS1_OAEP.new(RSA.importKey(raw_private_key)) public_key = PKCS1_OAEP.new(RSA.importKey(raw_public_key)) app = Flask(__name__, static_folder="../static/dist", template_folder="../static") app.config['MONGO_DBNAME'] = 'password_manager_db' app.config["MONGO_URI"] = "mongodb://localhost:27017/password_manager_db" mongo = PyMongo(app) user_collection = mongo.db.users whitelisted_users = mongo.db.whitelisted_users auth_service = AuthService(users_collection=user_collection, whitelisted_users=whitelisted_users, private_key=raw_private_key, jwt=jwt) user_credentials_collection = mongo.db.user_credentials credential_service = CredentialsService( credentials_collection=user_credentials_collection) blacklist_service = BlackListService() def token_required(f): def decorated(*args, **kwargs): token = None if 'x-access-token' in request.headers: token = request.headers['x-access-token']