本文整理汇总了C#中System.UriBuilder.AppendQueryArgs方法的典型用法代码示例。如果您正苦于以下问题:C# UriBuilder.AppendQueryArgs方法的具体用法?C# UriBuilder.AppendQueryArgs怎么用?C# UriBuilder.AppendQueryArgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.UriBuilder
的用法示例。
在下文中一共展示了UriBuilder.AppendQueryArgs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueryAccessToken
/// <summary>
/// Obtains an access token given an authorization code and callback URL.
/// </summary>
/// <param name="returnUrl">
/// The return url.
/// </param>
/// <param name="authorizationCode">
/// The authorization code.
/// </param>
/// <returns>
/// The access token.
/// </returns>
protected override string QueryAccessToken(Uri returnUrl, string authorizationCode)
{
var uriBuilder = new UriBuilder(AccessTokenServiceEndpoint);
var args = new Dictionary<string, string>();
args.Add("client_id", this.appId);
args.Add("client_secret", this.appSecret);
args.Add("redirect_uri", returnUrl.AbsoluteUri);
args.Add("code", authorizationCode);
uriBuilder.AppendQueryArgs(args);
using (var webClient = new WebClient())
{
webClient.Headers.Add("Accept", "application/json");
var text = webClient.UploadString(uriBuilder.Uri, string.Empty);
if (string.IsNullOrEmpty(text))
return null;
var data = JObject.Parse(text);
return data["access_token"].Value<string>();
}
}
示例2: GetServiceLoginUrl
/// <summary>
/// The get service login url.
/// </summary>
/// <param name="returnUrl">
/// The return url.
/// </param>
/// <returns>An absolute URI.</returns>
protected override Uri GetServiceLoginUrl(Uri returnUrl) {
// Note: Facebook doesn't like us to url-encode the redirect_uri value
var builder = new UriBuilder(AuthorizationEndpoint);
builder.AppendQueryArgs(
new Dictionary<string, string> {
{ "client_id", this.appId },
{ "redirect_uri", returnUrl.AbsoluteUri }
});
return builder.Uri;
}
示例3: AddCallbackArgumentClearsPreviousArgument
public void AddCallbackArgumentClearsPreviousArgument()
{
UriBuilder returnToWithArgs = new UriBuilder(this.returnTo);
returnToWithArgs.AppendQueryArgs(new Dictionary<string, string> { { "p1", "v1" } });
this.returnTo = returnToWithArgs.Uri;
IAuthenticationRequest_Accessor authRequest = this.CreateAuthenticationRequest(this.claimedId, this.claimedId);
authRequest.AddCallbackArguments("p1", "v2");
var req = (SignedResponseRequest)authRequest.RedirectingResponse.OriginalMessage;
NameValueCollection query = HttpUtility.ParseQueryString(req.ReturnTo.Query);
Assert.AreEqual("v2", query["p1"]);
}
示例4: GetServiceLoginUrl
/// <summary>
/// Gets the full url pointing to the login page for this client. The url should include the specified return url so that when the login completes, user is redirected back to that url.
/// </summary>
/// <param name="returnUrl">The return URL.</param>
/// <returns>
/// An absolute URL.
/// </returns>
protected override Uri GetServiceLoginUrl(Uri returnUrl) {
var builder = new UriBuilder(AuthorizationEndpoint);
builder.AppendQueryArgs(
new Dictionary<string, string> {
{ "client_id", this.appId },
{ "scope", "wl.basic" },
{ "response_type", "code" },
{ "redirect_uri", returnUrl.AbsoluteUri },
});
return builder.Uri;
}
示例5: GetServiceLoginUrl
protected override Uri GetServiceLoginUrl(Uri returnUrl)
{
var builder = new UriBuilder(_authorizationEndpoint);
builder.AppendQueryArgs(
new Dictionary<string, string>
{
{"response_type", "code"},
{"redirect_uri", returnUrl.AbsoluteUri},
{"scope", "https://www.googleapis.com/auth/userinfo.email"},
{"client_id", _clientId}
});
return builder.Uri;
}
示例6: GetServiceLoginUrl
protected override Uri GetServiceLoginUrl(Uri returnUrl)
{
if (returnUrl == null) throw new ArgumentNullException("returnUrl");
var builder = new UriBuilder("http://www.odnoklassniki.ru/oauth/authorize");
var args = new Dictionary<string, string>
{
{"client_id", AppId},
{"redirect_uri", returnUrl.AbsoluteUri},
{"scope", ""},
{"response_type", "code"}
};
builder.AppendQueryArgs(args);
return builder.Uri;
}
示例7: CreateHttpRequestInfo
internal static HttpRequestMessage CreateHttpRequestInfo(HttpMethod method, IDictionary<string, string> fields) {
var result = new HttpRequestMessage() { Method = method };
var requestUri = new UriBuilder(DefaultUrlForHttpRequestInfo);
if (method == HttpMethod.Post) {
result.Content = new FormUrlEncodedContent(fields);
} else if (method == HttpMethod.Get) {
requestUri.AppendQueryArgs(fields);
} else {
throw new ArgumentOutOfRangeException("method", method, "Expected POST or GET");
}
result.RequestUri = requestUri.Uri;
return result;
}
示例8: GetServiceLoginUrl
/// <summary>
/// The get service login url.
/// </summary>
/// <param name="returnUrl">
/// The return url.
/// </param>
/// <returns>An absolute URI.</returns>
protected override Uri GetServiceLoginUrl(Uri returnUrl)
{
var builder = new UriBuilder(AuthorizationServiceEndpoint);
var args = new Dictionary<string, string>();
args.Add("client_id", this.appId);
args.Add("response_type", "code");
args.Add("redirect_uri", returnUrl.AbsoluteUri);
builder.AppendQueryArgs(args);
return builder.Uri;
}
示例9: GetServiceLoginUrl
protected override Uri GetServiceLoginUrl(Uri returnUrl)
{
if (returnUrl == null) throw new ArgumentNullException("returnUrl");
var builder = new UriBuilder("https://oauth.vk.com/authorize");
var args = new Dictionary<string, string>
{
{"client_id", AppId},
{"redirect_uri", NormalizeHexEncoding(returnUrl.AbsoluteUri)},
{"display", "page"},
{"response_type", "code"},
{"scope", String.Join(",", Scopes)},
};
builder.AppendQueryArgs(args);
return builder.Uri;
}
示例10: GetServiceLoginUrl
protected override Uri GetServiceLoginUrl(Uri returnUrl)
{
UriBuilder builder = new UriBuilder("https://oauth.live.com/authorize");
Dictionary<string, string> args = new Dictionary<string, string>();
args.Add("client_id", this.clientId);
args.Add("scope", "wl.emails");
args.Add("response_type", "code");
#if DEBUG
args.Add("redirect_uri", (new Uri(returnUrl.AbsoluteUri.Replace("localhost", "mstestdomain.com"))).AbsoluteUri);
#else
args.Add("redirect_uri", returnUrl.AbsoluteUri);
#endif
builder.AppendQueryArgs(args);
return builder.Uri;
}
示例11: GetReturnToArgumentAndNames
public void GetReturnToArgumentAndNames()
{
UriBuilder returnToBuilder = new UriBuilder(this.response.ReturnTo);
returnToBuilder.AppendQueryArgs(new Dictionary<string, string> { { "a", "b" } });
this.request.ReturnTo = returnToBuilder.Uri;
// First pretend that the return_to args were signed.
this.response = new IndirectSignedResponse(this.request);
this.response.ReturnToParametersSignatureValidated = true;
Assert.AreEqual(1, this.response.GetReturnToParameterNames().Count());
Assert.IsTrue(this.response.GetReturnToParameterNames().Contains("a"));
Assert.AreEqual("b", this.response.GetReturnToArgument("a"));
// Now simulate them NOT being signed. They should still be visible at this level.
this.response = new IndirectSignedResponse(this.request);
this.response.ReturnToParametersSignatureValidated = false;
Assert.AreEqual(1, this.response.GetReturnToParameterNames().Count());
Assert.IsTrue(this.response.GetReturnToParameterNames().Contains("a"));
Assert.AreEqual("b", this.response.GetReturnToArgument("a"));
}
示例12: GetCallbackArguments
public void GetCallbackArguments()
{
PositiveAssertionResponse assertion = this.GetPositiveAssertion();
var rp = CreateRelyingParty();
UriBuilder returnToBuilder = new UriBuilder(assertion.ReturnTo);
returnToBuilder.AppendQueryArgs(new Dictionary<string, string> { { "a", "b" } });
assertion.ReturnTo = returnToBuilder.Uri;
var authResponse = new PositiveAuthenticationResponse(assertion, rp);
// First pretend that the return_to args were signed.
assertion.ReturnToParametersSignatureValidated = true;
Assert.AreEqual(1, authResponse.GetCallbackArguments().Count);
Assert.IsTrue(authResponse.GetCallbackArguments().ContainsKey("a"));
Assert.AreEqual("b", authResponse.GetCallbackArgument("a"));
// Now simulate them NOT being signed.
assertion.ReturnToParametersSignatureValidated = false;
Assert.AreEqual(0, authResponse.GetCallbackArguments().Count);
Assert.IsFalse(authResponse.GetCallbackArguments().ContainsKey("a"));
Assert.IsNull(authResponse.GetCallbackArgument("a"));
}
示例13: GetUserData
/// <summary>
/// The get user data.
/// </summary>
/// <param name="accessToken">
/// The access token.
/// </param>
/// <returns>A dictionary of profile data.</returns>
protected override IDictionary<string, string> GetUserData(string accessToken)
{
var builder = new UriBuilder(GetUsersEndpoint);
builder.AppendQueryArgs(
new Dictionary<string, string> {
{ "uid", _accessTokenResponse.user_id.ToString(CultureInfo.InvariantCulture) },
{ "access_token", _accessTokenResponse.access_token }
});
using (var client = new WebClient { Encoding = Encoding.UTF8 })
{
string data = client.DownloadString(builder.Uri);
if (string.IsNullOrEmpty(data))
{
return null;
}
var response = JsonConvert.DeserializeObject<VkApiResponse>(data);
if (response != null && response.response.Length == 1)
{
var userData = new Dictionary<string, string>();
userData.AddItemIfNotEmpty("id", response.response[0].uid);
userData.AddItemIfNotEmpty("name", response.response[0].first_name + " " + response.response[0].last_name);
return userData;
}
}
return new Dictionary<string, string>();
}
示例14: QueryAccessToken
/// <summary>
/// Obtains an access token given an authorization code and callback URL.
/// </summary>
/// <param name="returnUrl">
/// The return url.
/// </param>
/// <param name="authorizationCode">
/// The authorization code.
/// </param>
/// <returns>
/// The access token.
/// </returns>
protected override string QueryAccessToken(Uri returnUrl, string authorizationCode)
{
// Note: Facebook doesn't like us to url-encode the redirect_uri value
var builder = new UriBuilder(TokenEndpoint);
builder.AppendQueryArgs(
new Dictionary<string, string> {
{ "client_id", _appId },
{ "redirect_uri", NormalizeHexEncoding(returnUrl.AbsoluteUri) },
{ "client_secret", _appSecret },
{ "code", authorizationCode },
{ "scope", "" },
});
using (var client = new WebClient())
{
string data = client.DownloadString(builder.Uri);
if (string.IsNullOrEmpty(data))
{
return null;
}
_accessTokenResponse = JsonConvert.DeserializeObject<VkAccessTokenResponse>(data);
if (_accessTokenResponse != null)
{
return _accessTokenResponse.access_token;
}
return string.Empty;
}
}
示例15: QueryAccessToken
private static string QueryAccessToken(string tokenEndpoint, string consumerKey, string consumerSecret, Uri returnUrl, string authorizationCode)
{
// Note: Facebook doesn't like us to url-encode the redirect_uri value
var builder = new UriBuilder(tokenEndpoint);
builder.AppendQueryArgs(
new Dictionary<string, string> {
{ "client_id", consumerKey },
{ "redirect_uri", returnUrl.AbsoluteUri.NormalizeHexEncoding() },
{ "client_secret", consumerSecret },
{ "code", authorizationCode },
{ "scope", "email" },
});
using (var client = new WebClient())
{
var data = client.DownloadString(builder.Uri);
if (string.IsNullOrEmpty(data))
{
return null;
}
var parsedQueryString = HttpUtility.ParseQueryString(data);
return parsedQueryString["access_token"];
}
}