Skip to content

Commit

Permalink
Merge pull request #40 from mdsol/develop
Browse files Browse the repository at this point in the history
Release of v3.1.0
  • Loading branch information
bvillanueva-mdsol authored Oct 15, 2018
2 parents 14fd52f + 5ce5ffe commit 1227b4f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes in Medidata.MAuth

## v3.1.0
- **[Core]** Added a new extension method to the utilities which will authenticate a `HttpRequestMessage` with the
provided options.

## v3.0.4
- **[Core]** Fixed an issue with HTTP requests having binary content (the authentication was failing in this case)

Expand Down
12 changes: 12 additions & 0 deletions src/Medidata.MAuth.Core/UtilityExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace Medidata.MAuth.Core
{
Expand Down Expand Up @@ -55,5 +57,15 @@ public static bool TryParseAuthenticationHeader(this string headerValue,

return true;
}

/// <summary>
/// Authenticates a <see cref="HttpRequestMessage"/> with the provided options.
/// </summary>
/// <param name="request">The requesst message to authenticate.</param>
/// <param name="options">The MAuth options to use for the authentication.</param>
/// <returns>The task for the operation that is when completes will result in <see langword="true"/> if
/// the authentication is successful; otherwise <see langword="false"/>.</returns>
public static Task<bool> Authenticate(this HttpRequestMessage request, MAuthOptionsBase options) =>
new MAuthAuthenticator(options).AuthenticateRequest(request);
}
}
25 changes: 25 additions & 0 deletions tests/Medidata.MAuth.Tests/UtilityExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,30 @@ public static void ParseAuthenticationHeader_WithInvalidAuthHeader_WillThrowExce
// Act, Assert
Assert.Throws<ArgumentException>(() => invalid.ParseAuthenticationHeader());
}

[Theory]
[InlineData("GET")]
[InlineData("DELETE")]
[InlineData("POST")]
[InlineData("PUT")]
public static async Task Authenticate_WithValidRequest_WillAuthenticate(string method)
{
// Arrange
var testData = await method.FromResource();

var signedRequest = await testData.ToHttpRequestMessage()
.AddAuthenticationInfo(new PrivateKeyAuthenticationInfo()
{
ApplicationUuid = testData.ApplicationUuid,
PrivateKey = TestExtensions.ClientPrivateKey,
SignedTime = testData.SignedTime
});

// Act
var isAuthenticated = await signedRequest.Authenticate(TestExtensions.ServerOptions);

// Assert
Assert.True(isAuthenticated);
}
}
}
2 changes: 1 addition & 1 deletion version.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Version>3.0.4</Version>
<Version>3.1.0</Version>
</PropertyGroup>
</Project>

0 comments on commit 1227b4f

Please sign in to comment.