public OAuth2ConcentQueryResult Authorization(OAuth2ConcentQuery query, string codeVerifer = "") { query.client_id = this.clientKey; this.scope = query.scope; this.redirectUri = query.redirect_uri; var concentUrlArg = EndPoints.Oauth2.OriginalString + $"{URLArgEncoder.ToURLArg(query)}"; Console.WriteLine("Please input code of redirect url code="); Process.Start(new ProcessStartInfo("cmd", $"/c start {concentUrlArg}") { CreateNoWindow = true }); this.oauth2Code = Console.ReadLine(); if (string.IsNullOrEmpty(this.oauth2Code)) { return(new OAuth2ConcentQueryResult() { error = "oauth_code_error" //error_description = "inputed oauth_code is null or empty", }); } query.client_id = this.clientKey; return(new OAuth2ConcentQueryResult() { code = this.oauth2Code, }); }
public async ValueTask <IEnumerable <UserMessage> > GetAllAsync(long roomId, bool isForceMode = false) { // TODO QueryAsync + data is error // single arg is invalid ? var uri = $"{EndPoints.RoomMessages(roomId)}?force={URLArgEncoder.BoolToInt(isForceMode).ToString()}"; return(await this.chatworkClient.QueryAsync <List <UserMessage> >(new Uri(uri), HttpMethod.Get, new Dictionary <string, string>())); }
public async ValueTask <ElementId> SendAsync(long roomId, string message, bool isSelfUnread) { var data = new Dictionary <string, string>() { { "body", message }, { "self_unread", URLArgEncoder.BoolToInt(isSelfUnread).ToString() } }; return(await this.chatworkClient.QueryAsync <MessageId>(EndPoints.RoomMessages(roomId), HttpMethod.Post, data)); }
public async ValueTask <InviteLink> UpdateAsync(long roomId, string uniqueName, string description, bool requireAcceptance) { var data = new Dictionary <string, string>() { { "code", uniqueName }, { "description", description }, { "need_acceptance", URLArgEncoder.BoolToInt(requireAcceptance).ToString() }, }; return(await this.chatworkClient.QueryAsync <InviteLink>(EndPoints.RoomTasks(roomId), HttpMethod.Put, data)); }
public async Task <OAuth2TokenQueryResult> UpdateToken(OAuth2TokenQuery.GrantType grantType = OAuth2TokenQuery.GrantType.RefreshToken, string codeVerifer = "") { OAuth2TokenQuery tokenQuery = new OAuth2TokenQuery(grantType) { scope = this.scope, redirect_uri = this.redirectUri, }; HttpRequestMessage request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = EndPoints.Token, }; if (grantType == OAuth2TokenQuery.GrantType.AuthroizationCode) { tokenQuery.code = this.oauth2Code; } else if (grantType == OAuth2TokenQuery.GrantType.RefreshToken) { tokenQuery.refresh_token = this.refleshToken; } request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue( "Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{this.clientKey}:{this.secretKey}"))); request.Content = new FormUrlEncodedContent(URLArgEncoder.ToDictionary(tokenQuery)); HttpClient client = new HttpClient(); var response = await client.SendAsync(request); var stream = await response.Content.ReadAsStreamAsync(); using (StreamReader reader = new StreamReader(stream)) { var result = JsonConvert.DeserializeObject <OAuth2TokenQueryResult>(reader.ReadToEnd()); this.tokenExpired = result.expires_in; this.tokenQueryTime = DateTime.Now; this.refleshToken = result.refresh_token; this.accessToken = result.access_token; return(result); } }
public async ValueTask <UserFile> GetAsync(long roomId, long fileId, bool createDownloadLink) { var uri = $"{EndPoints.RoomFiles(roomId)}?create_download_url={URLArgEncoder.BoolToInt(createDownloadLink)}"; return(await this.chatworkClient.QueryAsync <UserFile>(new Uri(uri), HttpMethod.Get, new Dictionary <string, string>())); }