Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/caeEnabled #322

Merged
merged 4 commits into from
Aug 9, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.11.0] - 2024-08-08

- Enabled Continuous Access evaluation by default.

## [1.10.1] - 2024-08-01

- Cleans up enum serialization to read from attributes for form and text serialization [#284](https://github.com/microsoft/kiota-dotnet/issues/284)
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<!-- Common default project properties for ALL projects-->
<PropertyGroup>
<VersionPrefix>1.10.1</VersionPrefix>
<VersionPrefix>1.11.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<!-- This is overidden in test projects by setting to true-->
<IsTestProject>false</IsTestProject>
Expand Down
20 changes: 18 additions & 2 deletions src/authentication/azure/AzureIdentityAccessTokenProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
/// <summary>
/// Provides an implementation of <see cref="IAccessTokenProvider"/> for Azure.Identity.
/// </summary>
public class AzureIdentityAccessTokenProvider : IAccessTokenProvider, IDisposable

Check warning on line 18 in src/authentication/azure/AzureIdentityAccessTokenProvider.cs

View workflow job for this annotation

GitHub Actions / Build

Fix this implementation of 'IDisposable' to conform to the dispose pattern. (https://rules.sonarsource.com/csharp/RSPEC-3881)

Check warning on line 18 in src/authentication/azure/AzureIdentityAccessTokenProvider.cs

View workflow job for this annotation

GitHub Actions / Build

Fix this implementation of 'IDisposable' to conform to the dispose pattern. (https://rules.sonarsource.com/csharp/RSPEC-3881)

Check warning on line 18 in src/authentication/azure/AzureIdentityAccessTokenProvider.cs

View workflow job for this annotation

GitHub Actions / Build

Fix this implementation of 'IDisposable' to conform to the dispose pattern. (https://rules.sonarsource.com/csharp/RSPEC-3881)

Check warning on line 18 in src/authentication/azure/AzureIdentityAccessTokenProvider.cs

View workflow job for this annotation

GitHub Actions / Build

Fix this implementation of 'IDisposable' to conform to the dispose pattern. (https://rules.sonarsource.com/csharp/RSPEC-3881)
{
private static readonly object BoxedTrue = true;
private static readonly object BoxedFalse = false;

private readonly TokenCredential _credential;
private readonly ActivitySource _activitySource;
private readonly bool _isCaeEnabled;
private readonly HashSet<string> _scopes;
/// <inheritdoc />
public AllowedHostsValidator AllowedHostsValidator { get; protected set; }
Expand All @@ -33,7 +34,8 @@
/// <param name="allowedHosts">The list of allowed hosts for which to request access tokens.</param>
/// <param name="scopes">The scopes to request the access token for.</param>
/// <param name="observabilityOptions">The observability options to use for the authentication provider.</param>
public AzureIdentityAccessTokenProvider(TokenCredential credential, string[]? allowedHosts = null, ObservabilityOptions? observabilityOptions = null, params string[] scopes)
/// <param name="isCaeEnabled">Whether to enable Conditional Access Evaluation (CAE) for the token request.</param>
public AzureIdentityAccessTokenProvider(TokenCredential credential, string[]? allowedHosts = null, ObservabilityOptions? observabilityOptions = null, bool isCaeEnabled = true, params string[] scopes)
{
_credential = credential ?? throw new ArgumentNullException(nameof(credential));

Expand All @@ -45,6 +47,20 @@
_scopes = new(scopes, StringComparer.OrdinalIgnoreCase);

_activitySource = new((observabilityOptions ?? new()).TracerInstrumentationName);
_isCaeEnabled = isCaeEnabled;
}
/// <summary>
/// The <see cref="AzureIdentityAccessTokenProvider"/> constructor
/// </summary>
/// <param name="credential">The credential implementation to use to obtain the access token.</param>
/// <param name="allowedHosts">The list of allowed hosts for which to request access tokens.</param>
/// <param name="scopes">The scopes to request the access token for.</param>
/// <param name="observabilityOptions">The observability options to use for the authentication provider.</param>
[Obsolete("This constructor is obsolete and will be removed in a future version. Use the constructor that takes an isCaeEnabled parameter instead.")]

Check warning on line 59 in src/authentication/azure/AzureIdentityAccessTokenProvider.cs

View workflow job for this annotation

GitHub Actions / Build

Do not forget to remove this deprecated code someday. (https://rules.sonarsource.com/csharp/RSPEC-1133)

Check warning on line 59 in src/authentication/azure/AzureIdentityAccessTokenProvider.cs

View workflow job for this annotation

GitHub Actions / Build

Do not forget to remove this deprecated code someday. (https://rules.sonarsource.com/csharp/RSPEC-1133)

Check warning on line 59 in src/authentication/azure/AzureIdentityAccessTokenProvider.cs

View workflow job for this annotation

GitHub Actions / Build

Do not forget to remove this deprecated code someday. (https://rules.sonarsource.com/csharp/RSPEC-1133)
public AzureIdentityAccessTokenProvider(TokenCredential credential, string[]? allowedHosts, ObservabilityOptions? observabilityOptions, params string[] scopes) :
this(credential, allowedHosts, observabilityOptions, true, scopes)
{

}

private const string ClaimsKey = "claims";
Expand Down Expand Up @@ -96,7 +112,7 @@
scopes = [$"{uri.Scheme}://{uri.Host}/.default"];
span?.SetTag("com.microsoft.kiota.authentication.scopes", string.Join(",", scopes));

var result = await _credential.GetTokenAsync(new TokenRequestContext(scopes, claims: decodedClaim), cancellationToken).ConfigureAwait(false);
var result = await _credential.GetTokenAsync(new TokenRequestContext(scopes, claims: decodedClaim, isCaeEnabled: _isCaeEnabled), cancellationToken).ConfigureAwait(false);
return result.Token;
}

Expand Down
18 changes: 16 additions & 2 deletions src/authentication/azure/AzureIdentityAuthenticationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------

using System;
using Azure.Core;
using Microsoft.Kiota.Abstractions.Authentication;

Expand All @@ -17,9 +18,22 @@
/// <param name="credential">The credential implementation to use to obtain the access token.</param>
/// <param name="allowedHosts">The list of allowed hosts for which to request access tokens.</param>
/// <param name="scopes">The scopes to request the access token for.</param>
/// <param name="isCaeEnabled">Whether to enable Conditional Access Evaluation (CAE) for the token request.</param>
/// <param name="observabilityOptions">The observability options to use for the authentication provider.</param>
public AzureIdentityAuthenticationProvider(TokenCredential credential, string[]? allowedHosts = null, ObservabilityOptions? observabilityOptions = null, params string[] scopes)
: base(new AzureIdentityAccessTokenProvider(credential, allowedHosts, observabilityOptions, scopes))
public AzureIdentityAuthenticationProvider(TokenCredential credential, string[]? allowedHosts = null, ObservabilityOptions? observabilityOptions = null, bool isCaeEnabled = true, params string[] scopes)
: base(new AzureIdentityAccessTokenProvider(credential, allowedHosts, observabilityOptions, isCaeEnabled, scopes))
{
}
/// <summary>
/// The <see cref="AzureIdentityAuthenticationProvider"/> constructor
/// </summary>
/// <param name="credential">The credential implementation to use to obtain the access token.</param>
/// <param name="allowedHosts">The list of allowed hosts for which to request access tokens.</param>
/// <param name="scopes">The scopes to request the access token for.</param>
/// <param name="observabilityOptions">The observability options to use for the authentication provider.</param>
[Obsolete("This constructor is obsolete and will be removed in a future version. Use the constructor that takes an isCaeEnabled parameter instead.")]

Check warning on line 34 in src/authentication/azure/AzureIdentityAuthenticationProvider.cs

View workflow job for this annotation

GitHub Actions / Build

Do not forget to remove this deprecated code someday. (https://rules.sonarsource.com/csharp/RSPEC-1133)

Check warning on line 34 in src/authentication/azure/AzureIdentityAuthenticationProvider.cs

View workflow job for this annotation

GitHub Actions / Build

Do not forget to remove this deprecated code someday. (https://rules.sonarsource.com/csharp/RSPEC-1133)

Check warning on line 34 in src/authentication/azure/AzureIdentityAuthenticationProvider.cs

View workflow job for this annotation

GitHub Actions / Build

Do not forget to remove this deprecated code someday. (https://rules.sonarsource.com/csharp/RSPEC-1133)
public AzureIdentityAuthenticationProvider(TokenCredential credential, string[]? allowedHosts, ObservabilityOptions? observabilityOptions, params string[] scopes)
: this(credential, allowedHosts, observabilityOptions, true, scopes)
{
}
}
10 changes: 10 additions & 0 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
<PropertyGroup>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<IsTestProject>true</IsTestProject>
<Nullable>disable</Nullable>
<ImplicitUsings>true</ImplicitUsings>
<LangVersion>latest</LangVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsTestProject>true</IsTestProject>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<IsTestProject>true</IsTestProject>
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -26,7 +20,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\authentication\azure\Microsoft.Kiota.Authentication.Azure.csproj" />
<ProjectReference
Include="..\..\..\src\authentication\azure\Microsoft.Kiota.Authentication.Azure.csproj" />
</ItemGroup>

</Project>
</Project>
7 changes: 1 addition & 6 deletions tests/bundle/Microsoft.Kiota.Bundle.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsTestProject>true</IsTestProject>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -29,5 +24,5 @@
<ItemGroup>
<ProjectReference Include="..\..\src\bundle\Microsoft.Kiota.Bundle.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<IsTestProject>true</IsTestProject>
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -26,7 +20,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\http\httpClient\Microsoft.Kiota.Http.HttpClientLibrary.csproj" />
<ProjectReference
Include="..\..\..\src\http\httpClient\Microsoft.Kiota.Http.HttpClientLibrary.csproj" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<IsTestProject>true</IsTestProject>
<ImplicitUsings>true</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand All @@ -27,7 +23,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\serialization\form\Microsoft.Kiota.Serialization.Form.csproj" />
<ProjectReference
Include="..\..\..\src\serialization\form\Microsoft.Kiota.Serialization.Form.csproj" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<IsTestProject>true</IsTestProject>
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -26,7 +20,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\serialization\json\Microsoft.Kiota.Serialization.Json.csproj" />
<ProjectReference
Include="..\..\..\src\serialization\json\Microsoft.Kiota.Serialization.Json.csproj" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<IsTestProject>true</IsTestProject>
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -26,8 +20,10 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\serialization\json\Microsoft.Kiota.Serialization.Json.csproj" />
<ProjectReference Include="..\..\..\src\serialization\multipart\Microsoft.Kiota.Serialization.Multipart.csproj" />
<ProjectReference
Include="..\..\..\src\serialization\json\Microsoft.Kiota.Serialization.Json.csproj" />
<ProjectReference
Include="..\..\..\src\serialization\multipart\Microsoft.Kiota.Serialization.Multipart.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<IsTestProject>true</IsTestProject>
<Nullable>enable</Nullable> <!-- This test project supports NRT other projects need cleanup as outlined in https://github.com/microsoft/kiota-dotnet/issues/323 -->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -25,7 +24,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\serialization\text\Microsoft.Kiota.Serialization.Text.csproj" />
<ProjectReference
Include="..\..\..\src\serialization\text\Microsoft.Kiota.Serialization.Text.csproj" />
</ItemGroup>

</Project>
</Project>
Loading