A small Discord OAuth2 API wrapper for Java.
- Generates the authorization URL.
- Code authorization for access token and refresh token.
- Refresh the access token with refresh token.
- Get the user, guilds, and connection info of a user from access token.
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.Mokulu</groupId>
<artifactId>discord-oauth2-api</artifactId>
<version>1.0.2</version>
</dependency>
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.Mokulu:discord-oauth2-api:1.0.2'
}
import io.mokulu.discord.oauth.DiscordOAuth;
DiscordOAuth oauthHandler = new DiscordOAuth(clientID: String, clientSecret: String, redirectUri: String, scope: String[]);
String authURL = oauthHandler.getAuthorizationURL(state: String);
state
will be ingored by passing null.
import io.mokulu.discord.oauth.model.TokensResponse;
TokensResponse tokens = oauthHandler.getTokens(code: String);
String accessToken = tokens.getAccessToken();
String refreshToken = tokens.getRefreshToken();
TokensResponse tokens = oauthHandler.refreshTokens(refresh_token: String);
import io.mokulu.discord.oauth.DiscordAPI;
DiscordAPI api = new DiscordAPI(access_token: String);
The following API fetch calls will throw IOException (HttpStatusException)
when access is denied due to invalid scope or expired token.
Scope identity
is required.
Scope email
is required for email
and verified
values.
import io.mokulu.discord.oauth.model.User;
User user = api.fetchUser();
Scope guilds
is required.
import io.mokulu.discord.oauth.model.Guild;
List<Guild> guilds = api.fetchGuilds();
Scope connections
is required.
import io.mokulu.discord.oauth.model.Connection;
List<Connection> connections = api.fetchConnections();