cancel
Showing results for 
Search instead for 
Did you mean: 

Need to customize Oauth server error response

Former Member
0 Kudos
450

Hi,

Currently i am getting exception like "error": "unsupported_grant_type" while try to get Oauth access token. I need to customize that error response with error type like validation error.

I saw that oAuth2ExceptionRendererV2 has exceptionConverter but still i have error in below format { "error": "unsupported_grant_type", "error_description": "Unsupported grant type: passwor" }

I need to add type in error response like { "errors": [ { "message": "forgoodtest@gmail.com", "type": "DuplicateUidError" } ] }

There is any way to customize the Oauth2Exception? Please guide me on this

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi, Currently i have using https://localhost:9002/authorizationserver/oauth/token for Oauth i thing its configured in platform. in my local web service extension i have exceptionConverterV2 and oAuth2ExceptionRendererV2 but while calling https://localhost:9002/v2/oauth/token URL i got error. Could you please clarify how to enable this url in my local extension.

Please correct me if i am wrong.

Former Member
0 Kudos

Hi . Thank you for your response i will check.

former_member698810
Discoverer
0 Kudos

The json serialization that you are noticing comes from Spring framework (spring-security module). Please take a look at the class OAuth2Exception and the annotation OAuth2ExceptionJackson2Serializer that is responsible for serializing these exceptions.

You have to essentially create your own wrapper exception and custom serializer to create the JSON in the format you prefer. You can find an example here https://medium.com/@beladiyahardik7/spring-security-custom-oauth2exception-in-spring-b35a62af4d34