Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<LangVersion>13</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == 'NET6_0_OR_GREATER'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,22 @@ public Task LoadIfNeededAsync(CredentialDescription credentialDescription, Crede

internal static X509Certificate2 LoadFromBase64Encoded(string certificateBase64, X509KeyStorageFlags x509KeyStorageFlags)
{
#pragma warning disable SYSLIB0057 // Type or member is obsolete
return new X509Certificate2(
Convert.FromBase64String(certificateBase64),
(string?)null,
x509KeyStorageFlags);
#pragma warning restore SYSLIB0057 // Type or member is obsolete
}

internal static X509Certificate2 LoadFromBase64Encoded(string certificateBase64, string password, X509KeyStorageFlags x509KeyStorageFlags)
{
#pragma warning disable SYSLIB0057 // Type or member is obsolete
return new X509Certificate2(
Convert.FromBase64String(certificateBase64),
password,
x509KeyStorageFlags);
#pragma warning restore SYSLIB0057 // Type or member is obsolete
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ private static X509Certificate2 LoadFromPath(
{
X509KeyStorageFlags x509KeyStorageFlags = CertificateLoaderHelper.DetermineX509KeyStorageFlag();

#pragma warning disable SYSLIB0057 // Type or member is obsolete
return new X509Certificate2(
certificateFileName,
password,
x509KeyStorageFlags);
#pragma warning restore SYSLIB0057 // Type or member is obsolete
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ public async Task LoadIfNeededAsync(CredentialDescription credentialDescription,
// Return a certificate with only the public key if the private key is not exportable.
if (certificate.Policy?.Exportable != true)
{
#pragma warning disable SYSLIB0057 // Type or member is obsolete
return new X509Certificate2(
certificate.Cer,
(string?)null,
x509KeyStorageFlags);
#pragma warning restore SYSLIB0057 // Type or member is obsolete
}

// Parse the secret ID and version to retrieve the private key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ private X509Certificate2 CreateSelfSignedCertificateAddAddToCertStore(string cer
var cert = req.CreateSelfSigned(notBefore.HasValue ? notBefore.Value : DateTimeOffset.Now, expiry);

byte[] bytes = cert.Export(X509ContentType.Pfx, (string?)null);
#pragma warning disable SYSLIB0057 // Type or member is obsolete
X509Certificate2 certWithPrivateKey = new(bytes);
#pragma warning restore SYSLIB0057 // Type or member is obsolete

// Add it to the local cert store.
X509Store x509Store = new(StoreName.My, StoreLocation.CurrentUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public void TestFromStoreWithThumbprint(string certificateThumbprint, StoreLocat
[Fact]
public void TestFromCertificate()
{
using X509Certificate2 certificate2 = new X509Certificate2(new byte[0]);
#pragma warning disable SYSLIB0057 // Type or member is obsolete
using X509Certificate2 certificate2 = new([]);
#pragma warning restore SYSLIB0057 // Type or member is obsolete
CertificateDescription certificateDescription =
CertificateDescription.FromCertificate(certificate2);
}
Expand Down
8 changes: 6 additions & 2 deletions tests/Microsoft.Identity.Web.Test/MsAuth10AtPopTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ public void MsAuth10AtPop_ThrowsWithNullPopKeyTest()
{
// Arrange
IConfidentialClientApplication app = CreateBuilder();
var clientCertificate = new X509Certificate2(new byte[0]);
#pragma warning disable SYSLIB0057 // Type or member is obsolete
using X509Certificate2 clientCertificate = new([]);
#pragma warning restore SYSLIB0057 // Type or member is obsolete
var jwkClaim = "jwk_claim";
var clientId = "client_id";

Expand All @@ -99,7 +101,9 @@ public void MsAuth10AtPop_ThrowsWithNullJwkClaimTest()
{
// Arrange
IConfidentialClientApplication app = CreateBuilder();
var clientCertificate = new X509Certificate2(new byte[0]);
#pragma warning disable SYSLIB0057 // Type or member is obsolete
using X509Certificate2 clientCertificate = new([]);
#pragma warning restore SYSLIB0057 // Type or member is obsolete
var popPublicKey = "pop_key";
var clientId = "client_id";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected override HttpContext CreateHttpContext()
[Fact]
public async Task TokenValidated_MissingScopesAndRoles_AuthenticationFailsAsync()
{
Assert.True(_tokenContext.Result.Succeeded);
Assert.True(_tokenContext.Result!.Succeeded);
await _jwtEvents.TokenValidated(_tokenContext);
Assert.False(_tokenContext.Result.Succeeded);
}
Expand All @@ -68,7 +68,7 @@ protected override HttpContext CreateHttpContext()
[Fact]
public async Task TokenValidated_WithScopesAndRoles_AuthenticationSucceedsAsync()
{
Assert.True(_tokenContext.Result.Succeeded);
Assert.True(_tokenContext.Result!.Succeeded);
await _jwtEvents.TokenValidated(_tokenContext);
Assert.True(_tokenContext.Result.Succeeded);
}
Expand Down
Loading