0

アズール、ログイン成功のコード結果のこのセクションのストリームによると:Azure App Servicesでは、(App Service認証サービスを使用して)正常にログオンした後にテーブルにアクセスできないのはなぜですか?

MobileServiceUser user = null; 
    private async System.Threading.Tasks.Task<bool> AuthenticateAsync() 
    { 
     string message; 
     bool success = false; 


     var provider = MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory; 

     // Use the PasswordVault to securely store and access credentials. 
     PasswordVault vault = new PasswordVault(); 
     PasswordCredential credential = null; 

     try 
     { 
      // Try to get an existing credential from the vault. 
      credential = vault.FindAllByResource(provider.ToString()).FirstOrDefault(); 
     } 
     catch (Exception) 
     { 
      // When there is no matching resource an error occurs, which we ignore. 
     } 

     if (credential != null) 
     { 
      // Create a user from the stored credentials. 
      user = new MobileServiceUser(credential.UserName); 
      credential.RetrievePassword(); 
      user.MobileServiceAuthenticationToken = credential.Password; 

      // Set the user from the stored credentials. 
      App.MobileService.CurrentUser = user; 

      // Consider adding a check to determine if the token is 
      // expired, as shown in this post: http://aka.ms/jww5vp. 

      success = true; 
      message = string.Format("Cached credentials for user - {0}", user.UserId); 
     } 
     else 
     { 
      try 
      { 
       // Login with the identity provider. 
       user = await App.MobileService 
        .LoginAsync(provider, true); 

       // Create and store the user credentials. 
       credential = new PasswordCredential(provider.ToString(), 
        user.UserId, user.MobileServiceAuthenticationToken); 
       vault.Add(credential); 

       success = true; 
       message = string.Format("You are now logged in - {0}", user.UserId); 
      } 
      catch (MobileServiceInvalidOperationException) 
      { 
       message = "You must log in. Login Required"; 
      } 
     } 

     var dialog = new MessageDialog(message); 
     dialog.Commands.Add(new UICommand("OK")); 
     await dialog.ShowAsync(); 

     return success; 
    } 

しかし、私はIServiceTableからの情報をつかむしようとすると、アクセスが拒否されます。 Azureのストリームでは、テーブルへのアクセスに使用されるログオンメソッドが「匿名」であることに気付きました。誰も助けることができますか?

Link to screenshot of token

答えて

0

:(。私は、トークンを検討してきた、そしてそれが右に見える)ここで

public IMobileServiceTable<Finding> FindingsTable { get {return findingsTable;} } 
    private IMobileServiceTable<Finding> findingsTable; 

    private MobileServiceClient client; 

    public ClientAPI(string url) 
    { 
     //client = new MobileServiceClient(url); 
     client = App.MobileService; 
     findingsTable = client.GetTable<Finding>(); 
    } 

    public async Task<ObservableCollection<Finding>> GetAllFindingsAsync() 
    { 
    // The line below triggers the no access error: 
     var findings = await findingsTable.Select(f => f).ToCollectionAsync(); 

は、テーブルにアクセスしようとすると、サービスに送信されたトークンを示したグラフでありますauthenticationTokennbfGMT: Thursday, December 21, 2017 9:56:15 PMを表しますが、expGMT: Saturday, January 20, 2018 9:56:15 PMを表します。 AFAIK、有効なexpは、デフォルトでnbfという1時間分です。

キャッシングトークンを無効にし、ログに直接App.MobileService.LoginAsyncを呼び出し、fiddlerを利用してネットワークトレースをキャプチャし、オンラインテーブルFindingにアクセスしてこの問題を絞り込むことをお勧めします。

また、ブラウザ経由でログに記録してauthenticationTokenを取得すると、トークンをデコードしてローカルのキャッシュトークンと比較することができます。ブラウザ経由でログに記録した後、https://{your-app-name}.azurewebsites.net/tables/{table-name}にアクセスしてテーブルレコードを取得し、この問題を絞り込むことができます。さらにトークンをキャッシュするには、Caching Tokensに関するアドリアン・ホールの本に従ってください。

+0

ありがとうございました。私はあなたのアドバイスを取って、トークンキャッシングを制御する行をコメントアウトしました。残念ながら、Postmanを介してリクエストでトークンを手動で送信しても、私はまだアクセスが拒否されます。私は成功したログオンページにリダイレクトされます。私のエラーはAzureのリダイレクトURIやその他の設定のエントリによって発生する可能性がありますか?私はそれらをチェックして再点検したが、私は何かを理解していないかもしれない。ご協力いただきありがとうございます! – Matt

+0

郵便配達員の場合は、 'https:// {your-app-name} .azurewebsites.net/tables/{テーブル名}'を取得し、** x-zumo-auth **ヘッダーに値を設定して追加することができます'authenticationToken'です。さらに、他のログインプロバイダ(MSA、Facebookなど)を設定してから、 'https:// {your-app-name} .azurewebsites.net/.auth/login/{microsoftaccount | facebookブラウザから 'https:// {your-app-name} .azurewebsites.net/tables/{table-name}'にアクセスしてモバイルサーバー側にアクセスできることを確認してから、モバイルクライアントコード。 –

関連する問題