5

I need to generate custom response for token generation in OAuthAuthorizationServer

the default resposne is like this

{
  "access_token": "***access_token***",
  "token_type": "bearer",
  "expires_in": 119,
  ".issued": "Mon, 31 Oct 2016 11:20:50 GMT",
  ".expires": "Mon, 31 Oct 2016 11:22:50 GMT"
}

How can I generate this output instead of default one?

{
  "message": "Token Granted",
  "data": 
    {
      "Token": "***access_token***"
    },
  "messageCode": 200
}
Kahbazi
  • 14,331
  • 3
  • 45
  • 76

1 Answers1

0

This question is similar to How to modify token endpoint response body with Owin OAuth2 in Asp.Net Web API 2

Please look at my answer.

In addition you can parse response json instead of working with string, e.g.:

public async Task Invoke(HttpContext context)
{
    ...
    // parse json
    var bodyJson = JObject.Parse(bodyString);

    // do something with json inner objects
    bodyJson = ...

    // update the memory stream
    var bytes = Encoding.UTF8.GetBytes(bodyJson.ToString());
    ...
}