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

Sync authentication with IDSDK login/logout events #14653

Merged
merged 26 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
56ba101
Fix PostDiff job
zeusongit Aug 11, 2023
dc250de
Merge branch 'master' of https://github.com/zeusongit/Dynamo
zeusongit Aug 11, 2023
1fecd29
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Aug 16, 2023
90a6c41
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Aug 28, 2023
64c202b
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Aug 29, 2023
d6ac751
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Sep 5, 2023
255feeb
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Sep 7, 2023
4e55f7f
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Sep 8, 2023
1886669
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Sep 8, 2023
8ac6b74
Merge branch 'master' of https://github.com/zeusongit/Dynamo
zeusongit Sep 12, 2023
41c461c
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Sep 12, 2023
f9cf237
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Sep 28, 2023
a0adaef
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Oct 13, 2023
2ab3d49
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Oct 17, 2023
558df01
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Oct 20, 2023
efdb82b
Merge branch 'master' of https://github.com/zeusongit/Dynamo
zeusongit Oct 20, 2023
9b712f2
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Oct 23, 2023
7c2dc1e
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Oct 25, 2023
83bcb52
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Nov 1, 2023
30b861d
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
zeusongit Nov 3, 2023
5e9bf4f
auth sync
zeusongit Nov 28, 2023
e936747
Merge branch 'master' of https://github.com/DynamoDS/Dynamo into auth-s
zeusongit Nov 29, 2023
3b6f454
comments
zeusongit Nov 29, 2023
c713c4b
Update SplashScreen.xaml.cs
zeusongit Nov 29, 2023
066e83c
comments
zeusongit Nov 29, 2023
8c5d317
jesus PR changes
zeusongit Nov 29, 2023
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
17 changes: 15 additions & 2 deletions src/DynamoCore/Core/IDSDKManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Dynamo.Core
/// <summary>
/// The class to provide auth APIs for IDSDK related methods.
/// </summary>
public class IDSDKManager : IOAuth2AuthProvider, IOAuth2AccessTokenProvider
public class IDSDKManager : IOAuth2AuthProvider, IOAuth2AccessTokenProvider, IDisposable
{
/// <summary>
/// Used by the auth provider to request authentication.
Expand Down Expand Up @@ -228,8 +228,10 @@ private bool Initialize()
}

bool ret = GetClientIDAndServer(out idsdk_server server, out string client_id);
if (ret)
if (ret)
{
Client.LogoutCompleteEvent += AuthCompleteEventHandler;
Client.LoginCompleteEvent += AuthCompleteEventHandler;
ret = SetProductConfigs("Dynamo", server, client_id);
Client.SetServer(server);
return ret;
Expand All @@ -253,6 +255,11 @@ private bool Deinitialize()
}
return false;
}
public void Dispose()
zeusongit marked this conversation as resolved.
Show resolved Hide resolved
{
Client.LoginCompleteEvent -= AuthCompleteEventHandler;
Client.LogoutCompleteEvent -= AuthCompleteEventHandler;
}
private bool GetClientIDAndServer(out idsdk_server server, out string client_id)
{
server = idsdk_server.IDSDK_PRODUCTION_SERVER;
Expand All @@ -273,6 +280,12 @@ private bool GetClientIDAndServer(out idsdk_server server, out string client_id)
}
return !string.IsNullOrEmpty(client_id);
}

// Event handler for LogoutCompleteEvent and LoginCompleteEvent that is thrown whenever the user's auth state changes.
private void AuthCompleteEventHandler(object sender, Client.TypedEventArgs e)
{
OnLoginStateChanged(LoginState);
}
#endregion
}
}
21 changes: 17 additions & 4 deletions src/DynamoCoreWpf/Controls/ShortcutToolbar.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Linq;
using System.Windows;
using System.Collections.Generic;
using System;

namespace Dynamo.UI.Controls
{
Expand Down Expand Up @@ -57,13 +58,14 @@ public ShortcutToolbar(DynamoViewModel dynamoViewModel)
authManager = dynamoViewModel.Model.AuthenticationManager;
if (authManager.IsLoggedInInitial())
{
authManager.LoginStateChanged += SignOutHandler;
authManager.LoginStateChanged += AuthChangeHandler;
}
else {
logoutOption.Visibility = Visibility.Collapsed;
}

this.Loaded += ShortcutToolbar_Loaded;
this.Unloaded += ShortcutToolbar_Unloaded;
}

private void ShortcutToolbar_Loaded(object sender, RoutedEventArgs e)
Expand All @@ -73,14 +75,26 @@ private void ShortcutToolbar_Loaded(object sender, RoutedEventArgs e)
DynamoViewModel.OnRequestShorcutToolbarLoaded(RightMenu.ActualWidth);
}

private void SignOutHandler(LoginState status)
private void ShortcutToolbar_Unloaded(object sender, RoutedEventArgs e)
zeusongit marked this conversation as resolved.
Show resolved Hide resolved
{
authManager.LoginStateChanged -= AuthChangeHandler;
this.Loaded -= ShortcutToolbar_Loaded;
this.Unloaded -= ShortcutToolbar_Unloaded;
}

private void AuthChangeHandler(LoginState status)
{
if (status == LoginState.LoggedOut)
{
LoginButton.ToolTip = Wpf.Properties.Resources.SignInButtonContentToolTip;
txtSignIn.Text = Wpf.Properties.Resources.SignInButtonText;
logoutOption.Visibility = Visibility.Collapsed;
authManager.LoginStateChanged -= SignOutHandler;
}
else if (status == LoginState.LoggedIn)
{
txtSignIn.Text = authManager.Username;
logoutOption.Visibility = Visibility.Visible;
LoginButton.ToolTip = null;
}
}

Expand Down Expand Up @@ -115,7 +129,6 @@ private void LoginButton_OnClick(object sender, RoutedEventArgs e)
tb.Text = authManager.Username;
logoutOption.Visibility = Visibility.Visible;
LoginButton.ToolTip = null;
authManager.LoginStateChanged += SignOutHandler;
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/DynamoCoreWpf/Views/SplashScreen/SplashScreen.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Dynamo.Utilities;
using Dynamo.ViewModels;
using DynamoUtilities;
using Greg.AuthProviders;
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.Wpf;

Expand Down Expand Up @@ -236,6 +237,11 @@ private void LaunchDynamo(bool isCheckboxChecked)
dynamoView?.Activate();
}

private void OnLoginStateChanged(LoginState state)
{
HandleSignInStatusChange(authManager.IsLoggedIn());
}

/// <summary>
/// Once main window is initialized, Dynamic Splash screen should finish loading
/// </summary>
Expand All @@ -250,6 +256,7 @@ private void OnStaticScreenReady()
// If user is launching Dynamo for the first time or chose to always show splash screen, display it. Otherwise, display Dynamo view directly.
if (viewModel.PreferenceSettings.IsFirstRun || viewModel.PreferenceSettings.EnableStaticSplashScreen)
{
authManager.LoginStateChanged += OnLoginStateChanged;
zeusongit marked this conversation as resolved.
Show resolved Hide resolved
SetSignInStatus(authManager.IsLoggedInInitial());
SetLoadingDone();
}
Expand Down Expand Up @@ -393,6 +400,18 @@ await webView.CoreWebView2.ExecuteScriptAsync("window.setSignInStatus({" +
}
}

/// <summary>
/// Handle the login status changes on splash screen.
/// </summary>
internal async void HandleSignInStatusChange(bool status)
{
if (webView?.CoreWebView2 != null)
{
await webView.CoreWebView2.ExecuteScriptAsync("window.handleSignInStateChange({" +
zeusongit marked this conversation as resolved.
Show resolved Hide resolved
$"status: \"" + status + "\"})");
}
}

/// <summary>
/// Setup the values for all labels on splash screen using resources
/// </summary>
Expand Down
Loading