-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(provider): added google provider
- Loading branch information
1 parent
34fe3cb
commit e44419d
Showing
23 changed files
with
394 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
core/src/main/java/dev/cloudeko/zenei/infrastructure/config/AvailableProviders.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,53 +2,27 @@ | |
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import com.github.tomakehurst.wiremock.client.WireMock; | ||
import dev.cloudeko.zenei.extension.external.web.client.ExternalAccessToken; | ||
import dev.cloudeko.zenei.extension.external.web.external.discord.DiscordUser; | ||
import jakarta.ws.rs.core.Response; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class MockDiscordAuthorizationServerTestResource extends AbstractMockAuthorizationServerTestResource { | ||
|
||
private static final DiscordUser DISCORD_USER = new DiscordUser("12345L", "discord-user", "Discord Test User", "1234", | ||
"https://example.com/avatar.jpg", | ||
"[email protected]", true); | ||
|
||
@Override | ||
protected Map<String, String> providerSpecificStubsAndConfig(WireMockServer server) { | ||
final var testPort = ConfigProvider.getConfig().getOptionalValue("quarkus.http.test-port", Integer.class).orElse(8081); | ||
|
||
try { | ||
// Mock the Discord authorization URL | ||
server.stubFor(WireMock.get(WireMock.urlPathEqualTo("/discord/login/oauth/authorize")) | ||
.withQueryParam("client_id", WireMock.matching(".*")) | ||
.withQueryParam("redirect_uri", WireMock.matching(".*")) | ||
.withQueryParam("scope", WireMock.matching(".*")) | ||
.willReturn(WireMock.aResponse() | ||
.withStatus(Response.Status.FOUND.getStatusCode()) | ||
.withHeader("Location", | ||
"http://localhost:" + testPort + "/external/callback/discord?code=mock_code&state=mock_state"))); | ||
|
||
// Mock the Discord access token endpoint | ||
server.stubFor(WireMock.post(WireMock.urlPathEqualTo("/discord/login/oauth/access_token")) | ||
.withFormParam("client_id", WireMock.matching(".*")) | ||
.withFormParam("client_secret", WireMock.matching(".*")) | ||
.withFormParam("code", WireMock.matching(".*")) | ||
.withFormParam("grant_type", WireMock.matching(".*")) | ||
.withFormParam("redirect_uri", WireMock.matching(".*")) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withBody(objectMapper.writeValueAsString( | ||
new ExternalAccessToken("mock_access_token", 3600L, "mock_refresh_token", "user,email", | ||
"bearer") | ||
)))); | ||
|
||
// Mock the Discord user data endpoints | ||
server.stubFor(WireMock.get(WireMock.urlPathEqualTo("/discord/users/@me")) | ||
.withHeader("Authorization", WireMock.equalTo("Bearer mock_access_token")) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withBody(objectMapper.writeValueAsString( | ||
new DiscordUser("12345L", "discord-user", "Discord Test User", "1234", "https://example.com/avatar.jpg", | ||
"[email protected]", true) | ||
)))); | ||
.withHeader("Content-Type", MediaType.APPLICATION_JSON) | ||
.withBody(objectMapper.writeValueAsString(DISCORD_USER)))); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
@@ -58,11 +32,21 @@ protected Map<String, String> providerSpecificStubsAndConfig(WireMockServer serv | |
"zenei.external.auth.providers.discord.client-id", "mock_client_id", | ||
"zenei.external.auth.providers.discord.client-secret", "mock_client_secret", | ||
"zenei.external.auth.providers.discord.authorization-uri", | ||
server.baseUrl() + "/discord/login/oauth/authorize", | ||
server.baseUrl() + getFeaturePath(TestProviderFeature.AUTHORIZE), | ||
"zenei.external.auth.providers.discord.token-uri", | ||
server.baseUrl() + "/discord/login/oauth/access_token", | ||
"zenei.external.auth.providers.discord.redirect-uri", "http://localhost:8081/external/callback/discord", | ||
server.baseUrl() + getFeaturePath(TestProviderFeature.ACCESS_TOKEN), | ||
"zenei.external.auth.providers.discord.redirect-uri", getCallbackEndpoint(), | ||
"zenei.external.auth.providers.discord.scope", "user,email" | ||
); | ||
} | ||
|
||
@Override | ||
protected Set<TestProviderFeature> getFeatures() { | ||
return Set.of(TestProviderFeature.AUTHORIZE, TestProviderFeature.ACCESS_TOKEN); | ||
} | ||
|
||
@Override | ||
protected String getProvider() { | ||
return "discord"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.