Created
July 6, 2012 16:32
-
-
Save ericsk/3061197 to your computer and use it in GitHub Desktop.
使用 WebAuthenticationBroker 做 Facebook 身份驗證 (C#)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Windows.Foundation; | |
using Windows.Security.Authentication.Web; | |
// 組合授權的 URL | |
var authUrl = new Uri(string.Format( | |
"https://www.facebook.com/dialog/oauth?client_id={0}&redirect_uri={1}&response_type=token&display=popup&scope={2}", | |
"<你應用程式的 ID>", | |
Uri.EscapeDataString("https://www.facebook.com/connect/login_success.html"), | |
"<權限列表,以 , 隔開>")); | |
// 回呼 URL | |
var callbackUrl = new Uri("https://www.facebook.com/connect/login_success.html"); | |
// 呼叫 WebAuthenticationBroker | |
var result = await WebAuthenticationBroker.authenticateAsync( | |
WebAuthenticationOptions.none, authUrl, callbackUrl); | |
// 完成授權的動作,檢查授權是否成功 | |
if (result.ResponseStatus == WebAuthenticationStatus.Success) { | |
// 成功授權,從 result.ResponseData 中取得 access_token 以及 expires_in 的值 | |
} else { | |
// 處理發生錯誤的狀況 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment