2017-08-07 4 views
0

私はXamarin.Froms(PCL)プロジェクトに取り組んでいます。私はテストアプリケーションにログイン認証を追加するためにAzure Mobile Servicesと協力しています。しかし、私は未処理の例外を取得し続けます。毎回私はこのコード行を実行します user = await TodoItemManager.DefaultManager.CurrentClient.LoginAsync(this, MobileServiceAuthenticationProvider.Facebook, Constants.ApplicationURL); このコードスニペットは私の "{myApp} .Droid" MainActivityからです。Azure Mobile Servicesクライアント認証が機能しません。

MainActivity.cs

public class MainActivity : FormsApplicationActivity, IAuthenticate 
{ 

    private MobileServiceUser user; 


    protected override void OnCreate (Bundle bundle) 
    { 
     base.OnCreate (bundle); 

     // Initialize Azure Mobile Apps 
     CurrentPlatform.Init(); 

     // Initialize Xamarin Forms 
     Forms.Init(this, bundle); 

     // Initialize login provider 

     App.Init((IAuthenticate)this); 


     // Load the main application 
     LoadApplication (new App()); 

    } 
    public async Task<bool> Authenticate() 
    { 

     var success = false; 
     var message = string.Empty; 
     try 
     { 
      //var token = new JObject { { "access_token", "access_token_value" } }; 

      user = await TodoItemManager.DefaultManager.CurrentClient.LoginAsync(this, MobileServiceAuthenticationProvider.Facebook, Constants.ApplicationURL); 

      if (user != null) 
      { 
       message = string.Format("You are now signed in as {0}.", user.UserId); 
       success = true; 
      } 
     } 
     catch (Exception ex) 
     { 
      message = ex.Message; 
     } 
     // Display success or failure message 
     AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.SetMessage(message); 
     builder.SetTitle("Sign-in Result"); 
     builder.Create().Show(); 

     return success; 
    } 
}` 

MyAppには実行しますが、Facebookの認証ページが表示されません。私のアプリがクラッシュするたびに私はアプリを実行する。ここで

は、MSDNへのリンクは、私がここでAdding Authentication to Azure Mobile Clients

答えて

0

を複製しようとしているファイルである私はAdding Authentication to Azure Mobile Clientsを複製しようとしていますMSDNファイルへのリンクです。

私はあなたが提供されたリンクは、あなたのXamarin.Androidアプリに認証を追加する方法についてであることに気づきました。 Xamarin.FormsのAndroidアプリプロジェクトに認証を追加するには、Add authentication to the portable class libraryAdd authentication to the Android appを参照してください。サーバー管理のフローを使用してFacebookのログインで中

サイン:

MobileServiceUser user = await TodoItemManager.DefaultManager.CurrentClient.LoginAsync(this, 
    MobileServiceAuthenticationProvider.Facebook); 

また、あなたがデバッグし、この問題を狭めるためにクラッシュレポートを収集することができます。ここにはDebugging and Error Trackingに関する文書があります。

UPDATE:Microsoft.Azure.Mobile.Client 4.0.1を使用するための

、私はAdd your app to the Allowed External Redirect URLsを踏襲し、Azureのポータル上で許可外部リダイレクトURLとしてbruceapp://easyauth.callbackを追加します。その後

、ログイン操作のために、次のコードを使用します。

user = await TodoItemManager.DefaultManager.CurrentClient.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount, "bruceapp"); 

私は私のbruce_mobile.UWPプロジェクトでチェック予想通り、ログイン操作は、仕事ができます。

+0

ブルースにお返事ありがとうございます!私は他のmsdnリンクも試しました。しかし、私が使用している問題は、リンクが古くなっていることです。上記のLoginAsync(..)メソッドのパラメータは機能しません。私は現在 "Mobile Service Client 4.0.1"を使用しています。私はURI shcemeの追加パラメータを追加する必要があります。しかし、私はまだコードが "loginAsync"行を実行するたびに処理されない例外が発生する – oopragmmer

+0

私のアプリケーションでMicrosoft.Azure.Mobile.Client 3.1.0を使用しましたが、期待どおりに動作する可能性があります。私は明日の新しいバージョンをチェックします、あなたはこの問題を絞り込むために3.1.0を使うことができます。 –

+0

Microsoft.Azure.Mobile.Client 4.0.1を使用して自分の回答を更新しました。それを参照できます。さらに、この問題を解決しましたか? –

関連する問題