You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

47 lines
1.5 KiB

  1. package com.ffii.fpsms.m18.service
  2. import com.ffii.fpsms.api.service.ApiCallerService
  3. import com.ffii.fpsms.m18.M18Config
  4. import com.ffii.fpsms.m18.model.M18TokenRequest
  5. import com.ffii.fpsms.m18.model.M18TokenResponse
  6. import jakarta.annotation.PostConstruct
  7. import org.springframework.context.annotation.Bean
  8. import org.springframework.stereotype.Service
  9. @Service
  10. open class M18TokenService(
  11. private val apiCallerService: ApiCallerService,
  12. private val m18Config: M18Config
  13. ) {
  14. @Bean
  15. fun run() {
  16. // val params: MutableMap<String, String> = mutableMapOf(
  17. // "grant_type" to m18Config.GRANT_TYPE,
  18. // "client_id" to m18Config.CLIENT_ID,
  19. // "client_secret" to m18Config.CLIENT_SECRET,
  20. // "username" to m18Config.USERNAME,
  21. // "password" to m18Config.PASSWORD
  22. // )
  23. //
  24. val params = M18TokenRequest(
  25. grant_type = m18Config.GRANT_TYPE,
  26. client_id = m18Config.CLIENT_ID,
  27. client_secret = m18Config.CLIENT_SECRET,
  28. username = m18Config.USERNAME,
  29. password = m18Config.PASSWORD
  30. )
  31. apiCallerService
  32. .get<M18TokenResponse, M18TokenRequest>("/oauth/token", params, null)
  33. .subscribe(
  34. { response ->
  35. m18Config.ACCESS_TOKEN = response.access_token
  36. println("WebClient Response stored: $response")
  37. },
  38. { error -> println("WebClient Error: ${error.message}") }
  39. )
  40. }
  41. }