Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:21-slim
FROM amazoncorretto:21-alpine

ARG service_name
ARG service_base_dir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.bean.override.mockito.MockitoBean;

import java.util.List;
import java.util.Random;
Expand All @@ -30,16 +30,16 @@ class AccountingServiceTest {
@Autowired
private AccountingService accountingService;

@MockBean
@MockitoBean
private IncomeRepository incomeRepository;

@MockBean
@MockitoBean
private ProductRepository productRepository;

@MockBean
@MockitoBean
private GoogleGmailClient gmailClient;

@MockBean
@MockitoBean
private BillingFeignInternalClient billingClient;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import javax.annotation.Nullable;

@Getter
@RequiredArgsConstructor
public enum FrontOrigins {
FUNIX_PRODUCTIONS_DASHBOARD(
"funixproductions-dashboard",
"Dashboard Funix Productions",
"https://dashboard.funixproductions.com",
"http://localhost:4200"
"https://dev.dashboard.funixproductions.com"
),
PACIFISTA_PUBLIC_WEB(
"pacifista-public-web",
Expand All @@ -25,7 +27,8 @@ public enum FrontOrigins {
private final String domainProd;
private final String domainDev;

public static FrontOrigins getRedirectAuthOrigin(String origin) {
@Nullable
public static FrontOrigins getRedirectAuthOrigin(@Nullable String origin) {
if (Strings.isNullOrEmpty(origin)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;

import static org.mockito.ArgumentMatchers.anyString;
Expand All @@ -25,7 +25,7 @@ class GoogleCaptchaResourceTest {
@Autowired
private MockMvc mockMvc;

@MockBean
@MockitoBean
private GoogleRecaptchaClient googleRecaptchaClient;

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import com.funixproductions.core.crud.dtos.PageDTO;
import com.funixproductions.core.tools.pdf.tools.VATInformation;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.test.context.bean.override.mockito.MockitoBean;

import java.util.Date;
import java.util.List;
Expand All @@ -24,10 +24,10 @@

public abstract class BillingResourceTest {

@MockBean
@MockitoBean
protected UserAuthClient userAuthClient;

@MockBean
@MockitoBean
protected BillingCrudService billingCrudService;

protected final BillingDTO billingDTO = new BillingDTO();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.bean.override.mockito.MockitoBean;

import java.io.File;
import java.time.LocalDate;
Expand All @@ -41,10 +41,10 @@ class BillingCrudServiceTest {
@Autowired
private BillingRepository billingRepository;

@MockBean
@MockitoBean
private CurrentSession currentSession;

@MockBean
@MockitoBean
private GoogleGmailClient googleGmailClient;

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.bean.override.mockito.MockitoBean;

import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
Expand All @@ -28,7 +28,7 @@
@AutoConfigureMockMvc
class PaypalAccessTokenServiceTest {

@MockBean
@MockitoBean
private PaypalAuthClient paypalAuthClient;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;

Expand All @@ -40,13 +40,13 @@ class PaypalOrderResourceTest {
@Autowired
private MockMvc mockMvc;

@MockBean
@MockitoBean
private PaypalOrderService service;

@Autowired
private JsonHelper jsonHelper;

@MockBean
@MockitoBean
private BillingFeignInternalClient billingClient;

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.bean.override.mockito.MockitoBean;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
Expand All @@ -26,10 +26,10 @@
@AutoConfigureMockMvc
class PaypalOrderServiceTest {

@MockBean
@MockitoBean
private PaypalFeignOrderClient orderClient;

@MockBean
@MockitoBean
private PaypalAccessTokenService tokenService;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.funixproductions.api.twitch.auth.client.clients;

import com.funixproductions.api.twitch.auth.client.dtos.TwitchClientTokenDTO;
import lombok.NonNull;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Nullable;

@FeignClient(
name = "TwitchAuthClient",
url = "${funixproductions.api.twitch.auth.app-domain-url}",
Expand All @@ -13,9 +16,14 @@
public interface TwitchAuthClient {

@GetMapping("clientAuthUrl")
String getAuthClientUrl(@RequestParam(defaultValue = "VIEWER") String tokenType);
String getAuthClientUrl(
@RequestParam(defaultValue = "VIEWER") @NonNull String tokenType,
@RequestParam(required = false) @Nullable String origin
);

@GetMapping("accessToken")
TwitchClientTokenDTO getAccessToken();
TwitchClientTokenDTO getAccessToken(
@RequestParam(defaultValue = "VIEWER") @NonNull String tokenType
);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.funixproductions.api.twitch.auth.client.clients;

import com.funixproductions.api.twitch.auth.client.dtos.TwitchClientTokenDTO;
import lombok.NonNull;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -13,13 +14,22 @@
public interface TwitchInternalAuthClient {

@GetMapping("client")
TwitchClientTokenDTO fetchToken(@RequestParam String userUUID);
TwitchClientTokenDTO fetchToken(
@RequestParam String userUUID,
@RequestParam(defaultValue = "VIEWER") @NonNull String tokenType
);

@GetMapping("clientByStreamerName")
TwitchClientTokenDTO fetchTokenByStreamerName(@RequestParam String streamerName);
TwitchClientTokenDTO fetchTokenByStreamerName(
@RequestParam String streamerName,
@RequestParam(defaultValue = "VIEWER") @NonNull String tokenType
);

@GetMapping("clientByStreamerId")
TwitchClientTokenDTO fetchTokenByStreamerId(@RequestParam String streamerId);
TwitchClientTokenDTO fetchTokenByStreamerId(
@RequestParam String streamerId,
@RequestParam(defaultValue = "VIEWER") @NonNull String tokenType
);

@GetMapping("server")
String fetchServerToken();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.funixproductions.api.twitch.auth.client.dtos;

import com.funixproductions.api.twitch.auth.client.enums.TwitchClientTokenType;
import com.funixproductions.core.crud.dtos.ApiDTO;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -12,6 +13,7 @@
@Getter
@Setter
public class TwitchClientTokenDTO extends ApiDTO {

private UUID userUuid;

private String twitchUserId;
Expand All @@ -24,6 +26,8 @@ public class TwitchClientTokenDTO extends ApiDTO {

private Date expirationDateToken;

private TwitchClientTokenType tokenType;

public String getUserUuid() {
if (this.userUuid == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
package com.funixproductions.api.twitch.auth.client.enums;

import com.google.common.base.Strings;
import lombok.AllArgsConstructor;
import lombok.Getter;

import javax.annotation.Nullable;

@Getter
@AllArgsConstructor
public enum TwitchClientTokenType {
STREAMER,
MODERATOR,
BOT,
VIEWER
FUNIXGAMING(true),
STREAMER(true),
VIEWER(false);

private boolean needRegisterEvents;

public static TwitchClientTokenType getTokenTypeByString(@Nullable final String tokenType) {
if (Strings.isNullOrEmpty(tokenType)) {
return TwitchClientTokenType.VIEWER;
}

for (final TwitchClientTokenType token : TwitchClientTokenType.values()) {
if (token.name().equalsIgnoreCase(tokenType)) {
return token;
}
}

return TwitchClientTokenType.VIEWER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ public interface TwitchTokenAuthClient {
@PostMapping("token")
@Headers("Content-Type: application/x-www-form-urlencoded")
TwitchTokenResponseDTO getToken(Map<String, String> formParams);

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public TwitchValidationTokenResponseDTO makeHttpRequestValidation(final String a
httpRequest.setHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
httpRequest.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken);

try {
try (final HttpClient httpClient = HttpClient.newHttpClient()) {
final HttpRequest request = httpRequest.build();
final HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
final HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
final int status = response.statusCode();

if (Integer.toString(status).startsWith("2")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public class TwitchAuthConfig {
*/
private String appCallbackDomain = "https://api.funixproductions.com";

/**
* To know if the API is in dev mode or not
*/
private Boolean devMode = false;

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.funixproductions.api.twitch.auth.service.entities;

import com.funixproductions.api.encryption.client.utils.EncryptionString;
import com.funixproductions.api.twitch.auth.client.enums.TwitchClientTokenType;
import com.funixproductions.core.crud.entities.ApiEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;

Expand Down Expand Up @@ -43,6 +42,10 @@ public class TwitchClientToken extends ApiEntity {
@Column(name = "expiration_date_token", nullable = false)
private Date expirationDateToken;

@Enumerated(EnumType.STRING)
@Column(name = "token_type", nullable = false)
private TwitchClientTokenType tokenType;

public boolean isUsable() {
return Instant.now().isBefore(expirationDateToken.toInstant());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.funixproductions.api.twitch.auth.service.repositories;

import com.funixproductions.api.twitch.auth.client.enums.TwitchClientTokenType;
import com.funixproductions.api.twitch.auth.service.entities.TwitchClientToken;
import com.funixproductions.core.crud.repositories.ApiRepository;
import org.springframework.stereotype.Repository;
Expand All @@ -8,7 +9,7 @@

@Repository
public interface TwitchClientTokenRepository extends ApiRepository<TwitchClientToken> {
Optional<TwitchClientToken> findTwitchClientTokenByUserUuid(String userUuid);
Optional<TwitchClientToken> findTwitchClientTokenByTwitchUsername(String username);
Optional<TwitchClientToken> findTwitchClientTokenByTwitchUserId(String streamerId);
Optional<TwitchClientToken> findTwitchClientTokenByUserUuidAndTokenType(String userUuid, TwitchClientTokenType tokenType);
Optional<TwitchClientToken> findTwitchClientTokenByTwitchUsernameAndTokenType(String username, TwitchClientTokenType tokenType);
Optional<TwitchClientToken> findTwitchClientTokenByTwitchUserIdAndTokenType(String streamerId, TwitchClientTokenType tokenType);
}
Loading
Loading