Skip to content

Document OIDC authentication testing in HttpGraphQlTester #1260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions spring-graphql-docs/modules/ROOT/pages/testing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ existing `HttpSocketGraphQlTester` to create a new instance with customized sett

include-code::HttpSetup[tag=executeRequests,indent=0]

If you need to test with OIDC (OpenID Connect) authentication, you can use Spring Security's `mockOidcLogin()` to create a mock OIDC user:

include-code::HttpSetup[tag=oidcAuthentication,indent=0]



[[testing.websocketgraphqltester]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ void executeRequests() {
// end::executeRequests[]
}

void oidcAuthentication() {
// tag::oidcAuthentication[]
// Note: This requires spring-security-test dependency
WebTestClient client = WebTestClient.bindToServer()
.baseUrl("http://localhost:8080/graphql")
.build();

// The following code demonstrates how to use mockOidcLogin() with HttpGraphQlTester
// You need to add spring-security-test, spring-security-oauth2-client, and spring-security-oauth2-jose dependencies
/*
import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers;

HttpGraphQlTester tester = HttpGraphQlTester.create(
client.mutateWith(
SecurityMockServerConfigurers.mockOidcLogin()
.oidcUser(yourOidcUser())
)
);
*/

// For documentation purposes only, this is a simplified version
WebTestClient mutatedClient = client; // In real code, this would be client.mutateWith(mockOidcLogin().oidcUser(yourOidcUser()))
HttpGraphQlTester tester = HttpGraphQlTester.create(mutatedClient);
// end::oidcAuthentication[]
}

static class Configuration {

}
Expand Down