I am getting invalid credentials while implementing the Auth Code Flow with Oauth2 Spring Security. Below is the microservices flow:
Eureka Service - Gateway - Custom Spring Authentication Service - AM Service (pulls AM business data) - SM Service (pulls SM business data)
I am able to authenticate and auth code is getting generated as show below http://127.0.0.1:8060/login/oauth2/code/test-client?code=J5Qvmk&state=HLD0vIaz6GzJl4dK_HJCtt7CGojuPSBVj23bu9fL38s%3D
But then when trying to get redirected to original API call, it fails stating "Invalid credentials"
Below is the error: enter image description here
Below is the configurations on gateway:
spring:
application:
name: gateway-service
cloud:
gateway:
default-filters:
- TokenRelay
routes:
- id: CdsaiAMServiceApplication
uri: http://127.0.0.1:8082
predicates:
- Path=/ams/**
filters:
- TokenRelay=
- StripPrefix=0
- name: Retry
args:
retries: 1
statuses: UNAUTHORIZED
methods: GET,POST,DELETE
backoff:
firstBackoff: 10ms
maxBackoff: 50ms
factor: 2
basedOnPreviousValue: false
- id: CdsaiSMServiceApplication
uri: http://127.0.0.1:8866
predicates:
- Path=/sms/**
filters:
- TokenRelay=
- StripPrefix=0
- name: Retry
args:
retries: 1
statuses: UNAUTHORIZED
methods: GET,POST,DELETE
backoff:
firstBackoff: 10ms
maxBackoff: 50ms
factor: 2
basedOnPreviousValue: false
discovery:
locator:
enabled: true
sleuth:
sampler:
probability: 1
zipkin:
baseUrl: ${ZIPKIN_BASE_URL:http://127.0.0.1:9411}
security:
oauth2:
resource:
user-info-uri: "http://127.0.0.1:8383/user"
client:
registration:
test-client:
provider: spring
client-id: clientId
client-secret: client-secret
authorization-grant-type: authorization_code
redirect-uri: '{baseUrl}/login/oauth2/code/{registrationId}'
client-name: test-client
user-info-authentication-method: header
provider:
spring:
authorization-uri: "http://127.0.0.1:8383/oauth/authorize"
token-uri: "http://127.0.0.1:8383/oauth/token"
token-info-uri: "http://127.0.0.1:8383/oauth/check_token"
user-name-attribute: preferred_username
Can someone please help.