Skip to content

EazyFTW/DiscordOAuth

Repository files navigation

Jitpack build GitHub licence GitHub issues GitHub forks GitHub stars

DiscordOAuth

A little Discord OAuth wrapper for Discord.

Features

  • 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.

Examples

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
}

Download

Be sure to replace the VERSION key below with the jitpack build number shown above, for example build-2.

Maven

<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>

Gradle

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

dependencies {
    implementation 'com.github.EazyFTW:DiscordOAuth:VERSION'
}

Release

Just download the latest release here.