本文整理匯總了C#中System.UriBuilder.AppendQueryArgument方法的典型用法代碼示例。如果您正苦於以下問題:C# UriBuilder.AppendQueryArgument方法的具體用法?C# UriBuilder.AppendQueryArgument怎麽用?C# UriBuilder.AppendQueryArgument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.UriBuilder
的用法示例。
在下文中一共展示了UriBuilder.AppendQueryArgument方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetServiceLoginUrl
protected override Uri GetServiceLoginUrl(Uri returnUrl) {
var builder = new UriBuilder(Endpoints.Authorization);
builder.AppendQueryArgument("response_type", "code");
builder.AppendQueryArgument("client_id", ClientId);
builder.AppendQueryArgument("redirect_uri", returnUrl.AbsoluteUri);
return builder.Uri;
}
示例2: QueryAccessToken
protected override string QueryAccessToken(Uri returnUrl, string authorizationCode)
{
var builder = new UriBuilder(TokenEndpoint);
builder.AppendQueryArgument("client_id", this.appId);
builder.AppendQueryArgument("client_secret", this.clientSecret);
builder.AppendQueryArgument("code", authorizationCode);
var redirectUri = NormalizeHexEncoding(returnUrl.AbsoluteUri);
builder.AppendQueryArgument("redirect_uri", redirectUri);
//builder.AppendQueryArgument("grant_type", "client_credentials");
using (WebClient client = new WebClient())
{
string data = client.DownloadString(builder.Uri);
if (string.IsNullOrEmpty(data))
{
return null;
}
JObject dataObject = JObject.Parse(data);
//TODO: Проверять успешность запроса
var accessToken = dataObject["access_token"].ToString();
var userId = (int)dataObject["user_id"];
HttpContext.Current.Session[accessToken] = Convert.ToString(userId);
return accessToken;
}
}
示例3: GetUserData
protected override IDictionary<string, string> GetUserData(string accessToken)
{
var url = ApiEndpoint + "users.get";
var builder = new UriBuilder(url);
builder.AppendQueryArgument("access_token", accessToken);
var userId = Convert.ToString(HttpContext.Current.Session[accessToken]);
if (!string.IsNullOrWhiteSpace(userId))
{
builder.AppendQueryArgument("uids", userId);
}
using (WebClient client = new WebClient())
{
client.Encoding = Encoding.UTF8;
string data = client.DownloadString(builder.Uri);
if (string.IsNullOrEmpty(data))
{
return null;
}
dynamic jsonResult = JObject.Parse(data);
//TODO: Проверять успешность запроса
var userData = new Dictionary<string, string>();
userData.Add("id", Convert.ToString(jsonResult.response[0].uid));
userData.Add("username", Convert.ToString(jsonResult.response[0].uid));
userData.Add("name", string.Format("{0} {1}",
Convert.ToString(jsonResult.response[0].first_name),
Convert.ToString(jsonResult.response[0].last_name)));
return userData;
}
}
示例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 uriBuilder = new UriBuilder(AuthorizeUrl);
uriBuilder.AppendQueryArgument("client_id", this.clientId);
uriBuilder.AppendQueryArgument("redirect_uri", returnUrl.ToString());
return uriBuilder.Uri;
}
示例5: 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(_authorizationEndpoint);
builder.AppendQueryArgument("client_id", _appId);
builder.AppendQueryArgument("redirect_uri", returnUrl.AbsoluteUri);
return builder.Uri;
}
示例6: GetServiceLoginUrl
protected override Uri GetServiceLoginUrl(Uri returnUrl)
{
var builder = new UriBuilder(AuthorizationEndpoint);
builder.AppendQueryArgument("client_id", this.appId);
builder.AppendQueryArgument("scope", "groups, wall");
builder.AppendQueryArgument("redirect_uri", returnUrl.AbsoluteUri);
builder.AppendQueryArgument("display", "page");
return builder.Uri;
}
示例7: GetServiceLoginUrlInternal
internal Uri GetServiceLoginUrlInternal(Uri returnUrl)
{
UriBuilder uriBuilder = new UriBuilder(AuthorizationEndpoint);
uriBuilder.AppendQueryArgument("client_id", _clientID);
uriBuilder.AppendQueryArgument("redirect_uri", returnUrl.AbsoluteUri);
//uriBuilder.AppendQueryArgument("scope", "user");
return uriBuilder.Uri;
}
示例8: GetServiceLoginUrl
protected override Uri GetServiceLoginUrl(Uri returnUrl)
{
var builder = new UriBuilder(AUTHORIZATION_ENDPOINT);
builder.AppendQueryArgument("client_id", _appId);
builder.AppendQueryArgument("redirect_uri", returnUrl.AbsoluteUri);
builder.AppendQueryArgument("scope", "user:email");
return builder.Uri;
}
示例9: GetServiceLoginUrl
protected override Uri GetServiceLoginUrl(Uri returnUrl)
{
UriBuilder uriBuilder = new UriBuilder(AuthorizationEndpoint);
uriBuilder.AppendQueryArgument("client_id", this.clientId);
uriBuilder.AppendQueryArgument("redirect_uri", returnUrl.GetLeftPart(UriPartial.Path));
uriBuilder.AppendQueryArgument("response_type", "code");
uriBuilder.AppendQueryArgument("scope", "https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email");
uriBuilder.AppendQueryArgument("state", returnUrl.Query.Substring(1));
return uriBuilder.Uri;
}
示例10: GetServiceLoginUrl
protected override Uri GetServiceLoginUrl(Uri returnUrl)
{
UriBuilder builder = new UriBuilder(AuthorizationEndpoint);
builder.AppendQueryArgument("client_id", ApplicationId);
builder.AppendQueryArgument("response_type", "code");
builder.AppendQueryArgument("scope", Scope);
builder.AppendQueryArgument("redirect_uri", returnUrl.AbsoluteUri);
builder.AppendQueryArgument("nonce", Guid.NewGuid().ToString().Replace("-", ""));
return builder.Uri;
}
示例11: 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.AppendQueryArgument("client_id",this.appId);
builder.AppendQueryArgument("redirect_uri", returnUrl.AbsoluteUri);
builder.AppendQueryArgument("scope", this.scope);
builder.AppendQueryArgument("response_type", "code");
return builder.Uri;
}
示例12: GetUserData
protected override IDictionary<string, string> GetUserData(string accessToken)
{
UriBuilder uriBuilder = new UriBuilder(UserInfoEndpoint);
uriBuilder.AppendQueryArgument("access_token", accessToken);
WebRequest webRequest = WebRequest.Create(uriBuilder.Uri);
using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
{
if (webResponse.StatusCode == HttpStatusCode.OK)
{
using (var responseStream = webResponse.GetResponseStream())
{
if (responseStream == null)
return null;
StreamReader streamReader = new StreamReader(responseStream);
Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(streamReader.ReadToEnd());
// Add a username field in the dictionary
if (values.ContainsKey("email") && !values.ContainsKey("username"))
values.Add("username", values["email"]);
return values;
}
}
}
return null;
}
示例13: GetUserData
protected override IDictionary<string, string> GetUserData(string accessToken)
{
var client = new RestClient();
var builder = new UriBuilder(UsersEndpoint);
builder.AppendQueryArgument("access_token", accessToken);
var request = new RestRequest(builder.Uri.AbsoluteUri, Method.GET);
var response = client.Execute(request);
if (response.StatusCode != System.Net.HttpStatusCode.OK)
return new Dictionary<string, string>();
var json = JObject.Parse(response.Content);
var strs = new Dictionary<string, string>();
strs["id"] = json["id"].ToString();
strs["username"] = json["login"].ToString();
try
{
strs["name"] = json["name"].ToString();
}
catch
{
}
return strs;
}
示例14: Authorize
public ActionResult Authorize() {
var incomingAuthzRequest = this.authorizationServer.ReadAuthorizationRequest(this.Request);
if (incomingAuthzRequest == null) {
return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Missing authorization request");
}
var returnTo = new UriBuilder(this.Url.AbsoluteAction("AuthorizeWithMicrosoftAccount"));
returnTo.AppendQueryArgument("nestedAuth", this.Request.Url.Query);
var scopes = new[] { "wl.signin", "wl.basic", "wl.emails" }; // this is a subset of what the client app asks for, ensuring automatic approval.
return LiveConnectClient.PrepareRequestUserAuthorization(scopes, returnTo.Uri).AsActionResult();
}
示例15: GetUserData
/// <summary>
/// Given the access token, gets the logged-in user's data. The returned dictionary must include two keys 'id', and 'username'.
/// </summary>
/// <param name="accessToken">The access token of the current user.</param>
/// <returns>
/// A dictionary contains key-value pairs of user data
/// </returns>
protected override IDictionary<string, string> GetUserData(string accessToken)
{
using (var webClient = CreateWebClient())
{
var uriBuilder = new UriBuilder(ProfileUrl);
uriBuilder.AppendQueryArgument("access_token", accessToken);
var profileResponse = webClient.DownloadString(uriBuilder.Uri);
var profile = JsonConvert.DeserializeObject<dynamic>(profileResponse);
return new Dictionary<string, string>
{
{ "login", profile.login.ToString() },
{ "id", profile.id.ToString() },
{ "avatar_url", profile.avatar_url.ToString() },
{ "gravatar_id", profile.gravatar_id.ToString() },
{ "url", profile.url.ToString() },
{ "name", profile.name.ToString() },
{ "company", profile.company.ToString() },
{ "blog", profile.blog.ToString() },
{ "location", profile.location.ToString() },
{ "email", profile.email.ToString() },
{ "hireable", profile.hireable.ToString() },
{ "bio", profile.bio.ToString() },
{ "public_repos", profile.public_repos.ToString() },
{ "public_gists", profile.public_gists.ToString() },
{ "followers", profile.followers.ToString() },
{ "following", profile.following.ToString() },
{ "html_url", profile.html_url.ToString() },
{ "created_at", profile.created_at.ToString() },
{ "type", profile.type.ToString() },
{ "total_private_repos", profile.total_private_repos.ToString() },
{ "owned_private_repos", profile.owned_private_repos.ToString() },
{ "private_gists", profile.private_gists.ToString() },
{ "disk_usage", profile.disk_usage.ToString() },
{ "collaborators", profile.collaborators.ToString() },
{ "plan_name", profile.plan.name.ToString() },
{ "plan_space", profile.plan.space.ToString() },
{ "plan_collaborators", profile.plan.collaborators.ToString() },
{ "plan_private_repos", profile.plan.private_repos.ToString() }
};
}
}