A little Discord OAuth wrapper for Discord.
- Get a user's user, guild, and connection data.
- Generation of the authorization url.
- Revoking the access-token.
- Refreshing the access-token with refresh-token.
Initializing the OAuth builder.
import com.eazyftw.discordoauth.OAuthBuilder;
OAuthBuilder builder = new OAuthBuilder("clientID", "clientSecret")
.setScopes(new String[]{"connections", "guilds", "email", "identity"})
.setRedirectURI("redirectURL");
Getting a user response.
import com.eazyftw.discordoauth.objects.User;
import com.eazyftw.discordoauth.web.PostResponse;
PostResponse response = builder.exchange("code");
if(response == PostResponse.OK) {
User user = builder.getUser();
System.out.println(user.getId());
} else {
System.out.println("Response error.");
}
Refresh the access-token.
import com.eazyftw.discordoauth.objects.User;
import com.eazyftw.discordoauth.web.PostResponse;
PostResponse response = builder.refresh();
if (response == PostResponse.ERROR) {
System.out.println("Response error.");
} else {
// EXECUTE CODE
}
Revoke the access-token.
import com.eazyftw.discordoauth.objects.User;
import com.eazyftw.discordoauth.web.PostResponse;
PostResponse response = builder.revoke();
if (response == PostResponse.ERROR) {
System.out.println("Response error.");
} else {
// EXECUTE CODE
}
Be sure to replace the VERSION key below with the jitpack build number shown above, for example build-2
.
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.EazyFTW</groupId>
<artifactId>DiscordOAuth</artifactId>
<version>VERSION</version>
</dependency>
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.EazyFTW:DiscordOAuth:VERSION'
}
Just download the latest release here.