This page guides you through a mechanism you can use to send custom error codes to the client side in case of defined/identified errors, using a custom grant handler.
This simply uses the mobile grant sample and adds the specific error codes/messages to it. See the Writing a Custom OAuth 2.0 Grant Type topic for instructions on how to implement and use the mobile grant sample before adding the custom error codes to it.
The following Maven buildable source is compatible with WSO2 Identity Server 5.1.0 version. The attached
.jar file can be directly used as well.
The following code segment in the sample class
validateGrant() method is the relevant code used for this mechanism.
The code within lines 71-75 sets a custom response header in case an invalid mobile number is sent.
Try out Scenario
This is erroneous according to the mobile custom grant sample because the mobile number does not start with '003'. You can use the -v option in the cURL command to see the header of the response which should be as seen in the code block below.
Line 12 shows the custom header appearing in the headers.
Similarly this can be used to transfer any custom information to the client, in a flexible manner.