Add a workaround for ios/maccatalyst BlazorWebView
This commit is contained in:
Родитель
8ffe632cbe
Коммит
d8935309c5
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0-android</TargetFrameworks>
|
||||
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
|
||||
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows')) and '$(MSBuildRuntimeType)' == 'Full'">$(TargetFrameworks);net6.0-windows10.0.19041</TargetFrameworks>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>HybridApp</RootNamespace>
|
||||
|
|
|
@ -2,20 +2,22 @@
|
|||
@implements IDisposable
|
||||
|
||||
<ContentPage>
|
||||
<StackLayout>
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<GridCell Row="0">
|
||||
<StackLayout Margin="new Thickness(20)" Orientation="StackOrientation.Horizontal">
|
||||
<Label Text="@($"Hello, World! {CounterState.CurrentCount}")" FontSize="40" HorizontalOptions="LayoutOptions.StartAndExpand" />
|
||||
<Button Text="Increment" OnClick="@CounterState.IncrementCount" VerticalOptions="LayoutOptions.Center" Padding="10" />
|
||||
</StackLayout>
|
||||
</GridCell>
|
||||
|
||||
<StackLayout Margin="new Thickness(20)" Orientation="StackOrientation.Horizontal">
|
||||
<Label Text="@($"Hello, World! {CounterState.CurrentCount}")" FontSize="40" HorizontalOptions="LayoutOptions.StartAndExpand" />
|
||||
<Button Text="Increment" OnClick="@CounterState.IncrementCount" VerticalOptions="LayoutOptions.Center" Padding="10" />
|
||||
</StackLayout>
|
||||
|
||||
<BlazorWebView HostPage="wwwroot/index.html">
|
||||
<RootComponents>
|
||||
<RootComponent Selector="#app" ComponentType="typeof(HybridApp.WebUI.App) "/>
|
||||
</RootComponents>
|
||||
</BlazorWebView>
|
||||
|
||||
</StackLayout>
|
||||
<GridCell Row="1">
|
||||
<BlazorWebView HostPage="wwwroot/index.html" VerticalOptions="LayoutOptions.Fill">
|
||||
<RootComponents>
|
||||
<RootComponent Selector="#app" ComponentType="typeof(HybridApp.WebUI.App) " />
|
||||
</RootComponents>
|
||||
</BlazorWebView>
|
||||
</GridCell>
|
||||
</Grid>
|
||||
</ContentPage>
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0-android;net6.0-windows10.0.19041</TargetFrameworks>
|
||||
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst;net6.0-windows10.0.19041</TargetFrameworks>
|
||||
<Title>Authentication support for Mobile Blazor Bindings applications using MSAL with Azure Active Directory and Azure Active Directory B2Cs</Title>
|
||||
<Description>Add support for authentication in your Mobile Blazor Bindings application using MSAL with Azure Active Directory and Azure Active Directory B2C.</Description>
|
||||
<PackageTags>blazor;mobileblazorbindings;authentication;msal</PackageTags>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0-android;net6.0-windows10.0.19041</TargetFrameworks>
|
||||
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst;net6.0-windows10.0.19041</TargetFrameworks>
|
||||
<NoWarn>CS1591;CA1054;CA1303;CA1056;CA2007;CA2237;CA1835</NoWarn>
|
||||
<Title>Authentication support for Mobile Blazor Bindings applications using OpenID Connect</Title>
|
||||
<Description>Add support for authentication in your Mobile Blazor Bindings application with OpenID Connect.</Description>
|
||||
|
@ -13,7 +13,6 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="IdentityModel.OidcClient" Version="3.1.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.VisualStudioEng.MicroBuild.Core" Version="0.4.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Maui.Authentication;
|
||||
using Microsoft.MobileBlazorBindings.ProtectedStorage;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.MobileBlazorBindings.Authentication
|
||||
{
|
||||
/// <summary>
|
||||
/// An implementation for <see cref="IAuthenticationService"/> that uses Xamarin.Essentials WebAuthenticator to authenticate the user.
|
||||
/// </summary>
|
||||
/// <typeparam name="TRemoteAuthenticationState">The state to preserve across authentication operations.</typeparam>
|
||||
/// <typeparam name="TAccount">The type of the <see cref="RemoteUserAccount" />.</typeparam>
|
||||
/// <typeparam name="TProviderOptions">The options to be passed down to the underlying Authentication library handling the authentication operations.</typeparam>
|
||||
public class AuthenticationService<TRemoteAuthenticationState, TAccount, TProviderOptions> :
|
||||
OidcAuthenticationService<TRemoteAuthenticationState, TAccount, TProviderOptions>
|
||||
where TRemoteAuthenticationState : OidcAuthenticationState, new()
|
||||
where TProviderOptions : new()
|
||||
where TAccount : RemoteUserAccount
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance.
|
||||
/// </summary>
|
||||
/// <param name="options">The options to be passed down to the underlying Authentication library handling the authentication operations.</param>
|
||||
/// <param name="tokenCache">The token cache to use to store tokens.</param>
|
||||
/// <param name="protectedStorage">The protect storage where refresh tokens will be stored.</param>
|
||||
/// <param name="accountClaimsPrincipalFactory">The <see cref="AccountClaimsPrincipalFactory{TAccount}"/> used to generate the <see cref="ClaimsPrincipal"/> for the user.</param>
|
||||
public AuthenticationService(
|
||||
IOptionsSnapshot<RemoteAuthenticationOptions<TProviderOptions>> options,
|
||||
ITokenCache tokenCache,
|
||||
IProtectedStorage protectedStorage,
|
||||
AccountClaimsPrincipalFactory<TAccount> accountClaimsPrincipalFactory) : base(options, tokenCache, protectedStorage, accountClaimsPrincipalFactory)
|
||||
{
|
||||
}
|
||||
|
||||
protected override async Task<string> StartSecureNavigation(Uri startUrl, Uri redirectUrl)
|
||||
{
|
||||
var authenticationResult = await WebAuthenticator.AuthenticateAsync(startUrl, redirectUrl);
|
||||
|
||||
if (!authenticationResult.Properties.Any())
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return $"?{string.Join("&", authenticationResult.Properties.Select(x => $"{x.Key}={x.Value}"))}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Maui.Authentication;
|
||||
using Microsoft.MobileBlazorBindings.ProtectedStorage;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#if !IOS && !MACCATALYST
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
@ -33,6 +31,4 @@ namespace Microsoft.MobileBlazorBindings.Elements
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
#if !IOS && !MACCATALYST
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.MobileBlazorBindings.Core;
|
||||
|
@ -31,6 +29,4 @@ namespace Microsoft.MobileBlazorBindings.Elements.Handlers
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
|
@ -1,8 +1,6 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
#if !IOS && !MACCATALYST
|
||||
|
||||
using Microsoft.MobileBlazorBindings.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -63,6 +61,4 @@ namespace Microsoft.MobileBlazorBindings.Elements.Handlers
|
|||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
|
@ -1,8 +1,6 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
#if !IOS && !MACCATALYST
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.MobileBlazorBindings.Core;
|
||||
using Microsoft.MobileBlazorBindings.Elements.Handlers;
|
||||
|
@ -44,6 +42,4 @@ namespace Microsoft.MobileBlazorBindings.Elements
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
|
@ -21,12 +21,6 @@ namespace Microsoft.MobileBlazorBindings.Elements
|
|||
[Parameter] public MC.WebViewSource Source { get; set; }
|
||||
[Parameter] public EventCallback<string> OnWebMessageReceived { get; set; }
|
||||
|
||||
// Is that still needed?
|
||||
//public void SendMessage(string message)
|
||||
//{
|
||||
// ((WebViewHandler)ElementHandler).Control.SendMessage(message);
|
||||
//}
|
||||
|
||||
protected override void RenderAttributes(AttributesBuilder builder)
|
||||
{
|
||||
base.RenderAttributes(builder);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;net6.0-android;net6.0-ios;net6.0-maccatalyst;net6.0-windows10.0.19041</TargetFrameworks>
|
||||
|
@ -7,12 +7,6 @@
|
|||
<Description>Experimental Mobile Blazor Bindings enables using Blazor syntax in .razor files to build native apps for iOS and Android.</Description>
|
||||
<PackageTags>blazor;mobileblazorbindings</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) or $(TargetFramework.Contains('-maccatalyst'))">
|
||||
<!--This workaround disables BlazorWebView support for iOS, but at least allows to use native controls only.
|
||||
See https://github.com/dotnet/maui/issues/3536-->
|
||||
<UsingMicrosoftNETSdkRazor>false</UsingMicrosoftNETSdkRazor>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.VisualStudioEng.MicroBuild.Core" Version="0.4.1">
|
||||
|
@ -20,6 +14,12 @@
|
|||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!--We cannot use Microsoft.NET.Sdk.Razor because of this bug https://github.com/dotnet/maui/issues/3536.
|
||||
Therefore we reference WebView.Maui package directly, but excluding .targets files.-->
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="6.0.300-rc.2.5513" IncludeAssets="compile;runtime" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.MobileBlazorBindings.Core\Microsoft.MobileBlazorBindings.Core.csproj" />
|
||||
|
|
Загрузка…
Ссылка в новой задаче