Skip to content

Instantly share code, notes, and snippets.

View stefanozanella's full-sized avatar

Stefano Zanella stefanozanella

View GitHub Profile
@RestController
class WebhooksController {
// ...
@Autowired
private lateinit var authorizedClientService: OAuth2AuthorizedClientService
@PostMapping("/webhooks/hubspot")
fun hubspot(@RequestBody events: List<Map<String, String>>) {
events
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
}
client
// ...
.attributes(
ServerOAuth2AuthorizedClientExchangeFilterFunction
.oauth2AuthorizedClient(
authorizedClientService.loadAuthorizedClient("hubspot", event["portalId"])
)
)
.retrieve()
.bodyToMono<String>()
@Bean
fun webClient(authorizedClientManager: OAuth2AuthorizedClientManager): WebClient =
WebClient
.builder()
.apply(
ServletOAuth2AuthorizedClientExchangeFilterFunction(
authorizedClientManager
).oauth2Configuration()
)
.build()
@Bean
fun authorizedClientManager(
clientRegistrationRepository: ClientRegistrationRepository,
authorizedClientService: OAuth2AuthorizedClientService,
) =
AuthorizedClientServiceOAuth2AuthorizedClientManager(
clientRegistrationRepository,
authorizedClientService,
).apply {
setAuthorizedClientProvider(
@Bean
fun authorizedClientManager(
clientRegistrationRepository: ClientRegistrationRepository,
authorizedClientService: OAuth2AuthorizedClientService,
) =
AuthorizedClientServiceOAuth2AuthorizedClientManager(
clientRegistrationRepository,
authorizedClientService,
).apply {
setAuthorizedClientProvider(
@stefanozanella
stefanozanella / example.kt
Created August 13, 2023 15:42
Kotlin grass missing field parsing error
import com.github.doyaaaaaken.kotlincsv.dsl.csvReader
import io.blackmo18.kotlin.grass.dsl.grass
val csv = """
firstName,lastName,email
John,Doe,[email protected]
""".trimIndent()
data class Contact(
val firstName: String?,