/// <summary> /// Creates the HTTP Authorization header in hawk scheme. /// </summary> internal async Task CreateClientAuthorizationInternalAsync(HttpRequestMessage request, DateTime utcNow) { var credential = credentialFunc(); this.artifacts = new ArtifactsContainer() { Id = credential.Id, Timestamp = utcNow.AddSeconds(HawkClient.CompensatorySeconds).ToUnixTime(), Nonce = NonceGenerator.Generate() }; if (!String.IsNullOrWhiteSpace(this.ApplicationSpecificData)) { this.artifacts.ApplicationSpecificData = this.ApplicationSpecificData; } var normalizedRequest = new NormalizedRequest(request, this.artifacts); this.crypto = new Cryptographer(normalizedRequest, this.artifacts, credential); // Sign the request await crypto.SignAsync(request.Content); request.Headers.Authorization = new AuthenticationHeaderValue( HawkConstants.Scheme, this.artifacts.ToAuthorizationHeaderParameter()); }
/// <summary> /// Creates the HTTP Authorization header in hawk scheme. /// </summary> internal async Task CreateClientAuthorizationInternalAsync(IRequestMessage request, DateTime utcNow) { var credential = options.CredentialsCallback(); this.artifacts = new ArtifactsContainer() { Id = credential.Id, Timestamp = utcNow.AddSeconds(HawkClient.CompensatorySeconds).ToUnixTime(), Nonce = NonceGenerator.Generate() }; if (options.NormalizationCallback != null) { this.artifacts.ApplicationSpecificData = options.NormalizationCallback(request); } var normalizedRequest = new NormalizedRequest(request, this.artifacts, options.HostNameSource); this.crypto = new Cryptographer(normalizedRequest, this.artifacts, credential); // Sign the request bool includePayloadHash = options.RequestPayloadHashabilityCallback != null && options.RequestPayloadHashabilityCallback(request); string payload = includePayloadHash ? await request.ReadBodyAsStringAsync() : null; crypto.Sign(payload, request.ContentType); request.Authorization = new AuthenticationHeaderValue(HawkConstants.Scheme, this.artifacts.ToAuthorizationHeaderParameter()); }
public void GenerateNonceTest() { var generator = new NonceGenerator(); var nonce = generator.Generate(); nonce.Should().NotBeNullOrEmpty(); nonce.Length.Should().Be(44); }