public NegotiationToken GetToken() { WebRequest request = WebRequest.Create(requestUri); request.Method = "POST"; Nonce nonce = Nonce.Generate(); TimeStamp timestamp = TimeStamp.Generate(); BaseString baseString = new BaseString(request.RequestUri, request.Method, nonce, timestamp, credentials, HmacSha1Signature.MethodName); Signature signature = new HmacSha1Signature(baseString.ToString(), credentials); AuthorizationHeader header = new AuthorizationHeader(credentials, nonce, timestamp, signature); request.Headers.Add(HttpRequestHeader.Authorization, header.ToString()); using (WebResponse res = request.GetResponse()) using (Stream s = res.GetResponseStream()) using (StreamReader sr = new StreamReader(s)) { NameValueCollection response = HttpUtility.ParseQueryString(sr.ReadToEnd()); return(new NegotiationToken(response["oauth_token"], response["oauth_token_secret"])); } }
public static string Login(Application application, string redirectUrl, int response_type, string scope, string state) { var timeStamp = Timestamp.Now(); List <KeyValuePair <string, string> > oauthparameters = new List <KeyValuePair <string, string> >(); oauthparameters.Add(new KeyValuePair <string, string>("oauth_consumer_key", application.ConsumerKey)); oauthparameters.Add(new KeyValuePair <string, string>("oauth_timestamp", timeStamp)); oauthparameters.Add(new KeyValuePair <string, string>("oauth_version", Variables.Version)); oauthparameters.Add(new KeyValuePair <string, string> ("oauth_consumer_secret", application.ConsumerSecret)); oauthparameters.Add(new KeyValuePair <string, string>("redirect_uri", String.Format(@"""{0}""", redirectUrl))); oauthparameters.Add(new KeyValuePair <string, string>("response_type", response_type.ToString())); oauthparameters.Add(new KeyValuePair <string, string>("scope", scope)); oauthparameters.Add(new KeyValuePair <string, string>("state", state)); var basestring = BaseString.Transform(oauthparameters); var signature = Signature.GetSignature(basestring, application.ConsumerSecret); var header = String.Format(@"OAuth oauth_consumer_key={0},oauth_timestamp={1},oauth_version=1.0,redirect_uri={2},response_type={3},scope={4},state={5},oauth_signature={6}", application.ConsumerKey, timeStamp, String.Format(@"""{0}""", redirectUrl), response_type, scope, state, signature); return(header); }
public static string AccessToken(Application application, string temporaryCode, string grand_type) { var timeStamp = Timestamp.Now(); List <KeyValuePair <string, string> > oauthparameters = new List <KeyValuePair <string, string> >(); oauthparameters.Add(new KeyValuePair <string, string>("code", temporaryCode)); oauthparameters.Add(new KeyValuePair <string, string>("grand_type", grand_type)); oauthparameters.Add(new KeyValuePair <string, string>("oauth_consumer_key", application.ConsumerKey)); oauthparameters.Add(new KeyValuePair <string, string>("oauth_timestamp", timeStamp)); oauthparameters.Add(new KeyValuePair <string, string>("oauth_version", Variables.Version)); oauthparameters.Add(new KeyValuePair <string, string> ("oauth_consumer_secret", application.ConsumerSecret)); oauthparameters.Add(new KeyValuePair <string, string>("redirect_uri", "none")); var basestring = BaseString.Transform(oauthparameters); var signature = Signature.GetSignature(basestring, application.ConsumerSecret); var header = String.Format(@"OAuth code={0},grand_type={1},oauth_consumer_key={2},oauth_timestamp={3},oauth_version=1.0,redirect_uri={4},oauth_signature={5}", temporaryCode, grand_type, application.ConsumerKey, timeStamp, "none", signature); return(header); }
public bool Equals(NuyenString other) { if (UseDecimal != other.UseDecimal) { return(false); } return(UseDecimal ? Value == other.Value : BaseString.Equals(other.BaseString, StringComparison.Ordinal)); }
protected override Signature GenerateSignature(WebRequest request, Nonce nonce, TimeStamp timestamp) { BaseString baseString = new BaseString(request.RequestUri, request.Method, nonce, timestamp, credentials, HmacSha1Signature.MethodName); baseString.Token = token; return(new RsaSha1Signature(baseString.ToString(), key)); }
public virtual int CompareTo(Allele other) { if (Reference && other.NonReference) { return(-1); } else if (NonReference && other.Reference) { return(1); } else { return(BaseString.CompareTo(other.BaseString)); // todo -- potential performance issue } }
/// <summary> /// Get the string representation of the <see cref="LiteralText"/>, with escaped characters converted. /// Note: The <see cref="Parser"/> puts each escaped character of an input string /// into its own <see cref="LiteralText"/> item. /// </summary> /// <returns>The string representation of the <see cref="LiteralText"/>, with escaped characters converted.</returns> public override ReadOnlySpan <char> AsSpan() { if (Length == 0) { return(ReadOnlySpan <char> .Empty); } // The buffer is only for 1 character - each escaped char goes into its own LiteralText return(SmartSettings.Parser.ConvertCharacterStringLiterals && BaseString.AsSpan(StartIndex)[0] == SmartSettings.Parser.CharLiteralEscapeChar ? EscapedLiteral.UnEscapeCharLiterals(SmartSettings.Parser.CharLiteralEscapeChar, BaseString.AsSpan(StartIndex, Length), false, new char[1]) : BaseString.AsSpan(StartIndex, Length)); }
/// <summary> /// Uses Levenshtein Distance to determine the closest string. Outputs the string and the distance /// </summary> /// <param name="context"></param> protected override void Execute(NativeActivityContext context) { LevenshteinEngine engine = new LevenshteinEngine(BaseString.Get(context)); Boolean first = true; foreach (String possible in Possibles.Get(context)) { int currentDistance = engine.Distance(possible); if (currentDistance < Distance.Get(context) || first) { Distance.Set(context, currentDistance); SelectedString.Set(context, possible); } first = false; } }
public static string Operation(Application application, string accessToken) { var timeStamp = Timestamp.Now(); List <KeyValuePair <string, string> > oauthparameters = new List <KeyValuePair <string, string> >(); oauthparameters.Add(new KeyValuePair <string, string>("access_token", accessToken)); oauthparameters.Add(new KeyValuePair <string, string>("oauth_consumer_key", application.ConsumerKey)); oauthparameters.Add(new KeyValuePair <string, string>("oauth_timestamp", timeStamp)); oauthparameters.Add(new KeyValuePair <string, string>("oauth_version", Variables.Version)); oauthparameters.Add(new KeyValuePair <string, string> ("oauth_consumer_secret", application.ConsumerSecret)); var basestring = BaseString.Transform(oauthparameters); var signature = Signature.GetSignature(basestring, application.ConsumerSecret); var header = String.Format(@"OAuth access_token={0},oauth_consumer_key={1},oauth_timestamp={2},oauth_version=1.0,oauth_signature={3}", accessToken, application.ConsumerKey, timeStamp, signature); return(header); }
/// <summary> /// Gets the <see cref="ReadOnlySpan{T}"/> representation of this <see cref="FormatItem"/>. /// </summary> /// <returns>The <see cref="ReadOnlySpan{T}"/> representation of this <see cref="FormatItem"/></returns> public virtual ReadOnlySpan <char> AsSpan() => EndIndex <= StartIndex ? BaseString.AsSpan(StartIndex) : BaseString.AsSpan(StartIndex, Length);
protected override void Execute(CodeActivityContext context) { IDistanceEngine engine = DistanceEngineFactory(BaseString.Get(context)); Distance.Set(context, engine.Distance(ComparisonString.Get(context))); }
public Fixture Then_it_does_not_contain(string what) { return(new YesNoFixture(BaseString.Omits(what), "Expected [" + BaseString.Value + "] NOT to contain [" + what + "]", 2)); }
public Fixture Then_the_base_string_contains(string what) { return(new YesNoFixture(BaseString.Contains(what), "Expected [" + BaseString.Value + "] to contain [" + what + "]", 2)); }
public Fixture Then_the_base_string_matches(string what) { return(new YesNoFixture(BaseString.Matches(Uri.EscapeDataString(what)), "Expected [" + BaseString.Value + "] to match pattern [" + what + "]", 2)); }
public override string ToString() => BaseString.Substring(Start, Length);