This project is a Proof of Concept (PoC) that implements a small portion of the Discord OAuth2 flow and Rich Presence updates via the Discord Gateway WebSocket.
-
Add it to your root
build.gradleat the end of repositories:allprojects { repositories { ... maven { url 'https://jitpack.io' } } } -
Add the dependency (in your Java / Kotlin / Android project)
dependencies { implementation("com.github.UsagiApp:OAuth2-RPC:$version") }Versions are available on JitPack
When used in Android projects, core library desugaring with the NIO specification should be enabled to support Java 8+ features.
The core library (in library/src/main/kotlin/com/discord/oauth2rpc/) provides:
| Component | Description |
|---|---|
Gateway.kt |
Discord Gateway WebSocket client (Ktor + coroutines) |
Rest.kt |
REST API client with dynamic route builder |
Interface.kt |
TokenResponse, GatewayPacket, ReadyEvent, etc. |
structures/Presence.kt |
RichPresence, CustomStatus, SpotifyRPC builders |
utils/ |
BitField, Intents, GatewayCapabilities, ActivityFlags, Constants, Util |
okhttp— HTTP & WebSocketorg.json:json— JSON parsingkotlinx-coroutines— async concurrency
- JDK 17+
- Gradle (or use the included wrapper)
Go to the Discord Developer Portal and create a new Application.
Fill out the Social SDK registration form (Games > Social SDK) to unlock this feature for your Application.
- Go to the newly created Application > Select the OAuth2 tab.
- Enable the "Public Client" setting.
- Add your Redirects URL to the list (
usagi://discord-authORkotatsu://discord-auth), depends on your application.
Note
The bearer token remains valid for up to 7 days. You can use the refresh flow to renew its expiration and continue using the token.
- Original TS implementation by Elysia.
- Rewritten in Kotlin by Hà Tiến Sáng, modified by Draken.
