2015-04-26 41 views
1

我目前正在嘗試使用.NET SDK的Box SDK爲MVC Web應用程序構建登錄。 雖然我不能爲了我的生活而圍繞Oauth登錄過程。我覺得我已經把它放下了,但實際的POST動作令我感到困惑。Oauth with Box SDK(C#MVC .NET)

以下是我正在嘗試遵循的流程: https://developers.box.com/oauth/ 我陷入了「第一條腿」部分。

我通過我的URI和數據屬性後如預期

var data = new List<KeyValuePair<string, string>> 
     { 
      new KeyValuePair<string, string>("response_type", "code"), 
      new KeyValuePair<string, string>("client_id", client_id), 
      new KeyValuePair<string, string>("box_login", account_email) 
     }; 

     HttpResponseMessage values = await Post("https://app.box.com/api/oauth2/authorize", data); 

通過自定義post()方法包裝:

public static async Task<HttpResponseMessage> Post(string uri, List<KeyValuePair<string, string>> pairs) 
    { 
     using (HttpClient client = new HttpClient()) 
     { 
      var content = new FormUrlEncodedContent(pairs); 
      var response = await client.PostAsync(uri, content); 
      return response; 
     } 

    } 

但 「值」 的內容回來與HTML對於Box授權頁面。假設我應該重定向到這個頁面......我只是不知道這樣做的最佳方法(然後返回)。

我覺得這一切都可能歸結爲我誤解POST的工作原理。我錯過了什麼明顯而簡單的事情?

回答

0

OAuth表示外部認證。您必須將用戶重定向到Box OAuth頁面,而不是發送Post請求。應用程序中的重定向URL將決定授權令牌的發送位置,然後您可以獲取該授權代碼,並使用Box .NET SDK或使用自定義請求與訪問和刷新令牌進行交換。

OAuth的第一階段不是SDK的一部分。