Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set return url for DotNetOpenAuth

I'm using DotNetOpenAuth to sign in to Facebook.
Here is the code:

var facebookClient = new FacebookClient
{
    ClientIdentifier = "appId",
    ClientSecret = "appSecret"
};
IAuthorizationState authorization = facebookClient.ProcessUserAuthorization();
if (authorization == null)
{
    // Kick off authorization request
    facebookClient.RequestUserAuthorization();
}
else
{

    var request =
        WebRequest.Create("https://graph.facebook.com/me?access_token=" +
                            Uri.EscapeDataString(authorization.AccessToken));

    using (var response = request.GetResponse())
    {
        using (var responseStream = response.GetResponseStream())
        {
            var graph = FacebookGraph.Deserialize(responseStream);
            lblFacebookUserName.Text = HttpUtility.HtmlEncode(graph.Name);
        }
    }
}

Since I'm using custom url rewriter, I'm receiving an error after login because return url is something like

~/foo/foo.aspx?labg=en

and I want it to hard code it to

~/foo/foo

Any help would be appreciated

like image 793
šljaker Avatar asked Aug 12 '10 10:08

šljaker


1 Answers

You need to initialize the AuthorizationState object with a callback URL and pass that in to a slightly different method:

// Kick off authorization request
var authorizationState = new AuthorizationState()
{
    Callback = new Uri(Request.Url, Page.ResolveUrl("~/foo/foo"));
};
facebookClient.PrepareRequestUserAuthorization(authorizationState).Send();
like image 139
Andrew Arnott Avatar answered Oct 20 '22 08:10

Andrew Arnott