public override Dictionary <string, object> AddAuthenticationToParameters(string uri, HttpMethod method, Dictionary <string, object> parameters, bool signed, HttpMethodParameterPosition parameterPosition, ArrayParametersSerialization arraySerialization) { if (!signed) { return(parameters); } parameters.Add("nonce", _nonceProvider.GetNonce()); return(parameters); }
public void AddContentSecurityPolicy(CSPOptions cspOptions) { var csp = cspOptions.ToString(); if (cspOptions.HasNonce) { csp = csp.Replace("'nonce-'", $"'nonce-{nonceProvider.GetNonce()}'"); } contextAccessor.HttpContext.Response.Headers.Add("Content-Security-Policy", csp); }
private void Auth(HttpClient httpClient, string url, HttpMethods httpMethod, string @params = "") { var key = _bitmexAuthorization.Key ?? string.Empty; var secret = _bitmexAuthorization.Secret ?? string.Empty; var nonce = _nonceProvider.GetNonce().ToString(); var signatureString = _signatureProvider.CreateSignature(secret, $"{httpMethod}{url}{nonce}{@params}"); httpClient.DefaultRequestHeaders.Add("api-nonce", nonce); httpClient.DefaultRequestHeaders.Add("api-key", key); httpClient.DefaultRequestHeaders.Add("api-signature", signatureString); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }
private bool Authorize() { var nonce = _nonceProvider.GetNonce(); var respReceived = new ManualResetEvent(false); var data = new string[0]; var error = string.Empty; OperationResultEventHandler resultReceived = args => { if (args.OperationType == OperationType.authKey) { _isAuthorized = args.Result; error = args.Error; data = args.Args; respReceived.Set(); } }; var signatureString = _signatureProvider.CreateSignature(_bitmexAuthorization.Secret, $"GET/realtime{nonce}"); var message = new SocketAuthorizationMessage(_bitmexAuthorization.Key, nonce, signatureString); _bitmexApiSocketProxy.OperationResultReceived += resultReceived; _bitmexApiSocketProxy.Send(message); var waitResult = respReceived.WaitOne(SocketMessageResponseTimeout); _bitmexApiSocketProxy.OperationResultReceived -= resultReceived; if (!waitResult) { throw new BitmexSocketAuthorizationException("Authorization Failed: timeout waiting authorization response"); } if (!IsAuthorized) { throw new BitmexSocketAuthorizationException(error, data); } return(IsAuthorized); }
public override void Process(TagHelperContext context, TagHelperOutput output) { output.Attributes.RemoveAll("csp-nonce"); output.Attributes.Add("nonce", new HtmlString(nonceProvider.GetNonce())); }
public long GetNonce() => _nonceProvider.GetNonce();