2014-05-02 34 views
0

我有具有以下POST方法現有的C#項目:C#OAuthWebSecurity Google提供商網址?

// POST: /Account/ExternalLogin 
[HttpPost] 
[AllowAnonymous] 
[ValidateAntiForgeryToken] 
public ActionResult ExternalLogin(string provider, string returnUrl) 
{ 
    return new ExternalLoginResult(provider, Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl })); 
} 

其中採用:

OAuthWebSecurity.Login(provider, ...); 

我有點新到OAuth,並沒有做任何事的中這個C#項目。我不但是實現上的Android應用程序谷歌的授權,我想用下面的類/方法的HttpPost:

public class TaskPostAPI extends AsyncTask<String, Void, String> 
{ 
    GoogleApiClient googleAPI; 

    public TaskPostAPI(GoogleApiClient googleAPI){ 
     this.googleAPI = googleAPI; 
    } 

    @Override 
    protected String doInBackground(String... urls){ 
     String response = ""; 
     for(String url : urls){ 
      DefaultHttpClient client = new DefaultHttpClient(); 
      HttpPost post = new HttpPost(url); 
      try{ 
       List<NameValuePair> nvPairs = new ArrayList<NameValuePair>(2); //(3); 
       //nvPairs.add(new BasicNameValuePair("personName", Plus.PeopleApi.getCurrentPerson(googleAPI).getDisplayName())); 
       //nvPairs.add(new BasicNameValuePair("personGooglePlusProfile", Plus.PeopleApi.getCurrentPerson(googleAPI).getUrl())); 
       //nvPairs.add(new BasicNameValuePair("personEmail", Plus.AccountApi.getAccountName(googleAPI))); 

       nvPairs.add(new BasicNameValuePair("provider", ???)); 
       URL u = new URL(url); 
       nvPairs.add(new BasicNameValuePair("returnUrl", u.getProtocol() + "://" + u.getHost())); 

       post.setEntity(new UrlEncodedFormEntity(nvPairs)); 

       HttpResponse execute = client.execute(post); 
       InputStream content = execute.getEntity().getContent(); 

       BufferedReader buffer = new BufferedReader(new InputStreamReader(content)); 
       String s = ""; 
       while((s = buffer.readLine()) != null) 
        response += s; 
      } 
      catch(Exception ex){ 
       ex.printStackTrace(); 
      } 
     } 
     return response; 
    } 
} 

所以我的問題:我應該把在POST-method's???。那麼什麼是Provider?在我的Android應用程序中,我使用Google登錄,並獲得GoogleApiClientPersoncom.google.android.gms.plus.model.people.Person)。

this website我看到以下網址:https://accounts.google.com/o/oauth2/auth。這是我應該使用的網址爲provider?或者我應該將parameters添加到此網址?或者我應該使用完全不同的字符串作爲provider

PS:如果有人可以給我一個鏈接到的provider-urls列表(如Google'sFacebook'sTwitter's等),以及如何使用它們的C#OAuthWebSecurity我將不勝感激。

在此先感謝您的回覆。

回答

0

好的事實證明它是非常簡單的。該provider就是「谷歌」,僅此而已,無所不及。這provider name我在RegisterClient法德C#項目中找到:

OAuthWebSecurity.RegisterClient(client, "Google", extraData); 

現在POST的作品,除了郵件"The required anti-forgery cookie "__RequestVerificationToken" is not present.",但至少我可以繼續。並且將Cookie添加到HttpPost並不難,我相信當使用CookieManager時。