本文整理汇总了C#中QueryParameters.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# QueryParameters.ToList方法的具体用法?C# QueryParameters.ToList怎么用?C# QueryParameters.ToList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueryParameters
的用法示例。
在下文中一共展示了QueryParameters.ToList方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleAccessTokenResponse
public void HandleAccessTokenResponse(string response)
{
QueryParameters responseCollection = new QueryParameters();
try
{
if (response.StartsWith("{")) // access token is returned in JSON format
{
// {"access_token":"asasdasdAA","expires_in":3600,"scope":"wl.basic","token_type":"bearer"}
JObject accessTokenJson = JObject.Parse(response);
responseCollection.Add("response", response);
ConnectionToken.AccessToken = accessTokenJson.SelectToken("access_token").ToString().Replace("\"", "");
if (accessTokenJson.SelectToken("expires_in") != null)
ConnectionToken.ExpiresOn = DateTime.Now.AddSeconds(int.Parse(accessTokenJson.SelectToken("expires_in").ToString().Replace("\"", "")) - 20);
//put in raw list
foreach (var t in accessTokenJson.AfterSelf())
ConnectionToken.ResponseCollection.Add(t.Type.ToString(), t.ToString());
logger.Info("Access Token successfully received");
isSuccess = true;
}
else // access token is returned as part of Query String
{
responseCollection = Utility.GetQuerystringParameters(response);
string keyForAccessToken = responseCollection.Single(x => x.Key.Contains("token")).Key;
ConnectionToken.AccessToken = responseCollection[keyForAccessToken].Replace("\"", "");
if (responseCollection.ToList().Exists(x => x.Key.ToLower().Contains("expir")))
{
string keyForExpiry = responseCollection.Single(x => x.Key.Contains("expir")).Key;
ConnectionToken.ExpiresOn = ConnectionToken.ExpiresOn = DateTime.Now.AddSeconds(int.Parse(responseCollection[keyForExpiry].Replace("\"", "")) - 20);
}
//put in raw list
responseCollection.ToList().ForEach(x => ConnectionToken.ResponseCollection.Add(x.Key, x.Value));
logger.Info("Access Token successfully received");
isSuccess = true;
}
}
catch (Exception ex)
{
logger.Error(ErrorMessages.AccessTokenResponseInvalid(responseCollection), ex);
throw new OAuthException(ErrorMessages.AccessTokenResponseInvalid(responseCollection), ex);
}
}
示例2: HandleUserReturnCallback
public void HandleUserReturnCallback(QueryParameters responseCollection)
{
if (responseCollection.HasName("oauth_verifier"))
{
connectionToken.OauthVerifier = responseCollection["oauth_verifier"];
connectionToken.AuthorizationToken = responseCollection["oauth_token"];
logger.Info("User successfully logged in and returned");
}
else if (responseCollection.ToList().Exists(x => x.Key.ToLower().Contains("denied") || x.Value.ToLower().Contains("denied")))
{
logger.Error(ErrorMessages.UserDeniedAccess(connectionToken.Provider, responseCollection));
throw new OAuthException(ErrorMessages.UserDeniedAccess(connectionToken.Provider, responseCollection));
}
else
{
logger.Error(ErrorMessages.UserLoginResponseError(provider.ProviderType, responseCollection));
throw new OAuthException(ErrorMessages.UserLoginResponseError(provider.ProviderType, responseCollection));
}
}
示例3: HandleAuthorizationCode
public void HandleAuthorizationCode(QueryParameters responseCollection)
{
if (responseCollection.HasName("code"))
{
ConnectionToken.Code = responseCollection["code"];
logger.Info("User successfully logged in and returned with Authorization code");
}
else if (responseCollection.ToList().Exists(x => x.Key.ToLower().Contains("denied") || x.Value.ToLower().Contains("denied")))
{
logger.Error(ErrorMessages.UserDeniedAccess(provider.ProviderType, responseCollection));
throw new UserDeniedPermissionException(provider.ProviderType);
}
else
{
logger.Error(ErrorMessages.UserLoginResponseError(provider.ProviderType, responseCollection));
throw new OAuthException(ErrorMessages.UserLoginResponseError(provider.ProviderType, responseCollection));
}
}
示例4: RequestForRequestToken
public void RequestForRequestToken()
{
QueryParameters oauthParameters = new QueryParameters();
string signature = "";
OAuthHelper oauthHelper = new OAuthHelper();
//Twitter Test @ https://dev.twitter.com/docs/auth/oauth
//oauthParameters.Add("oauth_callback", "http://localhost:3005/the_dance/process_callback?service_provider_id=11");
//oauthParameters.Add("oauth_consumer_key", "GDdmIQH6jhtmLUypg82g");
//oauthParameters.Add("oauth_nonce", "QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk");
//oauthParameters.Add("oauth_signature_method", "HMAC-SHA1");
//oauthParameters.Add("oauth_timestamp", "1272323042");
//oauthParameters.Add("oauth_version", "1.0");
//signature = oauthHelper.GenerateSignature(new Uri(provider.RequestTokenEndpoint), oauthParameters, "GDdmIQH6jhtmLUypg82g", "MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98", provider.SignatureMethod, provider.TransportName, string.Empty);
////1. Setup request parameters
oauthParameters.Add("oauth_consumer_key", provider.Consumerkey);
oauthParameters.Add("oauth_signature_method", provider.SignatureMethod.ToString());
oauthParameters.Add("oauth_timestamp", oauthHelper.GenerateTimeStamp());
oauthParameters.Add("oauth_nonce", oauthHelper.GenerateNonce());
oauthParameters.Add("oauth_version", "1.0");
oauthParameters.Add("oauth_callback", ConnectionToken.Domain + "SocialAuth/validate_sauth.ashx");
//2. Notify Consumer (optionally user may wish to add extra parameters)
BeforeRequestingRequestToken(oauthParameters); // hook called
oauthParameters.ToList().ForEach(x=>x.Value = Utility.UrlEncode(x.Value));
//3. Generate Signature
signature = oauthHelper.GenerateSignature(new Uri(provider.RequestTokenEndpoint), oauthParameters, provider.Consumerkey, provider.Consumersecret, provider.SignatureMethod, provider.TransportName, string.Empty);
oauthParameters.Add("oauth_signature", signature);
//4.Connect and obtain Token
logger.Debug("Requesting Request Token at: " + provider.RequestTokenEndpoint);
string requestUrl = provider.RequestTokenEndpoint + "?" + oauthHelper.GetAuthorizationUrlParameters(oauthParameters);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
request.Method = provider.TransportName.ToString();
//request.Headers.Add("Authorization", oauthHelper.GetAuthorizationHeader(oauthParameters));
request.ContentLength = 0;
//request.ContentType = "application/x-www-form-urlencoded";
// Check issue with Authorization Header
string response = "";
try
{
logger.Debug("Requesting Request Token at: " + provider.RequestTokenEndpoint);
using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())
using (Stream responseStream = webResponse.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
{
response = reader.ReadToEnd();
if (response.Contains("oauth_token_secret"))
{
logger.Debug("Request Token response: " + response.ToString());
var responseCollection = Utility.GetQuerystringParameters(response);
HandleRequestTokenGrant(responseCollection);
}
}
}
catch (Exception ex)
{
logger.Error(ErrorMessages.RequestTokenRequestError(provider.RequestTokenEndpoint, oauthParameters), ex);
throw new OAuthException(ErrorMessages.RequestTokenRequestError(provider.RequestTokenEndpoint, oauthParameters), ex);
}
}