# Secure Service-to-Service Spring Microservices with HTTPS and OAuth 2.0

**URL:** <https://devforum.okta.com/t/secure-service-to-service-spring-microservices-with-https-and-oauth-2-0/17014>\
**Category:** Developer Blog Comments\
**Created:** [March 7, 2019, 2:13pm UTC](https://devforum.okta.com/t/secure-service-to-service-spring-microservices-with-https-and-oauth-2-0/17014 "2019-03-07T14:13:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [March 7, 2019, 2:13pm UTC](https://devforum.okta.com/t/secure-service-to-service-spring-microservices-with-https-and-oauth-2-0/17014/1 "2019-03-07T14:13:02Z")

</div>

[Secure Service-to-Service Spring Microservices with HTTPS and OAuth 2.0](https://developer.okta.com/blog/2019/03/07/spring-microservices-https-oauth2)

You’ve built a microservices architecture, but have you secured your service-to-service communication? This post shows you how.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [March 20, 2019, 10:14pm UTC](https://devforum.okta.com/t/secure-service-to-service-spring-microservices-with-https-and-oauth-2-0/17014/2 "2019-03-20T22:14:46Z")

</div>

**Alex Saunin**

Hi Matt, what could be the reason to make an additional basic security between microservices? I mean private-layer API calls.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [March 25, 2019, 9:57pm UTC](https://devforum.okta.com/t/secure-service-to-service-spring-microservices-with-https-and-oauth-2-0/17014/3 "2019-03-25T21:57:03Z")

</div>

**WonHee Jung**

Your client calls microservice A, microservice A implementation might need to call microservice B internally to complete the original request and microservice B has oauth2 scope annotated on the API?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [March 26, 2019, 3:16pm UTC](https://devforum.okta.com/t/secure-service-to-service-spring-microservices-with-https-and-oauth-2-0/17014/4 "2019-03-26T15:16:52Z")

</div>

**Matt Raible**

I’m not sure I understand your question. Are you asking why you should use HTTPS between your microservices?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [March 26, 2019, 3:24pm UTC](https://devforum.okta.com/t/secure-service-to-service-spring-microservices-with-https-and-oauth-2-0/17014/5 "2019-03-26T15:24:05Z")

</div>

**Alex Saunin**

Probably I misunderstood your point here: [https://developer.okta.com/…](https://developer.okta.com/blog/2019/03/07/spring-microservices-https-oauth2#use-http-basic-auth-for-secure-microservice-communication-with-eureka-and-spring-cloud-config "https://developer.okta.com/blog/2019/03/07/spring-microservices-https-oauth2#use-http-basic-auth-for-secure-microservice-communication-with-eureka-and-spring-cloud-config")  
What is the reason to implement basic auth for communication between microservices? I think HTTPS is enough for that.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [March 26, 2019, 3:25pm UTC](https://devforum.okta.com/t/secure-service-to-service-spring-microservices-with-https-and-oauth-2-0/17014/6 "2019-03-26T15:25:31Z")

</div>

**Alex Saunin**

For that case JWT is required for sure

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [March 26, 2019, 3:53pm UTC](https://devforum.okta.com/t/secure-service-to-service-spring-microservices-with-https-and-oauth-2-0/17014/7 "2019-03-26T15:53:08Z")

</div>

**Matt Raible**

The configuration you mentioned is to secure communication between the Eureka server and microservices. Without this, any microservice can register with your Eureka server. You’re right, HTTPS is probably enough, but you can never be _too secure_ IMO.

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [March 27, 2019, 10:59pm UTC](https://devforum.okta.com/t/secure-service-to-service-spring-microservices-with-https-and-oauth-2-0/17014/8 "2019-03-27T22:59:42Z")

</div>

**Alex Saunin**

Sure, but the KISS design principle is always in my mind )

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [November 15, 2020, 6:47pm UTC](https://devforum.okta.com/t/secure-service-to-service-spring-microservices-with-https-and-oauth-2-0/17014/9 "2020-11-15T18:47:38Z")

</div>

**Christof Tinnes**

Is the implementation above thread safe? There is a singelton rest template but injecting a request specific interceptor. Does this really work?

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [November 20, 2020, 9:55pm UTC](https://devforum.okta.com/t/secure-service-to-service-spring-microservices-with-https-and-oauth-2-0/17014/10 "2020-11-20T21:55:17Z")

</div>

**Matt Raible**

Worked for me! 🙂

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [January 8, 2021, 11:52pm UTC](https://devforum.okta.com/t/secure-service-to-service-spring-microservices-with-https-and-oauth-2-0/17014/11 "2021-01-08T23:52:49Z")

</div>

**Christof Tinnes**

Hi Matt,

I “works”. But the question is if it works in a productive setting under load as it is supposed to work.  
IMHO the code is a severe security breach.  
When to request from different users are handled at the same time, one gets the Bearer token of the other.  
I don’t think that you want someone else to see your bank account by accident?   
Can you please check again your code under load with different users to verify that no racing conditions will cause a swap of Bearer tokens? We don’t want that the code is copied by someone and goes into production unless it is secure.

I don’t know if RestTemplate handles these issues under the hood but I highly doubt it.
