def test_authenticate_user(): email = random_lower_string() password = random_lower_string() user_in = UserInCreate(name=email, email=email, password=password) user = upsert_user(bucket, user_in) authenticated_user = authenticate_user(bucket, email, password) assert authenticated_user assert user.Meta.key == authenticated_user.Meta.key
def test_authenticate_user(): email = random_lower_string() password = random_lower_string() user_in = UserInCreate(username=email, email=email, password=password) bucket = get_default_bucket() user = upsert_user(bucket, user_in, persist_to=1) authenticated_user = authenticate_user(bucket, email, password) assert authenticated_user assert user.username == authenticated_user.username
def login_access_token( form_data: OAuth2PasswordRequestForm = Depends(), db: Session = Depends(deps.get_db) ) -> Any: user = user_crud.authenticate_user(db, form_data.username, form_data.password) if not user: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Incorrect username or password", headers={"WWW-Authenticate": "Bearer"}, ) access_token = create_access_token(user.name) return {"access_token": access_token, "token_type": "bearer"}
def route_login_access_token(username, password): user = authenticate_user(bucket, username, password) if not user: abort(400, "Incorrect email or password") elif not check_if_user_is_active(user): abort(400, "Inactive user") access_token_expires = timedelta( minutes=config.ACCESS_TOKEN_EXPIRE_MINUTES) return { "access_token": create_access_token(identity=username, expires_delta=access_token_expires), "token_type": "bearer", }
def route_login_access_token(form_data: OAuth2PasswordRequestForm = Depends()): """ OAuth2 compatible token login, get an access token for future requests """ bucket = get_default_bucket() user = authenticate_user(bucket, form_data.username, form_data.password) if not user: raise HTTPException(status_code=400, detail="Incorrect email or password") elif not check_if_user_is_active(user): raise HTTPException(status_code=400, detail="Inactive user") access_token_expires = timedelta( minutes=config.ACCESS_TOKEN_EXPIRE_MINUTES) return { "access_token": create_access_token(data={"username": form_data.username}, expires_delta=access_token_expires), "token_type": "bearer", }
def test_not_authenticate_user(): email = random_lower_string() password = random_lower_string() user = authenticate_user(bucket, email, password) assert user is False