2012-12-16 185 views
1

我一直在下面的步驟,以使Windows 8商店應用得到一個ACS令牌如下所述: Does the WebAuthenticationBroker work in Windows 8 Metro App post Release Candidate獲取ACS令牌

但是,我WebAuthenticationResult對象的ResponseData屬性只包含ACS中指定的回調URI,並且不包含令牌信息。在我的代碼下面。 Windows 8的客戶端的

驗證方法

private async void Authenticate() 
    { 
     WebAuthenticationResult webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(
      WebAuthenticationOptions.None, 
      new Uri("https://myACSnamespace.accesscontrol.windows.net:443/v2/wsfederation?wa=wsignin1.0&wtrealm=http://localhost:12714/"), 
      new Uri("http://mypublicIPaddress:80/WebAppMVCAPI/api/federation/end")); 

信賴方應用程序返回URL設置爲http://mypublicIPaddress:80/WebAppMVCAPI/api/federation/en

我的web應用控制器編程如下:

public class FederationController : ApiController 
{ 
    protected virtual string ExtractBootstrapToken() 
    { 
     return "Hello World"; 
     //return HttpContext.Current.User.BootstrapToken(); 
    } 

    [HttpGet] 
    public string Get() 
    { 
     return "Hello Get World"; 
    } 

    [HttpPost] 
    public HttpResponseMessage Post() 
    { 
     var response = this.Request.CreateResponse(HttpStatusCode.Redirect); 
     response.Headers.Add("Location", "/WebAppMVCAPI/api/federation/end?acsToken=" + ExtractBootstrapToken()); 
     return response; 
    } 
} 

}

您可以想象,Web應用程序正在IIS服務器上運行並偵聽端口80.我的路由器配置爲根據需要轉發傳入請求,並且當我在Visual Studio中啓動我的Web應用程序時,我可以訪問來自互聯網主機的申請。

這個想法是讓Windows 8商店應用程序通過Facebook登錄從ACS獲取令牌。當我啓動win8客戶端時,應用程序會顯示一個Facebook登錄頁面。我成功登錄我的憑證。但是,當我查看webauthenticationresult.responsedata屬性時,我只能看到回調函數uri。另外,我沒有看到我的防火牆上有任何日誌,ACS試圖在我的回調函數中發佈一些內容。

+0

你如何配置你的ASP.NET Web API項目,使得ExtractBootstrapToken()的作品?我使用VS2012的「身份和訪問」嚮導添加了ACS,然後添加了wif.swt塊塊包,但不斷收到錯誤。 – markti

回答

1

您的回覆第三方應用程序返回的URL應該是

http://mypublicIPaddress:80/WebAppMVCAPI/api/federation 

http://mypublicIPaddress:80/WebAppMVCAPI/api/federation/end 
+0

安德魯,事實證明你的建議是解決我的問題。感謝您的貢獻。 –