Skip to content

Commit 3b21e81

Browse files
committed
backup stuff
1 parent e638ef6 commit 3b21e81

File tree

5 files changed

+37
-35
lines changed

5 files changed

+37
-35
lines changed

build.gradle.kts

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
plugins {
2-
id("org.springframework.boot") version "2.5.1"
3-
id("io.spring.dependency-management") version "1.0.11.RELEASE"
4-
java
2+
id("org.springframework.boot") version "2.5.1"
3+
id("io.spring.dependency-management") version "1.0.11.RELEASE"
4+
java
55
}
66

77
repositories {
8-
mavenCentral()
8+
mavenCentral()
99
}
1010

1111
dependencies {
12-
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
13-
implementation("org.springframework.boot:spring-boot-starter-data-redis")
14-
implementation("org.springframework.boot:spring-boot-starter-data-rest")
15-
implementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server")
16-
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
17-
implementation("org.springframework.boot:spring-boot-starter-security")
18-
implementation("org.springframework.boot:spring-boot-starter-web")
19-
implementation("org.mariadb.jdbc:mariadb-java-client:2.7.3")
20-
21-
developmentOnly("org.springframework.boot:spring-boot-devtools")
22-
23-
testImplementation("org.springframework.boot:spring-boot-starter-test")
24-
testImplementation("org.springframework.security:spring-security-test")
25-
testImplementation("com.h2database:h2")
12+
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
13+
implementation("org.springframework.boot:spring-boot-starter-data-redis")
14+
implementation("org.springframework.boot:spring-boot-starter-data-rest")
15+
implementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server")
16+
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
17+
implementation("org.springframework.boot:spring-boot-starter-security")
18+
implementation("org.springframework.boot:spring-boot-starter-web")
19+
implementation("org.mariadb.jdbc:mariadb-java-client:3.0.5")
20+
implementation("com.h2database:h2:2.1.212")
21+
22+
developmentOnly("org.springframework.boot:spring-boot-devtools")
23+
24+
testImplementation("org.springframework.boot:spring-boot-starter-test")
25+
testImplementation("org.springframework.security:spring-security-test")
26+
testImplementation("com.h2database:h2")
2627
}
2728

2829

@@ -32,11 +33,11 @@ version = "0.0.1-SNAPSHOT"
3233
java.sourceCompatibility = JavaVersion.VERSION_16
3334

3435
tasks {
35-
withType<JavaCompile> {
36-
options.encoding = "UTF-8"
37-
}
36+
withType<JavaCompile> {
37+
options.encoding = "UTF-8"
38+
}
3839

39-
withType<Test> {
40-
useJUnitPlatform()
41-
}
40+
withType<Test> {
41+
useJUnitPlatform()
42+
}
4243
}

src/main/java/net/developerden/backend/controller/InfoController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
import net.developerden.backend.security.DiscordUser;
5-
import org.springframework.security.access.annotation.Secured;
65
import org.springframework.security.core.annotation.AuthenticationPrincipal;
76
import org.springframework.web.bind.annotation.GetMapping;
87
import org.springframework.web.bind.annotation.RestController;
@@ -12,7 +11,7 @@ public class InfoController {
1211

1312
@GetMapping("/user")
1413
public String user(@AuthenticationPrincipal DiscordUser principal) {
15-
return "Hello, %s (%s)".formatted(principal.fullName(), principal.id());
14+
return "Hello, %s (%s) with token %s".formatted(principal.fullName(), principal.id(), principal.token().getTokenValue());
1615
}
1716

1817
@GetMapping("/ping")

src/main/java/net/developerden/backend/security/DiscordUser.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.developerden.backend.security;
22

33
import org.springframework.security.core.GrantedAuthority;
4+
import org.springframework.security.oauth2.core.OAuth2AccessToken;
45
import org.springframework.security.oauth2.core.user.OAuth2User;
56

67
import java.util.Collection;
@@ -11,7 +12,9 @@
1112
/**
1213
* Java representation of all of the data that Discord gives us from the /users/@me API endpoint.
1314
*/
14-
public record DiscordUser(String id, String username, String discriminator, String locale) implements OAuth2User {
15+
public record DiscordUser(String id, String username, String discriminator,
16+
String locale,
17+
OAuth2AccessToken token) implements OAuth2User {
1518
public String fullName() {
1619
return username + "#" + discriminator;
1720
}

src/main/java/net/developerden/backend/security/DiscordUserService.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
2727

2828
final var entity = new HttpEntity<>(headers);
2929

30-
final var user = new RestTemplate()
31-
.exchange(DISCORD_USERINFO_URI, HttpMethod.GET,
32-
entity, DiscordUser.class)
30+
var user = new RestTemplate()
31+
.exchange(DISCORD_USERINFO_URI, HttpMethod.GET, entity, DiscordUser.class)
3332
.getBody();
34-
35-
return user;
33+
return new DiscordUser(user.id(), user.username(), user.discriminator(), user.locale(), userRequest.getAccessToken());
3634
}
3735
}

src/main/resources/application-test.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
spring:
22
jpa:
33
hibernate:
4-
ddl-auto: none
4+
ddl-auto: update
55
show-sql: true
6+
database-platform: org.hibernate.dialect.H2Dialect
67
datasource:
7-
url: jdbc:h2:~/testdb;DB_CLOSE_ON_EXIT=FALSE
8+
url: jdbc:h2:file:./testdb
89
username: user
910
password: pass
1011
driver-class-name: org.h2.Driver
@@ -17,7 +18,7 @@ spring:
1718
clientSecret: ${DDB_CLIENT_SECRET}
1819
authorizationGrantType: authorization_code
1920
redirectUri: "{baseUrl}/login/oauth2/code/discord"
20-
scope: identify
21+
scope: identify,applications.commands.permissions.update
2122
provider:
2223
discord:
2324
authorizationUri: https://discord.com/api/oauth2/authorize

0 commit comments

Comments
 (0)