Skip to content

Commit

Permalink
Merge pull request #155 from DuendeSoftware/brock/update-maui-sample
Browse files Browse the repository at this point in the history
add updated maui sample and include andriod support
  • Loading branch information
josephdecock authored Jan 5, 2024
2 parents 95bdb75 + a0cbdcc commit dc8957b
Show file tree
Hide file tree
Showing 45 changed files with 304 additions and 332 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31611.283
VisualStudioVersion = 17.8.34322.80
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiApp2", "MauiApp2.csproj", "{03BCBB00-4C99-48DC-8DDC-036F54166C7C}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MauiApp1", "MauiApp1\MauiApp1.csproj", "{F47CF5D7-9D19-48C1-9AC3-0F26B4133D92}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{03BCBB00-4C99-48DC-8DDC-036F54166C7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03BCBB00-4C99-48DC-8DDC-036F54166C7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03BCBB00-4C99-48DC-8DDC-036F54166C7C}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{03BCBB00-4C99-48DC-8DDC-036F54166C7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03BCBB00-4C99-48DC-8DDC-036F54166C7C}.Release|Any CPU.Build.0 = Release|Any CPU
{03BCBB00-4C99-48DC-8DDC-036F54166C7C}.Release|Any CPU.Deploy.0 = Release|Any CPU
{F47CF5D7-9D19-48C1-9AC3-0F26B4133D92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F47CF5D7-9D19-48C1-9AC3-0F26B4133D92}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F47CF5D7-9D19-48C1-9AC3-0F26B4133D92}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{F47CF5D7-9D19-48C1-9AC3-0F26B4133D92}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F47CF5D7-9D19-48C1-9AC3-0F26B4133D92}.Release|Any CPU.Build.0 = Release|Any CPU
{F47CF5D7-9D19-48C1-9AC3-0F26B4133D92}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
SolutionGuid = {CF4F4884-6B6D-4CA0-9BD0-FCD86EFD26F4}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp2"
x:Class="MauiApp2.App">
xmlns:local="clr-namespace:MauiApp1"
x:Class="MauiApp1.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MauiApp2;
namespace MauiApp1;

public partial class App : Application
{
Expand All @@ -8,4 +8,4 @@ public App()

MainPage = new AppShell();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="MauiApp2.AppShell"
x:Class="MauiApp1.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp2"
Shell.FlyoutBehavior="Disabled">
xmlns:local="clr-namespace:MauiApp1"
Shell.FlyoutBehavior="Disabled"
Title="MauiApp1">

<ShellContent
Title="Home"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace MauiApp2;
namespace MauiApp1;

public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
}
33 changes: 33 additions & 0 deletions various/clients/Maui/MauiApp1/MauiApp1/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiApp1.MainPage">

<ScrollView>
<VerticalStackLayout
Padding="30,0"
Spacing="25">

<Label
Text="OIDC Client Sample"
Style="{StaticResource Headline}"
SemanticProperties.HeadingLevel="Level1" />

<Button
x:Name="LoginButton"
Text="Login"
Clicked="OnLoginClicked"
HorizontalOptions="Fill" />
<Button
x:Name="ApiButton"
Text="Call API"
Clicked="OnApiClicked"
HorizontalOptions="Fill" />

<Editor x:Name="editor"
HeightRequest="350" />

</VerticalStackLayout>
</ScrollView>

</ContentPage>
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
using System.Net.Http.Json;
using IdentityModel.Client;
using IdentityModel.OidcClient;
using System.Text;
using System.Text.Json;
using IdentityModel.Client;
using IdentityModel.OidcClient;

namespace MauiApp2;
namespace MauiApp1;

public partial class MainPage
public partial class MainPage : ContentPage
{
private readonly OidcClient _client;
private string _currentAccessToken;

private readonly OidcClient _client = default!;
private string? _currentAccessToken;
public MainPage(OidcClient client)
{
InitializeComponent();

_client = client;
}

private async void OnLoginClicked(object sender, EventArgs e)
{
editor.Text = "Login Clicked";

var result = await _client.LoginAsync();

if (result.IsError)
Expand Down Expand Up @@ -53,6 +55,8 @@ private async void OnLoginClicked(object sender, EventArgs e)

private async void OnApiClicked(object sender, EventArgs e)
{
editor.Text = "API Clicked";

if (_currentAccessToken != null)
{
var client = new HttpClient();
Expand All @@ -71,4 +75,5 @@ private async void OnApiClicked(object sender, EventArgs e)
}
}
}
}
}

67 changes: 67 additions & 0 deletions various/clients/Maui/MauiApp1/MauiApp1/MauiApp1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->

<!-- Note for MacCatalyst:
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

<OutputType>Exe</OutputType>
<RootNamespace>MauiApp1</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<!-- Display name -->
<ApplicationTitle>MauiApp1</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.companyname.mauiapp1</ApplicationId>

<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />

<PackageReference Include="IdentityModel.OidcClient" Version="5.2.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using IdentityModel.Client;
using IdentityModel.OidcClient.Browser;

namespace MauiApp2;
namespace MauiApp1;

public class MauiAuthenticationBrowser : IdentityModel.OidcClient.Browser.IBrowser
{
Expand All @@ -19,7 +19,7 @@ public async Task<BrowserResult> InvokeAsync(BrowserOptions options, Cancellatio
return new BrowserResult
{
Response = url,
ResultType = BrowserResultType.Success
ResultType = BrowserResultType.Success,
};
}
catch (TaskCanceledException)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using IdentityModel.OidcClient;
using Microsoft.Extensions.Logging;

namespace MauiApp2;

namespace MauiApp1;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
Expand All @@ -15,8 +15,9 @@ public static MauiApp CreateMauiApp()
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

// add main page
builder.Services.AddSingleton<MainPage>();
#if DEBUG
builder.Logging.AddDebug();
#endif

// setup OidcClient
builder.Services.AddSingleton(new OidcClient(new()
Expand All @@ -30,6 +31,9 @@ public static MauiApp CreateMauiApp()
Browser = new MauiAuthenticationBrowser()
}));

// add main page
builder.Services.AddSingleton<MainPage>();

return builder.Build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<intent>
<action android:name="android.support.customtabs.action.CustomTabsService" />
</intent>
</queries>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Android.App;
using Android.Content.PM;
using Android.OS;

namespace MauiApp1;
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Android.App;
using Android.Runtime;

namespace MauiApp2;

namespace MauiApp1;
[Application]
public class MainApplication : MauiApplication
{
Expand All @@ -12,4 +11,4 @@ public MainApplication(IntPtr handle, JniHandleOwnership ownership)
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Android.App;
using Android.Content.PM;

namespace YourNameSpace;

[Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTop, Exported = true)]
[IntentFilter(new[] { Android.Content.Intent.ActionView },
Categories = new[] { Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable },
DataScheme = CALLBACK_SCHEME)]
public class WebAuthenticationCallbackActivity : Microsoft.Maui.Authentication.WebAuthenticatorCallbackActivity
{
const string CALLBACK_SCHEME = "myapp";

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Foundation;

namespace MauiApp2;

namespace MauiApp1;
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- See https://aka.ms/maui-publish-app-store#add-entitlements for more information about adding entitlements.-->
<dict>
<!-- App Sandbox must be enabled to distribute a MacCatalyst app through the Mac App Store. -->
<key>com.apple.security.app-sandbox</key>
<true/>
<!-- When App Sandbox is enabled, this value is required to open outgoing network connections. -->
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using UIKit;

namespace MauiApp2;
using ObjCRuntime;
using UIKit;

namespace MauiApp1;
public class Program
{
// This is the main entry point of the application.
Expand All @@ -11,4 +11,4 @@ static void Main(string[] args)
// you can specify it here.
UIApplication.Main(args, null, typeof(AppDelegate));
}
}
}
Loading

0 comments on commit dc8957b

Please sign in to comment.