def test_debug(): from app_utils import create_access_token from datetime import timedelta access_token_expires = timedelta(minutes=10) access_token = create_access_token(data={"sub": "cuongld"}, expires_delta=access_token_expires) print(access_token) from app_utils import decode_access_token decoded_access_token = decode_access_token(data=access_token) print(decoded_access_token)
def mutate(root, info, token, title): query = AnimeSchema.get_query(info) try: payload = decode_access_token(data=token) username: str = payload.get("sub") if username is None: raise GraphQLError("Invalid credentials") token_data = TokenData(username=username) except PyJWTError: raise GraphQLError("Invalid credentials") user = crud.get_user_by_username(db, username=token_data.username) if user is None: raise GraphQLError("Invalid credentials") AnimeSearch = route_optima_search(query, title, str(title)) return SearchAnime(AnimeSearch=AnimeSearch)
def mutate(root, info, title, content, token): try: payload = decode_access_token(data=token) username: str = payload.get("sub") if username is None: raise GraphQLError("Invalid credentials") token_data = TokenData(username=username) except PyJWTError: raise GraphQLError("Invalid credentials") user = crud.get_user_by_username(db, username=token_data.username) if user is None: raise GraphQLError("Invalid credentials") blog = BlogBase(title=title, content=content) crud.create_new_blog(db=db, blog=blog) ok = True return CreateNewBlog(ok=ok)
def mutate(root, info, token): query = AnimeSchema.get_query(info) try: payload = decode_access_token(data=token) username: str = payload.get("sub") if username is None: raise GraphQLError("Invalid credentials") token_data = TokenData(username=username) except PyJWTError: raise GraphQLError("Invalid credentials") user = crud.get_user_by_username(db, username=token_data.username) if user is None: raise GraphQLError("Invalid credentials") AnimeList = route_optima(query, "allanime") return GetAnimeList(AnimeList=AnimeList)
async def get_current_user(token: str = Depends(oauth2_scheme), db: Session = Depends(get_db)): credentials_exception = HTTPException( status_code = status.HTTP_401_UNAUTHORIZED, detail = "Could not validate credentials", headers = {"WWW-Authenticate": "Bearer"}, ) try: payload = decode_access_token(data=token) username: str = payload.get("sub") if username is None: raise credentials_exception token_data = TokenData(username=username) except PyJWTError: raise credentials_exception user = get_user_by_username(db, username=token_data.username) if user is None: raise credentials_exception return user