Authorize with Permissions

我的梦境 提交于 2019-12-11 03:12:44

问题


I've done the "Getting Started with an ASP.NET MVC 3 Website" using Facebook C# SDK 5.0.8. Everything works fine.

How do I request extra Permissions from the user after that?

When I do [Authorize(Permissions = "offline_access")], I get 'System.Web.Mvc.AuthorizeAttribute' does not contain a definition for 'Permissions' error.

If I use [FacebookAuthorize(Permissions = "offline_access")], the page redirects to itself without going to the facebook login page.

Please help!

Thanks


回答1:


So the Authorize attribute is not part of the Facebook C# SDK. That example show you how to use Facebook authorization in conjunction with Forms authorization. The Authorize attribute does not contain a property named permission nor could it be used to authorize with Facebook, it is checking for permissions using your current ASP.NET Membership provider.

Regarding the FacebookAuthorize attribute not working, that is because you can't mix the two scenarios together. Basically, the tutorial you read shows you how to do authorization in the most simple way without using the Javascript SDK, etc. You should not use anything in Facebook.Web or Facebook.Web.Mvc in that tutorial as they are not designed to work with Forms Authentication.

I would suggest taking a look at some of the other samples. YThey will help you get started for some of the more common scenarios like asking for additional permissions.




回答2:


I've got it!

This is what I need to do under "LogOn" action to request extra permission:

var loginUri = oAuthClient.GetLoginUrl(new Dictionary<string, object> { { "state", returnUrl }, { "scope", "offline_access" } });


来源:https://stackoverflow.com/questions/5451346/authorize-with-permissions

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