Skip to main content

Harmony Auth

Discord OAuth2 Implicit Grant thingy for FastAPI.

Tokens are cached in Redis with the user's information & guilds (if enabled)

Yes. I know this is a mess. :)

Server Usage

from harmony_auth import HarmonyAuth
from fastapi import FastAPI, Depends

auth = HarmonyAuth()
app = FastAPI()


@app.get('/secure')
async def secure_route(user=Depends(auth)):
    return user

Client Usage

  1. Request an implicit grant access token from Discord
  2. Pass received access_token to any endpoint with the Harmony Auth dependency to login and access resources.
curl -X GET --location "http://127.0.0.1:8000/secure" \
    -H "Accept: application/json" \
    -H "Authorization: Bearer {{access_token}}"

Reload User Data

If you need to reload the user's data in the cache (if they joined a guild, for example), call get_user(token, force_fetch=True)

Example:

@app.get("/refresh")
async def refresh_user_data(token: str = Depends(auth.token)):
    user = await auth.get_user(token, force_fetch=True)
    ...

This will update the cache and return the user.

Log Out / Revoke token

Use revoke_token(token) to remove user data from the cache. This removes all the cached user information.

If you specify a client_id and client_secret, Harmony Auth will request that Discord revokes the token.

Q: How do I log in?

A: You don't need to log in. Just provide a valid access token.

Rate limit protections

I personally don't want to handle this, so I am using twilight-http-proxy.

TODO: Create fork to add OAuth2 routes to twilight http proxy.

Metadata

Release files for harmony-auth 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for harmony-auth 0.1.5
File Size Uploaded
harmony_auth-0.1.5.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for harmony-auth 0.1.5
File Interpreter ABI Platform
harmony_auth-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / harmony_auth-0.1.5.tar.gz

Download URL harmony_auth-0.1.5.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1cb65399fcb84db1a86cfaa99f4590a243fe082c00fcb2ebb808f5d940663d89
BLAKE2b-256 checksum
How to use checksums
795ff60521a92ca17711b21a6498b8fec7ef4e0ebe6d9a50b6c6045bb89f922d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.0b3 CPython/3.9.13 Darwin/21.6.0

Release files / harmony_auth-0.1.5-py3-none-any.whl

Download URL harmony_auth-0.1.5-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96ef6deeb4f081865d6ad2a2f9f0a55cd4065fbd6a6bbdbf915d9469b075894e
BLAKE2b-256 checksum
How to use checksums
890c8633e5572402915836744ba76aef531bb25c485bd05ea814406ca90ee916
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.0b3 CPython/3.9.13 Darwin/21.6.0

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page