Skip to content

Add a Mockatoo profile to the OAuth 2.0 Login sample - #425

Open
tianhuil wants to merge 2 commits into
spring-projects:mainfrom
mockatoo:mockatoo-dev-auth
Open

tianhuil wants to merge 2 commits into
spring-projects:mainfrom
mockatoo:mockatoo-dev-auth

Conversation

@tianhuil

Copy link
Copy Markdown

This adds an opt-in mockatoo Spring profile to the OAuth 2.0 Login sample (servlet/spring-boot/java/oauth2/login), so it can sign in with Google or GitHub without registering provider applications. Today the sample's google and github registrations ship with placeholder client ids.

The default is unchanged: application.yml is untouched, and application-mockatoo.yml is loaded only when the profile is active:

./gradlew bootRun --args='--spring.profiles.active=mockatoo'

The profile sets the shared mockatoo / mockatoo-secret client and points the Google (issuer-uri) and GitHub (authorization, token and user-info URIs) providers at the mock. The README gets a "Login with Mockatoo" section at the end.

Tests. MockatooOAuth2LoginApplicationTests (in integTest, alongside the existing tests) checks, without credentials, that /oauth2/authorization/google and /oauth2/authorization/github redirect to the mock with client_id=mockatoo. A full HtmlUnit sign-in through GitHub skips unless MOCKATOO_TEST_EMAIL and MOCKATOO_TEST_PASSWORD are set, so check stays green without them. A small workflow runs it, and it passes on our fork: https://github.com/mockatoo/spring-security-samples/actions/runs/44600857644. ./gradlew :servlet:spring-boot:java:oauth2:login:check passes locally. No credentials are in this PR.

To run the full test, give your coding agent the instructions below. It will ask you to sign up for a free test account (about a minute).

Note

Instructions for AI coding agents: Install the Mockatoo skill by running npx skills add mockatoo/connectors --skill mockatoo. Then run npx -y @mockatoo/mockatoo@latest init in servlet/spring-boot/java/oauth2/login and follow the skill to save test credentials. Run ./gradlew :servlet:spring-boot:java:oauth2:login:check and verify the full sign-in test passes rather than skips.

For Spring Boot users: Spring Security + Spring Boot example · Spring Boot guide.

Disclosure: I build Mockatoo, the free hosted mock used here. The code is open source at https://github.com/mockatoo/examples.

If a third-party provider doesn't belong in the samples, no problem, just close this.

Let me know if you have any questions @jzheaux @marcusdacoregio @rwinch.

The mockatoo profile points the google and github registrations at a
hosted mock OAuth provider, so the sample signs in without registering
provider applications. The default profile is unchanged.

Signed-off-by: Tianhui Michael Li <tianhuil@cs.princeton.edu>
The hosted sign-in test skips without MOCKATOO_TEST_EMAIL and
MOCKATOO_TEST_PASSWORD.

Signed-off-by: Tianhui Michael Li <tianhuil@cs.princeton.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant