Redirecting after login

Apr 19, 2010 at 9:36 AM

Hi all,

I've been using the Facebook toolkit to create an IFrame application and I've needed the ability to redirect to a specific url after the user has authorized my application. If the user goes to my application canvas page for the first time, they will be redirected to a login page that will ask them to authorize my application, then once they've authorized they will be redirected back to the canvas page.

If the user goes to my application for the first time through a story published on the news feed they will also be redirected to the canvas page after authorization, but I want them to be taken to the url that was published on the news feed.

To overcome this issue I have modified the GetLoginUrl method in CanvasSession.cs so that a callback url can be specified allowing the user to be redirected to a page of my choice. Here is the modified method...

protected string GetLoginUrl()        

{            

return string.Format("http://www.facebook.com/login.php?v=1.0&api_key={0}&next={1}&canvas=", ApplicationKey, HttpUtility.UrlEncode(HttpContext.Current.Request.Url.ToString()));        

}

Has anybody else needed this functionality? I think this would be a good addition to the core toolkit, is it possible to get this added to the next release?

Regards,

Jason

 

 

May 30, 2010 at 11:20 AM
Thanks Jason. Can you tell me how can i make the logout url. Now i am working with facebook garph api. I want that when user click on the logout button ,he must logout from the both my site as well facebook. Regards, Sam
Jun 17, 2010 at 4:38 PM

Hi jason, i am facing the same problem. please give me some detail description about it,Lawkant

Aug 31, 2010 at 11:38 PM

Hello Jason,

 

I was facing the same problem but I came with a different solution. As I want to use the binaries distribution I didn't want to modify CanvasSession. I implemented the solution in the master template like this:

 

        protected override void OnInit(EventArgs e)
        {
            if (RequireLogin && string.IsNullOrEmpty(this.Api.Session.SessionKey))
            {
                string nextParam = "&next=" + HttpUtility.UrlEncode(Request.Url.ToString());
                string url = string.Format("http://www.facebook.com/login.php?api_key={0}&v=1.0&canvas{1}", this.ApiKey, nextParam);

                Response.Write(
                string.Format("<script type=\"text/javascript\">\n" +
                               "if (parent != self) \n" +
                               "top.location.href = \"" + url + @"&v=1.0" + "\";\n" +
                               "else self.location.href = \"" + url + @"&v=1.0" + "\";\n" +
                               "</script>"));
                Response.End();
            }
            else
            {
                base.OnInit(e);
            }
        }

It works perfectly but I would like to see a more structural solution in the toolkit.

 

Al

Aug 31, 2010 at 11:53 PM

I've opened an issue for this http://facebooktoolkit.codeplex.com/workitem/18639