2017-06-01 1 views
2

トークンを使用してQuickBloxのサーバーを認証しようとすると大きな問題が発生します。REST APIへの不正アクセス

私が使用する方法である:

public static async Task<LoginResponse> GetLoginResponseAsync(string email, string password) 
{ 
    LoginResponse result = null; 

    using (var client = new HttpClient()) 
    { 
     string token = QbProvider.SessionResponse.Session.Token; 

     LoginRequest request = new LoginRequest() 
     { 
      Email = email, 
      Password = password 
     }; 

     using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, LoginUrlRequest)) 
     { 
      requestMessage.Headers.Authorization = new AuthenticationHeaderValue("QB-Token", token); 

      using (var response = await client.SendAsync(requestMessage)) 
      { 
       string json = response.Content.ReadAsStringAsync().Result; 
       result = JsonConvert.DeserializeObject<LoginResponse>(json); 
      } 
     } 
    } 

    return result; 
} 

サーバの応答がある:

{ "エラー":[ "トークンが必要とされる"]}

およびヘッダー(デバッグ)で

{ 
    StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: 
    { 
     Access-Control-Allow-Origin: * 
     Cache-Control: no-cache 
     Date: Thu, 01 Jun 2017 12:05:29 GMT 
     QuickBlox-REST-API-Version: 0.1.1 
     Server: openresty/1.9.15.1 
     Status: 401 Unauthorized 
     Strict-Transport-Security: max-age=31536000 
     WWW-Authenticate: OAuth realm=users 
     X-Content-Type-Options: nosniff 
     X-Frame-Options: SAMEORIGIN 
     X-Request-Id: 584a0dca-fc44-4114-9626-327ac1729f67 
     X-Runtime: 0.003430 
     X-XSS-Protection: 1; mode=block 
     Connection: keep-alive 
     Content-Type: application/json; charset=utf-8 
     Content-Length: 32 
    } 
} 

私が郵便配達でトークンを使用するとき、サーバーの応答はsuccですエッセルル。

私は何が間違っているのか分かりますか?

ありがとうございました!よろしくです。 よろしくお願いします。代わりにあなたの許可1のrequestMessage.Headers.Add(「QB-トークン」、トークン)を使用して、トークンヘッダを付加

+0

では、あなたは、お互いに対する要求を比較しました - あなたのコード対ポストマン。 [Fiddler](https://www.telerik.com/download/fiddler/fiddler2)のようなツールを使ってリクエストを比較することができます。 – Gururaj

+0

トークンがセッション変数 – Saravanan

+0

から取得されているかどうかを確認できますかドキュメントごとに、私はあなたのセッショントークンを使用する必要があると思いますhttps://quickblox.com/developers/Authentication_and_Authorization#Requests_and_Responses – Saravanan

答えて

0

TRY - @dukedukes

関連する問題