I’m trying to make a server-side login process with facebook in my C# MVC application.
At the moment of submiting an status update in my app it has to publish it on facebook, I make a redirect to:
https://www.facebook.com/dialog/oauth?client_id={0}&scope={1}&redirect_uri={2}
Using this Method:
Response.Redirect(...);
where my redirect uri is encoded like this:
HttpUtility.UrlEnconde("http://local.mydomain.com/getAuthToken?message=the original message");
And back into my MVC app (after accepting the fb permissions) the getAuthToken action makes a request to the URI:
https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&code={2}&redirect_uri={3}
Using this Method:
using (var wc = new WebClient()){
wc.DownloadString(...)
}
where my redirect uri again is encoded like this:
HttpUtility.UrlEnconde("http://local.mydomain.com/getAuthToken?message=the original message");
if “the original message” contains no spaces it works but when I start adding spaces and other special characters I get an OAuth Exception:
Error validating verification code
So my question is, what kind of URL Enconding should I have to use to make it work
I Found something here but I’m getting the same error, I dont know if I need a special method to make the redirects or if I need diferent Encodings for this two request.
To solve this I used this to encode:
and this to decode
In case someone needs it
Thaks