Xamarin.Iosアプリからの認証(Google/Facebook)が必要なサーバー上のセキュリティ保護されたWeb APIにアクセスしようとしています。Xamarin.Iosから保護されたWeb APIを呼び出すことはできません
AzureポータルからサンプルToDo Appをダウンロードして実行し、このチュートリアルのように認証を追加すると、https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-xamarin-ios-get-started-users/は、GoogleとFacebookを使用した魅力のように機能します。
しかし、私は、高速なASP.NETアプリケーションを作成し、Web API 2コントローラを追加してXamarin.Iosから呼び出そうとしても、それは届かない。例えば
、このコントローラを有する:
public class GetAdviceController : ApiController
{
[HttpGet]
[Authorize]
[ResponseType(typeof(string))]
public IHttpActionResult GetAdvice()
{
return Ok("RandomAdvice/Passed");
}
}
そしてXamarin.Ios
public MobileServiceClient Client = new MobileServiceClient(Constants.ApplicationURL);
HttpClient restClient= new HttpClient();
try
{
MobileServiceUser User = await App.Client.LoginAsync(this, MobileServiceAuthenticationProvider.Google);
//User contains the Token and SID
Console.Error.WriteLine(@"Logged IN");
HttpResponseMessage response = new HttpResponseMessage();
try
{
response = await client.GetAsync("https://mysite.azurewebsites.net/api/getadvice");
//The response is 200 but it does not reach my controller and redirests me to the login screen of the asp.net website. http://imgur.com/Fp9FhdR
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
このコードresponse.contentがちょうどJSON形式でhttp://imgur.com/Fp9FhdRあります。
私は何かが欠けていると確信していますが、私はそれが何であるかを見つけることができません。 ありがとうございます。
任意のヘッダーにトークンを設定していますか?私はこれを示す何も見ません。 – Cheesebaron