public StorageClient(string apiEndpoint, string key, string id) : base(apiEndpoint + "/") { credential = new HawkNet.HawkCredential() { Algorithm = "sha256", Id = id, Key = BinaryHelper.ToHexString(Encoding.UTF8.GetBytes(key)) }; }
// https://github.com/hueniverse/hawk/blob/master/lib/client.js // https://github.com/mozilla/fxa-python-client private AuthenticationHeaderValue GetHawkAuthenticationHeader(HttpMethod method, string requestUri, string jsonPayload, string token, string context, int size) { string tokenId; string reqHMACkey; using (var hmac = new HMACSHA256()) { HKDF hkdf = new HKDF(hmac, BinaryHelper.FromHexString(token)); byte[] sessionToken = hkdf.Expand(BinaryHelper.Kw(context), size); string buffer = BinaryHelper.ToHexString(sessionToken); tokenId = buffer.Substring(0, 64); reqHMACkey = buffer.Substring(64, 64); } HawkNet.HawkCredential credential = new HawkNet.HawkCredential() { Algorithm = "sha256", Key = reqHMACkey, Id = tokenId }; return(GetHawkAuthenticationHeader(method, requestUri, jsonPayload, credential)); }
protected Task Get(string requestUri, HawkNet.HawkCredential credential) { AuthenticationHeaderValue authenticationHeader = GetHawkAuthenticationHeader(HttpMethod.Get, requestUri, null, credential); return(Task.Run(() => Execute(HttpMethod.Get, requestUri, null, null, authenticationHeader, null))); }
protected Task <TResponse> Get <TResponse>(string requestUri, HawkNet.HawkCredential credential) { AuthenticationHeaderValue authenticationHeader = GetHawkAuthenticationHeader(HttpMethod.Get, requestUri, null, credential); return(Task.Run(() => (TResponse)Execute(HttpMethod.Get, requestUri, null, typeof(TResponse), authenticationHeader, null))); }
private AuthenticationHeaderValue GetHawkAuthenticationHeader(HttpMethod method, string requestUri, string jsonPayload, HawkNet.HawkCredential credential) { string parameter = HawkNet.Hawk.GetAuthorizationHeader( httpClient.BaseAddress.DnsSafeHost, method.ToString().ToUpperInvariant(), new Uri(httpClient.BaseAddress, requestUri), credential, payloadHash: HawkNet.Hawk.CalculatePayloadHash(jsonPayload, "application/json", credential)); return(new AuthenticationHeaderValue("Hawk", parameter)); }