From 362a52fd14ddcdbcd2183ae4a9a419e09f050a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Sat, 29 Jun 2024 18:18:08 +0200 Subject: [PATCH] Add a MAUI client sample --- Directory.Build.props | 65 ++- Directory.Build.targets | 7 + Directory.Packages.props | 2 + OpenIddict.sln | 9 + ...penIddict.Sandbox.AspNetCore.Client.csproj | 1 - ...penIddict.Sandbox.AspNetCore.Server.csproj | 2 - .../Worker.cs | 41 ++ .../OpenIddict.Sandbox.Console.Client.csproj | 2 - .../OpenIddict.Sandbox.Maui.Client/App.xaml | 14 + .../App.xaml.cs | 13 + .../AppShell.xaml | 14 + .../AppShell.xaml.cs | 8 + .../MainPage.xaml | 62 +++ .../MainPage.xaml.cs | 149 +++++++ .../MauiHostApplicationLifetime.cs | 22 + .../MauiHostedServiceAdapter.cs | 16 + .../MauiProgram.cs | 131 ++++++ .../OpenIddict.Sandbox.Maui.Client.csproj | 47 +++ .../Platforms/Windows/App.xaml | 8 + .../Platforms/Windows/App.xaml.cs | 10 + .../Platforms/Windows/Package.appxmanifest | 51 +++ .../Platforms/Windows/app.manifest | 15 + .../Platforms/iOS/AppDelegate.cs | 11 + .../Platforms/iOS/Info.plist | 45 ++ .../Platforms/iOS/Program.cs | 11 + .../OpenIddict.Sandbox.Maui.Client/Program.cs | 3 + .../Properties/launchSettings.json | 8 + .../Resources/AppIcon/appicon.svg | 4 + .../Resources/AppIcon/appiconfg.svg | 8 + .../Resources/Fonts/OpenSans-Regular.ttf | Bin 0 -> 107140 bytes .../Resources/Fonts/OpenSans-Semibold.ttf | Bin 0 -> 111028 bytes .../Resources/Images/dotnet_bot.svg | 93 +++++ .../Resources/Raw/AboutAssets.txt | 15 + .../Resources/Splash/splash.svg | 8 + .../Resources/Styles/Colors.xaml | 44 ++ .../Resources/Styles/Styles.xaml | 384 ++++++++++++++++++ .../OpenIddict.Sandbox.Maui.Client/Worker.cs | 14 + .../OpenIddict.Sandbox.WinForms.Client.csproj | 6 +- .../OpenIddict.Sandbox.Wpf.Client.csproj | 6 +- ...OpenIddict.Client.SystemIntegration.csproj | 1 - ...ystemIntegrationHandlers.Authentication.cs | 3 +- ...ClientSystemIntegrationHandlers.Session.cs | 3 +- ...penIddictClientSystemIntegrationHelpers.cs | 2 +- src/OpenIddict/OpenIddict.csproj | 1 - 44 files changed, 1321 insertions(+), 38 deletions(-) create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/App.xaml create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/App.xaml.cs create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/AppShell.xaml create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/AppShell.xaml.cs create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/MainPage.xaml create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/MainPage.xaml.cs create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/MauiHostApplicationLifetime.cs create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/MauiHostedServiceAdapter.cs create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/MauiProgram.cs create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/OpenIddict.Sandbox.Maui.Client.csproj create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Platforms/Windows/App.xaml create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Platforms/Windows/App.xaml.cs create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Platforms/Windows/Package.appxmanifest create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Platforms/Windows/app.manifest create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Platforms/iOS/AppDelegate.cs create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Platforms/iOS/Info.plist create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Platforms/iOS/Program.cs create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Program.cs create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Properties/launchSettings.json create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Resources/AppIcon/appicon.svg create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Resources/AppIcon/appiconfg.svg create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Resources/Fonts/OpenSans-Regular.ttf create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Resources/Fonts/OpenSans-Semibold.ttf create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Resources/Images/dotnet_bot.svg create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Resources/Raw/AboutAssets.txt create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Resources/Splash/splash.svg create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Resources/Styles/Colors.xaml create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Resources/Styles/Styles.xaml create mode 100644 sandbox/OpenIddict.Sandbox.Maui.Client/Worker.cs diff --git a/Directory.Build.props b/Directory.Build.props index 33a9154d..b1467cd0 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -7,7 +7,7 @@ true preview true - $(NoWarn);CS1591;NU5118;NU5128;xUnit2002 + $(NoWarn);CS1591;NETSDK1206;NU5118;NU5128;xUnit2002 NU1901;NU1902;NU1903;NU1904 enable enable @@ -33,6 +33,31 @@ + + true + + true + + + true + net461; net472; @@ -45,19 +70,14 @@ net8.0 - - net8.0-ios + Condition=" '$(NetCoreIOSTargetFrameworks)' == '' And '$(SupportsIOSPlatformTargeting)' == 'true' "> + net8.0-ios12.0; + net8.0-ios13.0 - + net6.0-windows7.0; net6.0-windows10.0.17763; net7.0-windows7.0; @@ -71,18 +91,14 @@ netstandard2.1 - + Condition=" '$(UniversalWindowsPlatformTargetFrameworks)' == '' And '$(SupportsUniversalWindowsPlatformTargeting)' == 'true' "> uap10.0.17763 + + 12.0 + 7.0 + 7.0 @@ -115,6 +131,15 @@ $(_ComputedOfficialBuildId) + + false + false + false + false + false + false + + true true diff --git a/Directory.Build.targets b/Directory.Build.targets index 6c77786a..f9fcb2a1 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -130,6 +130,13 @@ $(DefineConstants);SUPPORTS_UIKIT + + $(DefineConstants);SUPPORTS_PRESENTATION_CONTEXT_PROVIDER + + + + diff --git a/OpenIddict.sln b/OpenIddict.sln index aaaaea70..b281b36c 100644 --- a/OpenIddict.sln +++ b/OpenIddict.sln @@ -157,6 +157,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenIddict.Sandbox.WinForms EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenIddict.Sandbox.Console.Client", "sandbox\OpenIddict.Sandbox.Console.Client\OpenIddict.Sandbox.Console.Client.csproj", "{819CD7AA-01FD-4369-BABF-5DFCB7E94068}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenIddict.Sandbox.Maui.Client", "sandbox\OpenIddict.Sandbox.Maui.Client\OpenIddict.Sandbox.Maui.Client.csproj", "{CD5EE836-ED56-48E3-B3B6-8D74C7C859B9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -383,6 +385,12 @@ Global {819CD7AA-01FD-4369-BABF-5DFCB7E94068}.Debug|Any CPU.Build.0 = Debug|Any CPU {819CD7AA-01FD-4369-BABF-5DFCB7E94068}.Release|Any CPU.ActiveCfg = Release|Any CPU {819CD7AA-01FD-4369-BABF-5DFCB7E94068}.Release|Any CPU.Build.0 = Release|Any CPU + {CD5EE836-ED56-48E3-B3B6-8D74C7C859B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD5EE836-ED56-48E3-B3B6-8D74C7C859B9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD5EE836-ED56-48E3-B3B6-8D74C7C859B9}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {CD5EE836-ED56-48E3-B3B6-8D74C7C859B9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD5EE836-ED56-48E3-B3B6-8D74C7C859B9}.Release|Any CPU.Build.0 = Release|Any CPU + {CD5EE836-ED56-48E3-B3B6-8D74C7C859B9}.Release|Any CPU.Deploy.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -443,6 +451,7 @@ Global {D0C56832-6557-4CC1-91EA-7B31B18BEE7A} = {F47D1283-0EE9-4728-8026-58405C29B786} {35997586-8AAB-4EE5-A022-3E5BD12746CE} = {F47D1283-0EE9-4728-8026-58405C29B786} {819CD7AA-01FD-4369-BABF-5DFCB7E94068} = {F47D1283-0EE9-4728-8026-58405C29B786} + {CD5EE836-ED56-48E3-B3B6-8D74C7C859B9} = {F47D1283-0EE9-4728-8026-58405C29B786} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {A710059F-0466-4D48-9B3A-0EF4F840B616} diff --git a/sandbox/OpenIddict.Sandbox.AspNetCore.Client/OpenIddict.Sandbox.AspNetCore.Client.csproj b/sandbox/OpenIddict.Sandbox.AspNetCore.Client/OpenIddict.Sandbox.AspNetCore.Client.csproj index f97b3a4b..93de5836 100644 --- a/sandbox/OpenIddict.Sandbox.AspNetCore.Client/OpenIddict.Sandbox.AspNetCore.Client.csproj +++ b/sandbox/OpenIddict.Sandbox.AspNetCore.Client/OpenIddict.Sandbox.AspNetCore.Client.csproj @@ -2,7 +2,6 @@ net48;net8.0 - false disable diff --git a/sandbox/OpenIddict.Sandbox.AspNetCore.Server/OpenIddict.Sandbox.AspNetCore.Server.csproj b/sandbox/OpenIddict.Sandbox.AspNetCore.Server/OpenIddict.Sandbox.AspNetCore.Server.csproj index 07d99588..bea71b8c 100644 --- a/sandbox/OpenIddict.Sandbox.AspNetCore.Server/OpenIddict.Sandbox.AspNetCore.Server.csproj +++ b/sandbox/OpenIddict.Sandbox.AspNetCore.Server/OpenIddict.Sandbox.AspNetCore.Server.csproj @@ -2,8 +2,6 @@ net48;net8.0 - false - false false disable diff --git a/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Worker.cs b/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Worker.cs index aaf8556c..07e73800 100644 --- a/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Worker.cs +++ b/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Worker.cs @@ -103,6 +103,47 @@ public class Worker : IHostedService }); } + if (await manager.FindByClientIdAsync("maui") is null) + { + await manager.CreateAsync(new OpenIddictApplicationDescriptor + { + ApplicationType = ApplicationTypes.Native, + ClientId = "maui", + ClientType = ClientTypes.Public, + ConsentType = ConsentTypes.Systematic, + DisplayName = "MAUI client application", + DisplayNames = + { + [CultureInfo.GetCultureInfo("fr-FR")] = "Application cliente MAUI" + }, + PostLogoutRedirectUris = + { + new Uri("com.openiddict.sandbox.maui.client:/callback/logout/local") + }, + RedirectUris = + { + new Uri("com.openiddict.sandbox.maui.client:/callback/login/local") + }, + Permissions = + { + Permissions.Endpoints.Authorization, + Permissions.Endpoints.Logout, + Permissions.Endpoints.Token, + Permissions.GrantTypes.AuthorizationCode, + Permissions.GrantTypes.RefreshToken, + Permissions.ResponseTypes.Code, + Permissions.Scopes.Email, + Permissions.Scopes.Profile, + Permissions.Scopes.Roles, + Permissions.Prefixes.Scope + "demo_api" + }, + Requirements = + { + Requirements.Features.ProofKeyForCodeExchange + } + }); + } + if (await manager.FindByClientIdAsync("mvc") is null) { await manager.CreateAsync(new OpenIddictApplicationDescriptor diff --git a/sandbox/OpenIddict.Sandbox.Console.Client/OpenIddict.Sandbox.Console.Client.csproj b/sandbox/OpenIddict.Sandbox.Console.Client/OpenIddict.Sandbox.Console.Client.csproj index b6c184db..738601fe 100644 --- a/sandbox/OpenIddict.Sandbox.Console.Client/OpenIddict.Sandbox.Console.Client.csproj +++ b/sandbox/OpenIddict.Sandbox.Console.Client/OpenIddict.Sandbox.Console.Client.csproj @@ -3,8 +3,6 @@ Exe net48;net8.0 - false - false diff --git a/sandbox/OpenIddict.Sandbox.Maui.Client/App.xaml b/sandbox/OpenIddict.Sandbox.Maui.Client/App.xaml new file mode 100644 index 00000000..7a653d33 --- /dev/null +++ b/sandbox/OpenIddict.Sandbox.Maui.Client/App.xaml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/sandbox/OpenIddict.Sandbox.Maui.Client/App.xaml.cs b/sandbox/OpenIddict.Sandbox.Maui.Client/App.xaml.cs new file mode 100644 index 00000000..42de8c84 --- /dev/null +++ b/sandbox/OpenIddict.Sandbox.Maui.Client/App.xaml.cs @@ -0,0 +1,13 @@ +#if IOS || WINDOWS +namespace OpenIddict.Sandbox.Maui.Client; + +public partial class App : Application +{ + public App() + { + InitializeComponent(); + + MainPage = new AppShell(); + } +} +#endif diff --git a/sandbox/OpenIddict.Sandbox.Maui.Client/AppShell.xaml b/sandbox/OpenIddict.Sandbox.Maui.Client/AppShell.xaml new file mode 100644 index 00000000..aac5eadd --- /dev/null +++ b/sandbox/OpenIddict.Sandbox.Maui.Client/AppShell.xaml @@ -0,0 +1,14 @@ + + + + + + diff --git a/sandbox/OpenIddict.Sandbox.Maui.Client/AppShell.xaml.cs b/sandbox/OpenIddict.Sandbox.Maui.Client/AppShell.xaml.cs new file mode 100644 index 00000000..b3c46f73 --- /dev/null +++ b/sandbox/OpenIddict.Sandbox.Maui.Client/AppShell.xaml.cs @@ -0,0 +1,8 @@ +#if IOS || WINDOWS +namespace OpenIddict.Sandbox.Maui.Client; + +public partial class AppShell : Shell +{ + public AppShell() => InitializeComponent(); +} +#endif diff --git a/sandbox/OpenIddict.Sandbox.Maui.Client/MainPage.xaml b/sandbox/OpenIddict.Sandbox.Maui.Client/MainPage.xaml new file mode 100644 index 00000000..3db3b890 --- /dev/null +++ b/sandbox/OpenIddict.Sandbox.Maui.Client/MainPage.xaml @@ -0,0 +1,62 @@ + + + + + + + + +