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

fix: Test case for msal wasn't loading #722

Merged
merged 1 commit into from
Sep 13, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
[ReactiveBindable(false)]
public partial class MsalAuthenticationHomeViewModel : ObservableObject
{
public INavigator Navigator { get; init; }
public IAuthenticationService Authentication { get; init; }
private readonly IDispatcher _dispatcher;
private readonly INavigator _navigator;
private readonly IAuthenticationService _authentication;

public IMsalAuthenticationTaskListEndpoint TaskEndpoint { get; init; }
public ICustomAuthenticationDummyJsonEndpoint? Endpoint { get; init; }
private readonly IMsalAuthenticationTaskListEndpoint _taskEndpoint;
private readonly ICustomAuthenticationDummyJsonEndpoint? _endpoint;

public ITokenCache Tokens { get; }
private readonly ITokenCache _tokens;

[ObservableProperty]
private MsalAuthenticationToDoTaskListData[]? tasks;
Expand All @@ -19,43 +20,45 @@ public partial class MsalAuthenticationHomeViewModel : ObservableObject
private CustomAuthenticationProduct[]? products;

public MsalAuthenticationHomeViewModel(
IDispatcher dispatcher,
INavigator navigator,
IAuthenticationService auth,
ITokenCache tokens,
IMsalAuthenticationTaskListEndpoint taskEndpoint,
ICustomAuthenticationDummyJsonEndpoint? endpoint=null)
{
Navigator = navigator;
Authentication = auth;
TaskEndpoint = taskEndpoint;
Tokens = tokens;
Endpoint = endpoint;
_dispatcher = dispatcher;
_navigator = navigator;
_authentication = auth;
_taskEndpoint = taskEndpoint;
_tokens = tokens;
_endpoint = endpoint;
}

public async void Logout()
{
await Authentication.LogoutAsync(CancellationToken.None);
await Navigator.NavigateViewModelAsync<MsalAuthenticationWelcomeViewModel>(this, qualifier: Qualifiers.ClearBackStack);
await _authentication.LogoutAsync(_dispatcher, CancellationToken.None);
await _navigator.NavigateViewModelAsync<MsalAuthenticationWelcomeViewModel>(this, qualifier: Qualifiers.ClearBackStack);
}

public async void ClearAccessToken()
{
var creds = await Tokens.GetAsync(CancellationToken.None);
var creds = await _tokens.GetAsync(CancellationToken.None);
creds.Remove(TokenCacheExtensions.AccessTokenKey);
await Tokens.SaveAsync(await Tokens.GetCurrentProviderAsync(CancellationToken.None) ?? string.Empty, creds, CancellationToken.None);
await _tokens.SaveAsync(await _tokens.GetCurrentProviderAsync(CancellationToken.None) ?? string.Empty, creds, CancellationToken.None);
}

public async void Retrieve()
{
var current = await Tokens.GetCurrentProviderAsync(CancellationToken.None);
var current = await _tokens.GetCurrentProviderAsync(CancellationToken.None);
if (current?.StartsWith("Custom") ?? false)
{
var response = await Endpoint!.Products(CancellationToken.None);
var response = await _endpoint!.Products(CancellationToken.None);
Products = response?.Products?.ToArray();
}
else
{
var tasksResponse = await TaskEndpoint.GetAllAsync(CancellationToken.None);
var tasksResponse = await _taskEndpoint.GetAllAsync(CancellationToken.None);
Tasks = tasksResponse?.Value?.ToArray();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using TestHarness.Ext.Authentication.Custom;

namespace TestHarness.Ext.Authentication.MSAL;
namespace TestHarness.Ext.Authentication.MSAL;

public class MsalAuthenticationMultiHostInit : BaseMsalHostInitialization
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TestHarness.Ext.Authentication.MSAL;

public class MsalAuthenticationSettingsHostInit : BaseHostInitialization
public class MsalAuthenticationSettingsHostInit : BaseMsalHostInitialization
{
protected override string[] ConfigurationFiles => new string[] { "TestHarness.Ext.Authentication.Msal.appsettings.msalauthentication.json",
"TestHarness.Ext.Authentication.Msal.appsettings.msal.json"};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TestHarness.Ext.Authentication.MSAL;

internal record MsalAuthenticationWelcomeViewModel(INavigator Navigator, IAuthenticationService auth, IAuthenticationService Authentication, IAuthenticationRouteInfo RouteInfo)
internal record MsalAuthenticationWelcomeViewModel(IDispatcher Dispatcher, INavigator Navigator, IAuthenticationService auth, IAuthenticationService Authentication, IAuthenticationRouteInfo RouteInfo)
{
public string[] Providers => Authentication.Providers;

Expand All @@ -19,7 +19,7 @@ public async void Login()
{nameof(CustomAuthenticationCredentials.Password),DummyJsonEndpointConstants.ValidPassword }
} :
default;
var authenticated =await Authentication.LoginAsync(credentials: creds, provider: SelectedProvider);
var authenticated =await Authentication.LoginAsync(Dispatcher, credentials: creds, provider: SelectedProvider);
if (authenticated)
{
await Navigator.NavigateViewModelAsync(this, RouteInfo.HomeViewModel, qualifier: Qualifiers.ClearBackStack);
Expand Down