public WebResponse GetWebResponse(BaseConst.Realm realm, string signatureType, string contentType, string httpMethod, string urlPath, string parm, string consumerKey, string consumerSecret) { OAuthBase oAuth = new OAuthBase(); Uri url = new Uri(urlPath); string statusCode = string.Empty; string nonce = oAuth.GenerateNonce(); string timestamp = oAuth.GenerateTimeStamp(); string normalizedUrl = string.Empty; string normalizedReqParms = string.Empty; string sig = oAuth.GenerateSignature(url, consumerKey, consumerSecret, AccessToken, AccessTokenSecret, httpMethod, timestamp, nonce, signatureType, out normalizedUrl, out normalizedReqParms); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); string authHeader = OAuthBase.BuildOAuthHeader(consumerKey, nonce, sig, signatureType, timestamp, AccessToken); request.Headers.Add("Authorization", authHeader); request.Accept = contentType; request.Method = httpMethod; if (!string.IsNullOrEmpty(parm)) { request.ContentLength = parm.Length; // Write the request StreamWriter stOut = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII); stOut.Write(parm); stOut.Close(); } WebResponse webResponse = request.GetResponse(); return(webResponse); }//class
public string GetTokenURI(BaseConst.Realm realm, string urlPart) { string uri = string.Empty; switch (realm) { case BaseConst.Realm.People: uri = BaseConst.ApiURL + urlPart; break; case BaseConst.Realm.Groups: uri = BaseConst.ApiGroupsURL + urlPart; break; case BaseConst.Realm.Giving: uri = BaseConst.ApiGivingURL + urlPart; break; case BaseConst.Realm.Events: uri = BaseConst.ApiEventsURL + urlPart; break; default: uri = BaseConst.ApiURL + urlPart; break; } return(uri); }
public string GetAccessTokenForPortalUser(string username, string password, BaseConst.Realm realm, string consumerKey, string consumerSecret) { OAuthBase oAuth = new OAuthBase(); string url = GetTokenURI(realm, BaseConst.PortalAccessTokenURL); string creds = OAuthBase.BuildCredentials(username, password); string results = null; //begin WebResponse webResponse = GetWebResponse(realm, OAuthBase.HMACSHA1SignatureType, "appliation/xml", "POST", url, creds, consumerKey, consumerSecret); StreamReader sr = new StreamReader(webResponse.GetResponseStream()); if (webResponse.Headers["oauth_token"] != null) { AccessToken = webResponse.Headers["oauth_token"].ToString(); } if (webResponse.Headers["oauth_token_secret"] != null) { AccessTokenSecret = webResponse.Headers["oauth_token_secret"].ToString(); } results = sr.ReadToEnd().Trim(); webResponse.Close(); //end return(results); }