Skip to content

Changes to use the library in .Net 7 winforms app #197

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions src/Auth.UI.WPF/Auth.UI.WPF.csproj
Original file line number Diff line number Diff line change
@@ -26,18 +26,19 @@ The library provides a drop-in auth solution that handles the flows for signing
<AssemblyName>Firebase.Auth.UI.WPF</AssemblyName>
<RootNamespace>Firebase.Auth.UI</RootNamespace>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>

<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="BuildOnlySettings;ResolveReferences">
<ItemGroup>
<!-- Filter out unnecessary files -->
<_ReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->WithMetadataValue('PrivateAssets', 'All'))"/>
<_ReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths-&gt;WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')-&gt;WithMetadataValue('PrivateAssets', 'All'))" />
</ItemGroup>

<ItemGroup>
<!-- Add file to package with consideration of sub folder. If empty, the root folder is chosen. -->
<BuildOutputInPackage Include="@(_ReferenceCopyLocalPaths)" TargetPath="%(_ReferenceCopyLocalPaths.DestinationSubDirectory)"/>
<BuildOutputInPackage Include="@(_ReferenceCopyLocalPaths)" TargetPath="%(_ReferenceCopyLocalPaths.DestinationSubDirectory)" />
</ItemGroup>
</Target>

@@ -50,9 +51,9 @@ The library provides a drop-in auth solution that handles the flows for signing
<Resource Include="..\Auth.UI\Assets\mail.png" Link="Assets\mail.png" />
<Resource Include="..\Auth.UI\Assets\microsoft.png" Link="Assets\microsoft.png" />
<Resource Include="..\Auth.UI\Assets\twitter.png" Link="Assets\twitter.png" />
<None Include="..\Auth.UI\Assets\firebase.png" Link="Assets\firebase.png" Pack="true" PackagePath=""/>
<None Include="..\..\LICENSE.txt" Link="Assets\LICENSE.txt" Pack="true" PackagePath=""/>
<None Include="..\..\README.md" Link="Assets\README.md" Pack="true" PackagePath=""/>
<None Include="..\Auth.UI\Assets\firebase.png" Link="Assets\firebase.png" Pack="true" PackagePath="" />
<None Include="..\..\LICENSE.txt" Link="Assets\LICENSE.txt" Pack="true" PackagePath="" />
<None Include="..\..\README.md" Link="Assets\README.md" Pack="true" PackagePath="" />
<None Include="tools\VisualStudioToolsManifest.xml" Pack="true" PackagePath="tools" />
</ItemGroup>

@@ -62,7 +63,7 @@ The library provides a drop-in auth solution that handles the flows for signing
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1462.37" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1661.34" />
</ItemGroup>

<ItemGroup>
15 changes: 11 additions & 4 deletions src/Auth.UI.WPF/WebAuthenticationBroker.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
using Firebase.Auth.UI.Converters;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Forms;

namespace Firebase.Auth.UI
{
internal static class WebAuthenticationBroker
public static class WebAuthenticationBroker
{
public static Task<string> AuthenticateAsync(Window owner, FirebaseProviderType provider, string uri, string redirectUri)
public static Task<string> AuthenticateAsync(object owner, FirebaseProviderType provider, string uri, string redirectUri)
{
var tcs = new TaskCompletionSource<string>();

Application.Current.Dispatcher.Invoke(() =>
System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
var window = new WebAuthenticationBrokerWindow();
window.WebView.NavigationCompleted += (s, e) =>
@@ -25,7 +27,12 @@ public static Task<string> AuthenticateAsync(Window owner, FirebaseProviderType
};
window.Title = ProviderToTitleConverter.Convert(provider);
window.WebView.Loaded += (s, e) => window.WebView.Source = new System.Uri(uri);
window.Owner = owner;
if (owner is Window owner_window) window.Owner = owner_window;
else if (owner is Form owner_form)
{
WindowInteropHelper helper = new WindowInteropHelper(window);
helper.Owner = owner_form.Handle;
}
if (!(window.ShowDialog() ?? false))
{
tcs.SetResult(null);
2 changes: 1 addition & 1 deletion src/Auth/Auth.csproj
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ FirebaseUI is supported by platform-specific libraries:
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/Auth/FirebaseAuthClient.cs
Original file line number Diff line number Diff line change
@@ -204,12 +204,12 @@ private void TriggerAuthStateChanged(EventHandler<UserEventArgs> value, User use
value?.Invoke(this, new UserEventArgs(user));
}

private void SaveToken(User user)
public void SaveToken(User user)
{
this.config.UserManager.SaveNewUser(user);
}

private async Task CheckAuthDomain()
public async Task CheckAuthDomain()
{
if (this.domainChecked)
{
2 changes: 1 addition & 1 deletion src/Auth/Providers/OAuthProvider.cs
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ internal virtual AuthCredential GetCredential(VerifyAssertionResponse response)
response.PendingToken == null ? OAuthCredentialTokenType.AccessToken : OAuthCredentialTokenType.PendingToken);
}

internal virtual async Task<OAuthContinuation> SignInAsync()
public virtual async Task<OAuthContinuation> SignInAsync()
{
if (this.LocaleParameterName != null && !this.parameters.ContainsKey(this.LocaleParameterName))
{