Discord OAuth2 API wrapper for Java, for creating apps using discord account as authentication.
Important thing to know is that the library only supports discord scopes "identify, guilds, email".
Please see ApplicationInfo#getAuthCode to understand how actually to implement your discord application with this library.
Installing JDOA2 is just like every other dependency:
Maven:
<repositories>
<repository>
<id>ivan</id>
<url>https://repo.mrivanplays.com/repository/ivan/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.mrivanplays</groupId>
<artifactId>jdoa2</artifactId>
<version>VERSION</version> <!-- Replace with latest version -->
<scope>compile</scope>
</dependency>
</dependencies>
Gradle:
repositories {
maven {
url "https://repo.mrivanplays.com/repository/ivan/"
}
}
dependencies {
implementation 'com.mrivanplays:jdoa2:VERSION' // Replace VERSION with latest version
}
Example spring controller:
@Controller
public class TestController {
@GetMapping("/")
public ResponseEntity<CurrentUser> render(@RequestParam(value = "code", required = false, defaultValue = "") String authCode) {
if (authCode.isEmpty()) {
return ResponseEntity.ok(
new CurrentUser("0", "unknown", "unknown", "unknown",
false, false, false, "unknown", "unknown", 0)
);
}
JDOA2 jdoa2 = JDOA2.builder()
.applicationInfo(
ApplicationInfo.builder()
.clientId("exampleClientId")
.clientSecret("exampleClientSecret")
.redirectUri("http://exampleRedirect.uri/")
.authCode(authCode)
.build()
)
.build();
jdoa2.doTokenExchange();
return ResponseEntity.ok(jdoa2.getCurrentUser().execute());
}
}
Can be found here