Skip to content

Instantly share code, notes, and snippets.

@stefanozanella
Last active August 27, 2022 20:08
Show Gist options
  • Save stefanozanella/78821e36380e4218787fd19f18f006b7 to your computer and use it in GitHub Desktop.
Save stefanozanella/78821e36380e4218787fd19f18f006b7 to your computer and use it in GitHub Desktop.
dependencies {
// ...
implementation("org.springframework.boot:spring-boot-starter-jdbc")
implementation("org.flywaydb:flyway-core") // Optional, but highly recommended
implementation("org.postgresql:postgresql") // Add the driver for your favourite database here
}
spring:
# ...
datasource:
url: jdbc:postgresql://localhost:5432/demo-app-oauth2-webhooks
username: stefano
password:
; -- src/main/resources/db/migration/V1__Add_oauth2_authorized_client_table.sql
CREATE TABLE oauth2_authorized_client
(
client_registration_id varchar(100) NOT NULL,
principal_name varchar(200) NOT NULL,
access_token_type varchar(100) NOT NULL,
access_token_value bytea NOT NULL,
access_token_issued_at timestamp NOT NULL,
access_token_expires_at timestamp NOT NULL,
access_token_scopes varchar(1000) DEFAULT NULL,
refresh_token_value bytea DEFAULT NULL,
refresh_token_issued_at timestamp DEFAULT NULL,
created_at timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (client_registration_id, principal_name)
);
@Configuration
class WebSecurityConfig {
// ...
@Bean
fun authorizedClientService(
jdbcOperations: JdbcOperations,
clientRegistrationRepository: ClientRegistrationRepository,
): OAuth2AuthorizedClientService =
JdbcOAuth2AuthorizedClientService(jdbcOperations, clientRegistrationRepository)
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment