Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
fastapi-discord
Readme
Support for "Login with Discord"/ Discord OAuth for FastAPI.
PIP Package fastapi-discord
You can find the Example in expamples/
from typing import List
from fastapi import Depends, FastAPI
from fastapi.responses import JSONResponse
from fastapi_discord import DiscordOAuthClient, RateLimited, Unauthorized, User
from fastapi_discord.exceptions import ClientSessionNotInitialized
from fastapi_discord.models import GuildPreview
app = FastAPI()
discord = DiscordOAuthClient(
"<client-id>", "<client-secret>", "<redirect-url>", ("identify", "guilds", "email")
) # scopes
@app.on_event("startup")
async def on_startup():
await discord.init()
@app.get("/login")
async def login():
return {"url": discord.oauth_login_url}
@app.get("/callback")
async def callback(code: str):
token, refresh_token = await discord.get_access_token(code)
return {"access_token": token, "refresh_token": refresh_token}
@app.get(
"/authenticated",
dependencies=[Depends(discord.requires_authorization)],
response_model=bool,
)
async def isAuthenticated(token: str = Depends(discord.get_token)):
try:
auth = await discord.isAuthenticated(token)
return auth
except Unauthorized:
return False
@app.exception_handler(Unauthorized)
async def unauthorized_error_handler(_, __):
return JSONResponse({"error": "Unauthorized"}, status_code=401)
@app.exception_handler(RateLimited)
async def rate_limit_error_handler(_, e: RateLimited):
return JSONResponse(
{"error": "RateLimited", "retry": e.retry_after, "message": e.message},
status_code=429,
)
@app.exception_handler(ClientSessionNotInitialized)
async def client_session_error_handler(_, e: ClientSessionNotInitialized):
print(e)
return JSONResponse({"error": "Internal Error"}, status_code=500)
@app.get("/user", dependencies=[Depends(discord.requires_authorization)], response_model=User)
async def get_user(user: User = Depends(discord.user)):
return user
@app.get(
"/guilds",
dependencies=[Depends(discord.requires_authorization)],
response_model=List[GuildPreview],
)
async def get_guilds(guilds: List = Depends(discord.guilds)):
return guilds
Thanks to @jnawk and @nwunderly
FAQs
Discord OAuth FastAPI extension for APIs
We found that fastapi-discord demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.