0

: 내가 IServiceTable에서 정보를 잡아하려고 할 때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; 
    } 

그러나, 액세스가 거부됩니다. Azure의 스트림에서 테이블에 액세스하려는 시도에 사용 된 로그온 방법이 "익명"임을 알았습니다. 누구든지 도와 줄 수 있습니까? (I 토큰을 조사했으며, 그것은 바로 보인다.) 여기

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(); 

은 그래픽은 테이블에 액세스 할 때 서비스로 전송되는 토큰을 보여주고있다 :

Link to screenshot of token

답변

0

authenticationTokennbfGMT: Thursday, December 21, 2017 9:56:15 PM을 나타내지 만 expGMT: Saturday, January 20, 2018 9:56:15 PM을 나타냅니다. AFAIK, exp의 유효 기간은 기본적으로 nbf입니다.

난 당신이 캐싱 토큰을 사용하지 않고 직접 다음, 로깅을위한 App.MobileService.LoginAsync 전화를 활용 fiddler을 네트워크 추적을 캡처하고이 문제를 좁힐 온라인 테이블 Finding에 액세스하려고 추천 할 것입니다.

또한 브라우저를 통해 로깅하기 위해 https://{your-app-name}.azurewebsites.net/.auth/login/aad에 액세스하여 authenticationToken을 검색하면 토큰을 디코딩하여 로컬 캐싱 토큰과 비교할 수 있습니다. 브라우저를 통해 기록한 후 https://{your-app-name}.azurewebsites.net/tables/{table-name}에 액세스하여 테이블 레코드를 검색하여이 문제를 좁힐 수 있습니다. 또한 캐싱 토큰의 경우 adrian hall의 Caching Tokens에 대한 책을 참고할 수 있습니다.

+0

감사합니다. 귀하의 조언을 듣고 토큰 캐싱을 제어하는 ​​라인을 주석 처리했습니다. 불행히도, 수동으로 우편 배달부를 통해 요청에 토큰을 보내는 경우에도 여전히 액세스가 거부됩니다. 성공적인 로그온 페이지로 리디렉션됩니다. 내 오류가 리디렉션 URI 또는 ​​Azure의 다른 설정 항목으로 인해 발생할 수 있습니다. 나는 그들을 확인하고 재검사했지만, 아마도 나는 뭔가를 이해하지 못하고있다. 당신의 도움을 주셔서 감사합니다! – Matt

+0

우편 배달부의 경우'https : // {your-app-name} .azurewebsites.net/tables/{table-name}'을 (를) 얻을 수 있고 ** 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}'에 액세스하여 모바일 서버 측에 성공적으로 액세스 할 수 있는지 확인한 다음 귀하의 모바일 클라이언트 코드. –

관련 문제