Skip to content

Commit

Permalink
deploy: Fix getAuthOriginFromOriginHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
giovanni-orciuolo committed Feb 14, 2024
1 parent 317273d commit 3ddbb32
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ public class OAuthAccessToken {
public String access_token;
public String token_type;
public String scope;

public String error;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.apache.tomcat.util.codec.binary.Base64;
import org.kohsuke.github.GitHub;
import org.kohsuke.github.GitHubBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -42,6 +44,8 @@ public class AuthServiceImpl implements AuthService {
@Value("${ckb.test}")
private Boolean isTest;

Logger logger = LoggerFactory.getLogger(AuthServiceImpl.class);

private OAuthConfig getOAuthConfig(AuthOrigin authOrigin) {
final HashMap<AuthOrigin, OAuthConfig> oauthConfigMap = new HashMap<>() {{
put(AuthOrigin.SWAGGER, new OAuthConfig(swaggerClientId, swaggerClientSecret));
Expand All @@ -65,6 +69,7 @@ public OAuthAccessToken handleOAuthCallback(String code, AuthOrigin authOrigin)
throw new OAuthException("Failed to obtain access token from GitHub");
}
if (response.getBody() == null || response.getBody().access_token == null) {
logger.error("Error from GitHub: " + response.getBody().error);
throw new OAuthException("Invalid response body");
}

Expand Down Expand Up @@ -117,6 +122,9 @@ public AuthOrigin getAuthOriginFromOriginHeader(String origin) {
if (origin.contains("localhost:5173")) {
return AuthOrigin.FRONTEND;
}
if (origin.contains("codekatabattle.onrender.com")) {
return AuthOrigin.FRONTEND;
}

return AuthOrigin.SWAGGER;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ spring.datasource.hikari.maximumPoolSize=500
spring.datasource.hikari.connectionTimeout=30000
spring.datasource.hikari.idleTimeout=600000
spring.datasource.hikari.maxLifetime=1800000
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

# The ddl-auto property is used to automatically create the database schema
# Usually, in production, a migration tool like Liquibase or Flyway is used to manage the database schema
Expand Down

0 comments on commit 3ddbb32

Please sign in to comment.