Need help in machine to machine Okta Oauth2 Flow and code example in java spring boot

Hi All,
I need to understan the exact flow and code example to undertand the service to service flow.
I have a Microservice A which acts as Resource Server. The other Microservice B acts as Client.
There is Authrization Server OKTA provider at Org level.

So far my understanding is →

  • I have Client Id and Secret from ORG Authrixzation Server. I use these in application.properties. I use Grant Type as “clientcredentials”, scope = “x.scope”
  • Also, I have token uri and introspect uri.
  • I have proxy host and port.

Now, I start my Service A. It starts fine. Then I start Service B, then I call a rest end point of A from B.

I am using org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.6.3

My understanding is when Service B calls the api of A, internally sprring must be calling Auth Server with my client-id, secret, grant_type and scope to get the access token. If it gets the token then Internally request would be redirected to Service A actual end point and then Service A will Call Authrization Server with the token to validate and if it is success I will get the expected output. However, I am not clear on this and not able to make my entire code work.

Note: I really appreciate anyon’e help. If anyone wants me paste the code for their reference I will do it. But really need help on this. Please guide me step by step how this entire logic works and what the magic spring autoconfigure does.