问题描述
我创建了一个基于网络的OData使用Web API 2.本作品真的很好,在使用控制器AuthorizeAttribute后端。
I've created a OData based web back-end using Web API 2. This works really well, using AuthorizeAttribute on controllers.
我想可以上传一个文件,通过一个标准的HTML表单和一个提交。
I'd like to be able to upload a files, via a standard html form and a submit.
我们正在通过OAuth令牌,这通常会在OData的请求的标头中传递,作为隐藏输入字段。
We are passing the OAuth token, which would normally be passed in the header of an OData request, as a hidden input field.
问:你如何在控制器验证此
Question: How do you validate this in the controller?
推荐答案
然后,你需要解锁加密令牌,然后从准考证,你是否有主,如果通过身份验证(检查属性IsAuthenticated)。使用下面的code控制器内的:
Then you need to un-protect the token, then from the "ticket" you check if there is principal and if it is authenticated (check property IsAuthenticated). Use the code below inside your controller:
string token = "Your token goes here";
Microsoft.Owin.Security.AuthenticationTicket ticket = Startup.OAuthBearerOptions.AccessTokenFormat.Unprotect(token);
这篇关于验证承载的OAuth令牌表格后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!