Member-only story
Spring Cloud OpenFeign OAuth 2.0 Client Credentials Non-interactive S2S Authentication With Spring Security 5
4 min readMay 14, 2021
In the world of micro-services, we often come across scenarios of service to service (S2S) communication that require service to establish their authenticity for successful dialogue exchange. Here I will walk you through the simple steps of establishing OAuth2 authenticity using client credentials flow for consumer service, using the Spring Security 5 framework, to be able to talk to supplier service.
For brevity, let’s get straight to the code:
Step 1) Include the dependencies:
#build.gradle
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
Step 2) Spring configuration:
#application.yml
spring.security.oauth2.client:
registration:
#Repeat block for any number of AuthZ servers
bar-auth: #unique supplier service name
client-id: DUMMY_CLIENT_ID_XXX
client-secret: DUMMY_CLIENT_SECRET_YYYY
authorization-grant-type: client_credentials
client-authentication-method: post
provider:
#Repeat block for any number of AuthZ servers
bar-auth:
token-uri…