Skip to content

First Example

This guide takes you from zero to a running Squizy application. Follow every step and you will have a working app with Google login and a fully managed entity.

1. Generate the Project

Go to start.squizy.io — the Squizy project initializer. It works like start.spring.io but pre-configured for Squizy.

  1. Fill in your project metadata (group, artifact, package name)
  2. In Dependencies, add OAuth2 Database and H2 (in-memory database for development)
  3. Click Generate Project to download a .zip file
  4. Extract the archive and open it in your IDE

2. Set Up Google OAuth2 Credentials

Squizy uses OAuth2 for authentication. You need a Google OAuth2 client:

  1. Go to the Google Cloud Console
  2. Create a new project (or select an existing one)
  3. Navigate to APIs & Services → Credentials
  4. Click Create Credentials → OAuth 2.0 Client ID
  5. Select Web application as the application type
  6. Under Authorized redirect URIs, add:
    http://localhost:8080/login/oauth2/code/google
  7. Click Create and copy the Client ID and Client Secret

TIP

If prompted to configure the OAuth consent screen first, select External, fill in the required fields (app name, user support email), and save. You can leave it in "Testing" mode for development.

3. Configure the Application

The only configuration you need is Google OAuth2. Edit src/main/resources/application.properties:

properties
# Google OAuth2
spring.security.oauth2.client.registration.google.client-id=YOUR_CLIENT_ID
spring.security.oauth2.client.registration.google.client-secret=YOUR_CLIENT_SECRET

# JWT token seed (use any random string; keeps tokens valid across restarts)
squizy.oauth2.token-seed=change-me-to-something-random

Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with the values from Google Cloud Console. Everything else (datasource, JPA settings) works out of the box with the H2 dependency you selected.

4. Enable Auto-Create Users

By default, Squizy rejects users that don't exist in its database. For this quickstart, configure auto-creation so that any Google user can log in and get a User role automatically.

Create a class in your project:

java
package com.example.myapp;

import io.twentyninetech.squizy.security.oauth2.database.SquizyGeneratedUsersDetailsProvider;
import io.twentyninetech.squizy.security.oauth2.database.GeneratedUserDetails;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class AutoCreateUsersProvider implements SquizyGeneratedUsersDetailsProvider {

    @Override
    public List<GeneratedUserDetails> getInitializationUsersDetails() {
        return List.of();
    }

    @Override
    public List<String> getOnDemandNewUserRoles(String email) {
        return List.of("User");
    }
}

With this in place, when a user logs in with Google for the first time, Squizy automatically creates the user record and assigns the User role.

5. Define an Entity

Create a JPA entity annotated with @SquizyEntity. This is all Squizy needs to generate the full CRUD API and UI:

java
@Entity
@SquizyEntity(displayFormat = "${name}")
public class Product {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull
    private String name;

    private String description;

    @NotNull
    private BigDecimal price;

    // getters and setters
}

Three fields, three different column types in the generated UI — text, long text, and number. Squizy handles the rest.

6. Run the Application

Start the application:

bash
./mvnw spring-boot:run

Open http://localhost:8080 in your browser. You will be redirected to Google's login page. After signing in, Squizy creates your user and you land on the application with a fully functional Product management view — table, create/edit forms, filters, search, and export — all generated from that single entity.

Next Steps