Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Commit 6ac8b39

Browse files
committed
Fix twitch auth
1 parent 0919cc0 commit 6ac8b39

File tree

6 files changed

+28
-4
lines changed

6 files changed

+28
-4
lines changed

modules/twitch/auth/service/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
<version>${com.funixproductions.api.version}</version>
2626
</dependency>
2727

28+
<dependency>
29+
<groupId>com.funixproductions.api.twitch.eventsub.client</groupId>
30+
<artifactId>funixproductions-twitch-eventsub-client</artifactId>
31+
<version>${com.funixproductions.api.version}</version>
32+
</dependency>
33+
2834
<dependency>
2935
<groupId>com.funixproductions.api.encryption.client</groupId>
3036
<artifactId>funixproductions-encryption-client</artifactId>

modules/twitch/auth/service/src/main/java/com/funixproductions/api/twitch/auth/service/FunixProductionsTwitchAuthApp.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
@EnableFeignClients(basePackages = {
1010
"com.funixproductions.api.user",
1111
"com.funixproductions.api.twitch.auth.service",
12-
"com.funixproductions.api.encryption"
12+
"com.funixproductions.api.twitch.eventsub.client",
13+
"com.funixproductions.api.encryption",
1314
})
1415
@SpringBootApplication(scanBasePackages = "com.funixproductions")
1516
public class FunixProductionsTwitchAuthApp {

modules/twitch/auth/service/src/main/java/com/funixproductions/api/twitch/auth/service/services/TwitchClientTokenService.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.funixproductions.api.twitch.auth.service.entities.TwitchClientToken;
1313
import com.funixproductions.api.twitch.auth.service.mappers.TwitchClientTokenMapper;
1414
import com.funixproductions.api.twitch.auth.service.repositories.TwitchClientTokenRepository;
15+
import com.funixproductions.api.twitch.eventsub.client.clients.TwitchEventSubInternalClient;
1516
import com.funixproductions.api.user.client.dtos.UserDTO;
1617
import com.funixproductions.api.user.client.security.CurrentSession;
1718
import com.funixproductions.core.exceptions.ApiBadRequestException;
@@ -46,6 +47,7 @@ public class TwitchClientTokenService {
4647
private final TwitchClientTokenMapper twitchClientTokenMapper;
4748
private final TwitchTokenAuthClient twitchTokenAuthClient;
4849
private final TwitchValidTokenClient validTokenClient;
50+
private final TwitchEventSubInternalClient twitchEventSubInternalClient;
4951

5052
private final PasswordGenerator passwordGenerator;
5153
private final CurrentSession currentSession;
@@ -67,14 +69,16 @@ public TwitchClientTokenService(TwitchAuthConfig twitchAuthConfig,
6769
TwitchTokenAuthClient twitchTokenAuthClient,
6870
CurrentSession currentSession,
6971
TwitchApiConfig twitchApiConfig,
70-
TwitchValidTokenClient twitchValidTokenClient) {
72+
TwitchValidTokenClient twitchValidTokenClient,
73+
TwitchEventSubInternalClient twitchEventSubInternalClient) {
7174
this.twitchClientTokenRepository = twitchClientTokenRepository;
7275
this.twitchAuthConfig = twitchAuthConfig;
7376
this.twitchTokenAuthClient = twitchTokenAuthClient;
7477
this.twitchClientTokenMapper = twitchClientTokenMapper;
7578
this.currentSession = currentSession;
7679
this.validTokenClient = twitchValidTokenClient;
7780
this.twitchApiConfig = twitchApiConfig;
81+
this.twitchEventSubInternalClient = twitchEventSubInternalClient;
7882

7983
this.passwordGenerator = new PasswordGenerator();
8084
passwordGenerator.setSpecialCharsAmount(0);
@@ -361,7 +365,11 @@ private TwitchClientTokenDTO refreshToken(final TwitchClientToken token) {
361365
}
362366

363367
private void createEventSub(final String streamerName) {
364-
368+
try {
369+
this.twitchEventSubInternalClient.createSubscription(streamerName);
370+
} catch (Exception e) {
371+
log.error("Error while creating event sub for streamer {}", streamerName, new ApiException("Error while creating event sub for streamer " + streamerName, e));
372+
}
365373
}
366374

367375
}

modules/twitch/auth/service/src/test/java/com/funixproductions/api/twitch/auth/service/resources/TwitchAuthResourceTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.funixproductions.api.twitch.auth.service.clients.TwitchValidTokenClient;
77
import com.funixproductions.api.twitch.auth.service.dtos.TwitchTokenResponseDTO;
88
import com.funixproductions.api.twitch.auth.service.dtos.TwitchValidationTokenResponseDTO;
9+
import com.funixproductions.api.twitch.eventsub.client.clients.TwitchEventSubInternalClient;
910
import com.funixproductions.api.user.client.clients.UserAuthClient;
1011
import com.funixproductions.api.user.client.dtos.UserDTO;
1112
import com.funixproductions.api.user.client.enums.UserRole;
@@ -48,6 +49,9 @@ class TwitchAuthResourceTest {
4849
@MockitoBean
4950
private EncryptionClient encryptionClient;
5051

52+
@MockitoBean
53+
private TwitchEventSubInternalClient twitchEventSubInternalClient;
54+
5155
@Autowired
5256
private MockMvc mockMvc;
5357

@@ -80,6 +84,8 @@ void setupFeignClients() {
8084

8185
Mockito.when(this.encryptionClient.decrypt(anyString())).thenReturn(UUID.randomUUID().toString());
8286
Mockito.when(this.encryptionClient.encrypt(anyString())).thenReturn(UUID.randomUUID().toString());
87+
88+
Mockito.doNothing().when(twitchEventSubInternalClient).createSubscription(anyString());
8389
}
8490

8591
@Test

modules/twitch/eventsub/service/src/main/java/com/funixproductions/api/twitch/eventsub/service/services/TwitchEventSubReferenceService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public void createSubscription(@NonNull final TwitchSubscription request) throws
7676
} else if (statusCode == 429) {
7777
throw new ApiException("Erreur 429 Too Many Requests (rate limit) de Twitch lors de la création d'une subscription Twitch.", e);
7878
} else if (statusCode == 409) {
79-
throw new ApiException(String.format(
79+
log.info("Erreur 409 Conflict de Twitch lors de la création d'une subscription Twitch. Event {} déjà existant.", request.getType());
80+
throw new ApiBadRequestException(String.format(
8081
"Erreur 409 Conflict de Twitch lors de la création d'une subscription Twitch. Event %s déjà existant.",
8182
request.getType()
8283
), e);

modules/twitch/eventsub/service/src/main/java/com/funixproductions/api/twitch/eventsub/service/services/TwitchEventSubRegistrationService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public void handleOnePendingSubscriptionFromQueue() {
5757

5858
if (subscription != null) {
5959
this.twitchEventSubReferenceService.createSubscription(subscription);
60+
log.info("Subscription created for type {} with payload {}.", subscription.getType(), subscription.getPayload());
6061
}
6162
}
6263

@@ -66,6 +67,7 @@ public void handleOnePendingUnsubscriptionFromQueue() {
6667

6768
if (subscriptionId != null) {
6869
this.twitchEventSubReferenceService.deleteSubscription(subscriptionId);
70+
log.info("Subscription deleted with id {}.", subscriptionId);
6971
}
7072
}
7173

0 commit comments

Comments
 (0)