public async Task <EncodingParameters> CreateEncodingParametersAsync(HttpRequestMessage request) { if (request == null) { throw new ArgumentNullException("request"); } var token = request.GetAccessToken(); if (token == null) { return(null); } var parameters = new EncodingParameters(token); if (SignMethod) { Logger.Debug("Encoding method"); parameters.Method = request.Method; } if (SignHost) { Logger.Debug("Encoding host"); parameters.Host = request.RequestUri.Host; } if (SignPath) { Logger.Debug("Encoding path"); parameters.Path = request.RequestUri.AbsolutePath; } var queryParamsToSign = GetQueryParamsToSign(request.RequestUri); foreach (var item in queryParamsToSign) { Logger.DebugFormat("Encoding query string param: {0}", item.Key); parameters.QueryParameters.Add(item); } var headersToSign = GetRequestHeadersToSign(request); foreach (var item in headersToSign) { Logger.DebugFormat("Encoding request header: {0}", item.Key); parameters.RequestHeaders.Add(item); } if (SignBody) { Logger.Debug("Encoding body"); parameters.Body = await request.ReadBodyAsync(); } return(parameters); }
public string Sign(EncodingParameters payload) { if (payload == null) { throw new ArgumentNullException("payload"); } var encodedPayload = payload.Encode(); return(JWT.Encode(encodedPayload.Encode(), _key, _alg)); }