Skip to content

Instantly share code, notes, and snippets.

@Tapanila
Created May 25, 2014 09:48
Show Gist options
  • Select an option

  • Save Tapanila/7968c1fdd229ae15a0d0 to your computer and use it in GitHub Desktop.

Select an option

Save Tapanila/7968c1fdd229ae15a0d0 to your computer and use it in GitHub Desktop.
private async void Authenticate()
{
//Facebook Authentication Uri
var facebookUri = "https://www.facebook.com/dialog/oauth";
//Standard redirect uri for desktop/non-web based apps
var redirectUri =
"https://www.facebook.com/connect/login_success.html";
//Place your appclient id here
var clientId = "";
//The type of token that can be requested
var responseType = "token";
//Response pattern
var pattern = string.Format("{0}#access_token={1}&expires_in={2}",
redirectUri, "(?.+)", "(?.+)");
//Access scope wanted
var scope = "read_stream";
try
{
String FacebookURL = "https://www.facebook.com/dialog/oauth?" +
"client_id=" + clientId + "&redirect_uri=" +
Uri.EscapeUriString(redirectUri) + "&scope=" + scope +
"&display=touch&response_type=" + responseType;
System.Uri StartUri = new Uri(FacebookURL);
System.Uri EndUri = new Uri(redirectUri);
WebAuthenticationResult WebAuthenticationResult =
await WebAuthenticationBroker.AuthenticateAsync(
WebAuthenticationOptions.None,
StartUri,
EndUri);
if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
{
//Authenticated succesfully
var response = WebAuthenticationResult.ResponseData.ToString();
}
else if
(WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp)
{
//Handle HTTP error
}
else
{
//Authentication failed
}
}
catch (Exception ex)
{
//Handle error
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment