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
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With