/// <summary> /// OAuth認証ヘッダの署名作成 /// </summary> /// <param name="tokenSecret">アクセストークン秘密鍵</param> /// <param name="method">HTTPメソッド文字列</param> /// <param name="uri">アクセス先Uri</param> /// <param name="parameter">クエリ、もしくはPOSTデータ</param> /// <returns>署名文字列</returns> protected virtual string CreateSignature(string tokenSecret, string method, Uri uri, Dictionary <string, string> parameter) { // パラメタをソート済みディクショナリに詰替(OAuthの仕様) SortedDictionary <string, string> sorted = new SortedDictionary <string, string>(parameter); // URLエンコード済みのクエリ形式文字列に変換 string paramString = this.CreateQueryString(sorted); // アクセス先URLの整形 string url = string.Format("{0}://{1}{2}", uri.Scheme, uri.Host, uri.AbsolutePath); // 署名のベース文字列生成(&区切り)。クエリ形式文字列は再エンコードする string signatureBase = string.Format("{0}&{1}&{2}", method, this.UrlEncode(url), this.UrlEncode(paramString)); // 署名鍵の文字列をコンシューマー秘密鍵とアクセストークン秘密鍵から生成(&区切り。アクセストークン秘密鍵なくても&残すこと) string key = this.UrlEncode(this.consumerSecret) + "&"; if (!string.IsNullOrEmpty(tokenSecret)) { key += this.UrlEncode(tokenSecret); } // 鍵生成&署名生成 using (HMACSHA1 hmac = new HMACSHA1(Encoding.ASCII.GetBytes(key))) { byte[] hash = hmac.ComputeHash(Encoding.ASCII.GetBytes(signatureBase)); return(Convert.ToBase64String(hash)); } }
public static string Serialize(this Template template) { var fields = new XElement("fields"); var parameters = new XElement("parameters", template.Parameters.Select(pair => new XElement ( "parameter", new XAttribute("name", pair.Key), new XAttribute("value", pair.Value) ))); #warning Временно, проблема в процедуре если ей отправить <body> </body> то в БД запишется 0x, а нас это не устраивает XElement xml; if (template.Content.Count() != 0) { xml = new XElement( "template", new XAttribute("type", template.TypeCodeString), new XAttribute("name", template.Name), new XAttribute("entityID", template.Entity.ID), new XAttribute("fileName", template.FileName), fields, parameters, new XElement("body", Convert.ToBase64String(template.Content)) ); } else { xml = new XElement( "template", new XAttribute("type", template.TypeCodeString), new XAttribute("name", template.Name), new XAttribute("entityID", template.Entity.ID), new XAttribute("fileName", template.FileName), new XAttribute("templateByDefault", (template.TemplateByDefault ? "1" : "0")), new XAttribute("treeTypeID", (int)template.TreeTypeEnum), fields, parameters ); } if (template.ID != null) { xml.Add(new XAttribute("id", template.ID)); } foreach (var item in template.Fields) { fields.Add(new XElement( "field", //new XAttribute("id", item.ID), new XAttribute("attributeID", item.Attribute.ID), new XAttribute("formatID", item.Format.ID), new XAttribute("alias", item.Name), // new XAttribute("filter", item.Filter), // new XAttribute("operation", item.Operation), new XAttribute("order", item.Order), new XAttribute("aggregate", item.Aggregation), new XAttribute("predicateInfo", item.PredicateInfo), new XAttribute("predicate", item.Predicate == null ? string.Empty : item.Predicate), // is new add Alex new XAttribute("isVisible", item.IsVisible), new XAttribute("level", item.Level), new XAttribute("listCol", item.Attribute.IsListAttribute ? item.ListAttributeAggregation.ColumnName : string.Empty), new XAttribute("listAggregate", item.Attribute.IsListAttribute ? item.ListAttributeAggregation.AggregateLexem : string.Empty), new XAttribute("crossTableRoleID", item.CrossTableRoleID) )); } return(xml.ToString()); }
/// <summary> /// 获取授权头信息 /// </summary> private async Task <string> GetAuthorization() { var config = await _configProvider.GetConfigAsync(); return($"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes($"api:{config.Key}"))}"); }