Validate OAuth bearer token with form post

≡放荡痞女 提交于 2020-01-22 16:28:31

问题


I've created a OData based web back-end using Web API 2. This works really well, using AuthorizeAttribute on controllers.

I'd like to be able to upload a files, via a standard html form and a submit.

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?


回答1:


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);


来源:https://stackoverflow.com/questions/26533722/validate-oauth-bearer-token-with-form-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!