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> <PublicSign>false</PublicSign>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup
<SupportedOSPlatformVersion Condition=" '$(TargetPlatformIdentifier)' == 'iOS' ">12.0</SupportedOSPlatformVersion> Condition=" ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '5.0')) And
<SupportedOSPlatformVersion Condition=" '$(TargetPlatformIdentifier)' == 'Windows' ">7.0</SupportedOSPlatformVersion> '$(TargetPlatformIdentifier)' == 'iOS' And '$(TargetPlatformVersion)' != '' And
<TargetPlatformMinVersion Condition=" '$(TargetPlatformIdentifier)' == 'Windows' ">7.0</TargetPlatformMinVersion> $([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> </PropertyGroup>
<!-- <!--

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

@ -2,7 +2,7 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="OpenIddict.Sandbox.Maui.Client.MainPage"> x:Class="OpenIddict.Sandbox.Maui.Client.MainPage">
<ScrollView> <ScrollView>
<VerticalStackLayout <VerticalStackLayout
Spacing="25" Spacing="25"
@ -14,14 +14,15 @@
SemanticProperties.Description="Cute dot net bot waving hi to you!" SemanticProperties.Description="Cute dot net bot waving hi to you!"
HeightRequest="200" HeightRequest="200"
HorizontalOptions="Center" /> HorizontalOptions="Center" />
<Label <Label
Text="Hello, World!" Text="Hello, World!"
SemanticProperties.HeadingLevel="Level1" SemanticProperties.HeadingLevel="Level1"
FontSize="32" FontSize="32"
HorizontalOptions="Center" /> HorizontalOptions="Center" />
<Label <Label
x:Name="Message"
Text="Welcome to .NET Multi-platform App UI" Text="Welcome to .NET Multi-platform App UI"
SemanticProperties.HeadingLevel="Level2" SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to dot net Multi platform App U I" SemanticProperties.Description="Welcome to dot net Multi platform App U I"
@ -58,5 +59,5 @@
</VerticalStackLayout> </VerticalStackLayout>
</ScrollView> </ScrollView>
</ContentPage> </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. // Wait for the user to complete the authorization process.
var principal = (await _service.AuthenticateInteractivelyAsync(new() var principal = (await _service.AuthenticateInteractivelyAsync(new()
{ {
CancellationToken = source.Token,
Nonce = result.Nonce Nonce = result.Nonce
})).Principal; })).Principal;
await DisplayAlert("Authentication successful", $"Welcome, {principal.FindFirst(Claims.Name)!.Value}.", "OK"); Message.Text = $"Welcome, {principal.FindFirst(Claims.Name)!.Value}.";
} }
catch (OperationCanceledException) 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) 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 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 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) catch (OperationCanceledException)
{ {
await DisplayAlert("Logout timed out", "The logout process was aborted.", "OK"); Message.Text = "The logout process was aborted.";
} }
catch 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