Browse Source

Update the MAUI sample to use a label instead of a modal alert

pull/2115/head
Kévin Chalet 2 years ago
parent
commit
4f58cd615b
  1. 23
      Directory.Build.targets
  2. 9
      sandbox/OpenIddict.Sandbox.Maui.Client/MainPage.xaml
  3. 15
      sandbox/OpenIddict.Sandbox.Maui.Client/MainPage.xaml.cs

23
Directory.Build.targets

@ -15,10 +15,25 @@
<PublicSign>false</PublicSign>
</PropertyGroup>
<PropertyGroup>
<SupportedOSPlatformVersion Condition=" '$(TargetPlatformIdentifier)' == 'iOS' ">12.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition=" '$(TargetPlatformIdentifier)' == 'Windows' ">7.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition=" '$(TargetPlatformIdentifier)' == 'Windows' ">7.0</TargetPlatformMinVersion>
<PropertyGroup
Condition=" ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
'$(TargetPlatformIdentifier)' == 'iOS' And '$(TargetPlatformVersion)' != '' And
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '12.0'))) ">
<SupportedOSPlatformVersion>12.0</SupportedOSPlatformVersion>
</PropertyGroup>
<PropertyGroup
Condition=" ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
'$(TargetPlatformIdentifier)' == 'Windows' And '$(TargetPlatformVersion)' != '' And
$([MSBuild]::VersionEquals($(TargetPlatformVersion), '7.0'))) ">
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
</PropertyGroup>
<PropertyGroup
Condition=" ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
'$(TargetPlatformIdentifier)' == 'Windows' And '$(TargetPlatformVersion)' != '' And
$([MSBuild]::VersionGreaterThanOrEquals($(TargetPlatformVersion), '10.0.17763'))) ">
<SupportedOSPlatformVersion>10.0.17763</SupportedOSPlatformVersion>
</PropertyGroup>
<!--

9
sandbox/OpenIddict.Sandbox.Maui.Client/MainPage.xaml

@ -2,7 +2,7 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="OpenIddict.Sandbox.Maui.Client.MainPage">
<ScrollView>
<VerticalStackLayout
Spacing="25"
@ -14,14 +14,15 @@
SemanticProperties.Description="Cute dot net bot waving hi to you!"
HeightRequest="200"
HorizontalOptions="Center" />
<Label
Text="Hello, World!"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
HorizontalOptions="Center" />
<Label
x:Name="Message"
Text="Welcome to .NET Multi-platform App UI"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to dot net Multi platform App U I"
@ -58,5 +59,5 @@
</VerticalStackLayout>
</ScrollView>
</ContentPage>

15
sandbox/OpenIddict.Sandbox.Maui.Client/MainPage.xaml.cs

@ -58,25 +58,26 @@ public partial class MainPage : ContentPage
// Wait for the user to complete the authorization process.
var principal = (await _service.AuthenticateInteractivelyAsync(new()
{
CancellationToken = source.Token,
Nonce = result.Nonce
})).Principal;
await DisplayAlert("Authentication successful", $"Welcome, {principal.FindFirst(Claims.Name)!.Value}.", "OK");
Message.Text = $"Welcome, {principal.FindFirst(Claims.Name)!.Value}.";
}
catch (OperationCanceledException)
{
await DisplayAlert("Authentication timed out", "The authentication process was aborted.", "OK");
Message.Text = "The authentication process was aborted.";
}
catch (ProtocolException exception) when (exception.Error is Errors.AccessDenied)
{
await DisplayAlert("Authorization denied", "The authorization was denied by the end user.", "OK");
Message.Text = "The authorization was denied by the end user.";
}
catch
{
await DisplayAlert("Authentication failed", "An error occurred while trying to authenticate the user.", "OK");
Message.Text = "An error occurred while trying to authenticate the user.";
}
}
@ -122,17 +123,17 @@ public partial class MainPage : ContentPage
Nonce = result.Nonce
});
await DisplayAlert("Logout demand successful", "The user was successfully logged out from the local server.", "OK");
Message.Text = "The user was successfully logged out from the local server.";
}
catch (OperationCanceledException)
{
await DisplayAlert("Logout timed out", "The logout process was aborted.", "OK");
Message.Text = "The logout process was aborted.";
}
catch
{
await DisplayAlert("Logout failed", "An error occurred while trying to log the user out.", "OK");
Message.Text = "An error occurred while trying to log the user out.";
}
}

Loading…
Cancel
Save