我需要为 OAuthAuthorizationServer
中的 token 生成生成自定义响应
默认的响应是这样的
{
"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"
}
如何生成此输出而不是默认输出?
{
"message": "Token Granted",
"data":
{
"Token": "***access_token***"
},
"messageCode": 200
}
最佳答案
这个问题类似于How to modify token endpoint response body with Owin OAuth2 in Asp.Net Web API 2
请看我的回答。
此外,您可以解析响应 json 而不是使用字符串,例如:
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());
...
}
关于c# - OWIN 中 OAuthAuthorizationServer 的自定义响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40338425/