Skip to content

Commit

Permalink
Merge pull request #2489 from unoplatform/dev/sb/msal-api
Browse files Browse the repository at this point in the history
  • Loading branch information
kazo0 authored Aug 5, 2024
2 parents b16b3d1 + 8b1cd84 commit 1d33cba
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
2 changes: 0 additions & 2 deletions src/Uno.Extensions.Authentication.MSAL/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
global using System.Threading.Tasks;
global using Microsoft.Extensions.Logging;
global using Microsoft.Extensions.Options;
#if UNO_EXT_MSAL
global using Microsoft.Identity.Client;
global using Microsoft.Identity.Client.Extensions.Msal;
#endif
global using Uno.Extensions.Authentication;
global using Uno.Extensions.Authentication.MSAL;
global using Uno.Extensions.Configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
/// </summary>
public static class MsalAuthenticationBuilderExtensions
{
#if UNO_EXT_MSAL

/// <summary>
/// Configures the MSAL authentication feature to use a public client application builder.
/// </summary>
Expand All @@ -24,6 +22,9 @@ public static IMsalAuthenticationBuilder Builder(
Action<PublicClientApplicationBuilder> build
)
{
#if !UNO_EXT_MSAL
return builder;
#else
if (builder is IBuilder<MsalAuthenticationSettings> authBuilder)
{
authBuilder.Settings = authBuilder.Settings with
Expand All @@ -33,6 +34,7 @@ Action<PublicClientApplicationBuilder> build
}

return builder;
#endif
}

/// <summary>
Expand All @@ -52,6 +54,9 @@ public static IMsalAuthenticationBuilder Storage(
Action<StorageCreationPropertiesBuilder> store
)
{
#if !UNO_EXT_MSAL
return builder;
#else
if (builder is IBuilder<MsalAuthenticationSettings> authBuilder)
{
authBuilder.Settings = authBuilder.Settings with
Expand All @@ -61,8 +66,8 @@ Action<StorageCreationPropertiesBuilder> store
}

return builder;
}
#endif
}

/// <summary>
/// Configures the MSAL authentication feature to be built with the specified scopes for authentication.
Expand All @@ -81,6 +86,9 @@ public static IMsalAuthenticationBuilder Scopes(
string[] scopes
)
{
#if !UNO_EXT_MSAL
return builder;
#else
if (builder is IBuilder<MsalAuthenticationSettings> authBuilder)
{
authBuilder.Settings = authBuilder.Settings with
Expand All @@ -90,9 +98,9 @@ string[] scopes
}

return builder;
#endif
}

#if UNO_EXT_MSAL
/// <summary>
/// Configures a public client application builder to create the MSAL authentication
/// feature to use the redirect Uri provided by WebAuthenticationBroker.
Expand All @@ -106,7 +114,10 @@ string[] scopes
[MethodImpl(MethodImplOptions.NoInlining)]
public static PublicClientApplicationBuilder WithWebRedirectUri(this PublicClientApplicationBuilder builder)
{
#if !UNO_EXT_MSAL
return builder;
#else
return builder.WithRedirectUri(WebAuthenticationBroker.GetCurrentApplicationCallbackUri().OriginalString);
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ namespace Uno.Extensions.Authentication.MSAL;

internal record MsalAuthenticationSettings
{
#if UNO_EXT_MSAL
public Action<PublicClientApplicationBuilder>? Build { get; init; }

public Action<StorageCreationPropertiesBuilder>? Store { get; init; }
#endif

public string[]? Scopes { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ItemGroup >
<!-- MSAL isn't supported on skia targets, macos or maccatalyst -->
<PackageReference Include="Uno.WinUI" />
<PackageReference Include="Uno.WinUI.MSAL" Condition="'$(IsMSALSupported)'=='true'" />
<PackageReference Include="Uno.WinUI.MSAL" />
</ItemGroup>

<PropertyGroup Condition="$(TargetFramework.ToLower().StartsWith('net6')) and $(_IsAndroid)">
Expand Down Expand Up @@ -46,11 +46,9 @@
<PropertyGroup>
<!--Temporary disable missing XML doc until fixed in the whole package-->
<WarningsNotAsErrors>$(WarningsNotAsErrors);CS1591</WarningsNotAsErrors>
<IsMSALSupported>false</IsMSALSupported>
</PropertyGroup>

<PropertyGroup Condition="'$(_IsNetStd)'!='true' and '$(_IsMacOS)'!='true' and '$(_IsCatalyst)'!='true'" >
<IsMSALSupported>true</IsMSALSupported>
<DefineConstants>$(DefineConstants);UNO_EXT_MSAL</DefineConstants>
</PropertyGroup>

Expand All @@ -63,8 +61,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" />
<PackageReference Include="Microsoft.Identity.Client" Condition="'$(IsMSALSupported)'=='true'" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Condition="'$(IsMSALSupported)'=='true'" />
<PackageReference Include="Microsoft.Identity.Client" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" />
</ItemGroup>

<ItemGroup Condition="'$(IsBrowserWasm)'!='true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
</ItemGroup>

<PropertyGroup Condition="'$(_IsNetStd)'!='true' and '$(_IsMacOS)'!='true' and '$(_IsCatalyst)'!='true'" >
<IsMSALSupported>true</IsMSALSupported>
<DefineConstants>$(DefineConstants);UNO_EXT_MSAL</DefineConstants>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ protected override IHostBuilder Custom(IHostBuilder builder)
auth.AddMsal(msal =>
msal
.Scopes(new[] { "Tasks.Read", "User.Read", "Tasks.ReadWrite" })
#if UNO_EXT_MSAL
.Builder(msalBuilder =>
msalBuilder
.WithClientId("161a9fb5-3b16-487a-81a2-ac45dcc0ad3b")
Expand All @@ -25,7 +24,6 @@ protected override IHostBuilder Custom(IHostBuilder builder)
//{
// msalBuilder = msalBuilder.WithIosKeychainSecurityGroup(settings.KeychainSecurityGroup);
//}
#endif
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ protected override IHostBuilder Custom(IHostBuilder builder)
}
return default;
}), name: "CustomService")
#if UNO_EXT_MSAL
.AddMsal(msal =>
msal
.Scopes(new[] { "Tasks.Read", "User.Read", "Tasks.ReadWrite" })
Expand All @@ -118,7 +117,6 @@ protected override IHostBuilder Custom(IHostBuilder builder)
//}
, name: "MsalCode")
.AddMsal(name: "MsalConfig")
#endif
);
}

Expand Down

0 comments on commit 1d33cba

Please sign in to comment.