[英]Custom Response for OAuthAuthorizationServer in OWIN
I need to generate custom response for token generation in OAuthAuthorizationServer
我需要为
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
}
This question is similar to How to modify token endpoint response body with Owin OAuth2 in Asp.Net Web API 2 此问题类似于如何在Asp.Net Web API 2中使用Owin OAuth2修改令牌终结点响应主体
Please look at my answer. 请看看我的回答。
In addition you can parse response json instead of working with string, eg: 另外,您可以解析响应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());
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.