Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set permissions dynamically in Microsoft.AspNet.Mvc.Facebook.FacebookAuthorize?

Controller

public partial class HomeController
{
     private static String[] userPermissions;
     public HomeController()
     {
          var MyPermission = Convert.ToString(TempData["MyPermission"]);
          userPermissions = (MyPermission).Split(',');
     }

     [Microsoft.AspNet.Mvc.Facebook.FacebookAuthorize(userPermissions)]
     public virtual ActionResult MyActionMethod()
     {
         return View();
     }
}

Overload

enter image description here

Compilation Error

In the above block, we have following code

[Microsoft.AspNet.Mvc.Facebook.FacebookAuthorize(userPermissions)]

It is giving below compilation error...

enter image description here

like image 954
Pankaj Avatar asked Nov 23 '22 14:11

Pankaj


1 Answers

Not sure if it helps but this is how I let users add additional permissions.

        /// <summary>
    /// Use this method when an action fails due to lack of priviligies. It will redirect user to facebook with provided permission request.
    /// Refactor to handle list of request.
    /// </summary>
    /// <param name="permission"></param>
    private static void AddAdditionalPermissions(string permission)
    {
        System.Diagnostics.Trace.TraceInformation(permission + " not authorized for user.");
        string facebook_urlAuthorize_base = "https://graph.facebook.com/oauth/authorize";
        string scope = permission; //see: https://developers.facebook.com/docs/authentication/permissions/ for extended permissions
        string urlAuthorize = facebook_urlAuthorize_base;
        urlAuthorize += "?client_id=" + AppId;
        urlAuthorize += "&redirect_uri=" + "https://mydomainnamehere.nu/";
        urlAuthorize += "&scope=" + scope;

        //redirect the users browser to Facebook to ask the user to authorize our Facebook application
        HttpContext.Current.Response.Redirect(urlAuthorize, true); //this cannot be done using WebRequest since facebook may need to show dialogs in the users browser
    }
like image 156
Magnus Karlsson Avatar answered Dec 25 '22 02:12

Magnus Karlsson