-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f2a604
commit b48f888
Showing
6 changed files
with
115 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...ng/TestHarness/TestHarness/Ext/Authentication/Custom/CustomAuthenticationMainPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...ing/TestHarness/TestHarness/Ext/Authentication/Custom/CustomAuthenticationMockHostInit.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
namespace TestHarness.Ext.Authentication.Custom; | ||
|
||
public class CustomAuthenticationMockHostInit : BaseHostInitialization | ||
{ | ||
protected override IHostBuilder Custom(IHostBuilder builder) | ||
{ | ||
return builder.UseAuthentication(auth => | ||
auth.AddCustom(custom => | ||
custom | ||
.Login(async (sp, dispatcher, credentials, cancellationToken) => | ||
{ | ||
if (credentials?.TryGetValue(nameof(CustomAuthenticationCredentials.Username), out var username) ?? false && | ||
!username.IsNullOrEmpty()) | ||
{ | ||
credentials ??= new Dictionary<string, string>(); | ||
credentials[TokenCacheExtensions.AccessTokenKey] = "SampleToken"; | ||
credentials[TokenCacheExtensions.RefreshTokenKey] = "RefreshToken"; | ||
credentials["Expiry"] = DateTime.Now.AddMinutes(5).ToString("g"); | ||
return credentials; | ||
} | ||
|
||
return default; | ||
}) | ||
.Refresh(async (sp, tokenDictionary, cancellationToken) => | ||
{ | ||
if ((tokenDictionary?.TryGetValue(TokenCacheExtensions.RefreshTokenKey, out var refreshToken) ?? false) && | ||
!refreshToken.IsNullOrEmpty() && | ||
(tokenDictionary?.TryGetValue("Expiry", out var expiry) ?? false) && | ||
DateTime.TryParse(expiry, out var tokenExpiry) && | ||
tokenExpiry > DateTime.Now) | ||
{ | ||
tokenDictionary ??= new Dictionary<string, string>(); | ||
tokenDictionary[TokenCacheExtensions.AccessTokenKey] = "NewSampleToken"; | ||
tokenDictionary["Expiry"] = DateTime.Now.AddMinutes(5).ToString("g"); | ||
return tokenDictionary; | ||
} | ||
|
||
return default; | ||
}) | ||
, name: "CustomAuth") | ||
) | ||
.ConfigureServices(services => | ||
services | ||
.AddSingleton<IAuthenticationRouteInfo>( | ||
_ => new AuthenticationRouteInfo< | ||
CustomAuthenticationLoginViewModel, | ||
CustomAuthenticationHomeViewModel>()) | ||
); | ||
} | ||
|
||
|
||
protected override void RegisterRoutes(IViewRegistry views, IRouteRegistry routes) | ||
{ | ||
|
||
views.Register( | ||
new ViewMap(ViewModel: typeof(AuthenticationShellViewModel)), | ||
new ViewMap<CustomAuthenticationLoginPage, CustomAuthenticationLoginViewModel>(), | ||
new ViewMap<CustomAuthenticationHomeTestBackendPage, CustomAuthenticationHomeTestBackendViewModel>() | ||
); | ||
|
||
|
||
routes | ||
.Register( | ||
new RouteMap("", View: views.FindByViewModel<AuthenticationShellViewModel>(), | ||
Nested: new RouteMap[] | ||
{ | ||
new RouteMap("Login", View: views.FindByViewModel<CustomAuthenticationLoginViewModel>()), | ||
new RouteMap("Home", View: views.FindByViewModel<CustomAuthenticationHomeTestBackendViewModel>()) | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
<UserControl | ||
x:Class="TestHarness.TestFrameHost" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:TestHarness" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
d:DesignHeight="300" | ||
d:DesignWidth="400" | ||
> | ||
<UserControl x:Class="TestHarness.TestFrameHost" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:TestHarness" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
d:DesignHeight="300" | ||
d:DesignWidth="400"> | ||
|
||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
<Frame x:Name="TestFrame" SourcePageType="local:MainPage"/> | ||
<Button Grid.Row="1" HorizontalAlignment="Center" Content="Exit Test" IsEnabled="{Binding ElementName=TestFrame, Path=CanGoBack}" Click="ExitTestClick" /> | ||
<Frame x:Name="TestFrame" SourcePageType="local:MainPage" /> | ||
<Button Grid.Row="1" | ||
HorizontalAlignment="Center" | ||
Content="Exit Test" | ||
AutomationProperties.AutomationId="ExitTestButton" | ||
IsEnabled="{Binding ElementName=TestFrame, Path=CanGoBack}" | ||
Click="ExitTestClick" /> | ||
</Grid> | ||
</UserControl> |