Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions various/clients/Maui/net10/MauiApp1/MauiApp1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net10.0-android;net10.0-ios;net10.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net10.0-windows10.0.19041.0</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>
<!-- https://github.com/CommunityToolkit/Maui/issues/2921 -->
<NoWarn>NU1608</NoWarn>
<MauiEnableXamlCBindingWithSourceCompilation>true</MauiEnableXamlCBindingWithSourceCompilation>

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

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

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

<!-- To develop, package, and publish an app to the Microsoft Store, see: https://aka.ms/MauiTemplateUnpackaged -->
<WindowsPackageType>None</WindowsPackageType>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</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>
</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="Duende.IdentityModel.OidcClient" Version="7.0.0-rc.1" />
<PackageReference Include="Microsoft.Maui.Controls" Version="10.0.10" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="10.0.10" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.0" />
</ItemGroup>

</Project>
34 changes: 34 additions & 0 deletions various/clients/Maui/net10/MauiApp1/MauiAuthenticationBrowser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Duende.IdentityModel.Client;
using Duende.IdentityModel.OidcClient.Browser;

namespace MauiApp1;

public class MauiAuthenticationBrowser : Duende.IdentityModel.OidcClient.Browser.IBrowser
{
public async Task<BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default)
{
try
{
var result = await WebAuthenticator.Default.AuthenticateAsync(
new Uri(options.StartUrl),
new Uri(options.EndUrl),
cancellationToken);

var url = new RequestUrl("myapp://callback")
.Create(new Parameters(result.Properties));

return new BrowserResult
{
Response = url,
ResultType = BrowserResultType.Success,
};
}
catch (TaskCanceledException)
{
return new BrowserResult
{
ResultType = BrowserResultType.UserCancel
};
}
}
}
43 changes: 43 additions & 0 deletions various/clients/Maui/net10/MauiApp1/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Duende.IdentityModel.OidcClient;
using Microsoft.Extensions.Logging;

namespace MauiApp1;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if DEBUG
builder.Logging.AddDebug();
builder.Services.AddLogging(configure => configure.AddDebug());
#endif

// setup OidcClient
builder.Services.AddSingleton(new OidcClient(new()
{
Authority = "https://demo.duendesoftware.com",

ClientId = "interactive.public",
Scope = "openid profile api",
RedirectUri = "myapp://callback",

Browser = new MauiAuthenticationBrowser()
}));

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

return builder.Build();
}
}
27 changes: 27 additions & 0 deletions various/clients/Maui/net9/MauiApp1.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34322.80
MinimumVisualStudioVersion = 10.0.40219.1
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
{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 = {CF4F4884-6B6D-4CA0-9BD0-FCD86EFD26F4}
EndGlobalSection
EndGlobal
14 changes: 14 additions & 0 deletions various/clients/Maui/net9/MauiApp1/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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:MauiApp1"
x:Class="MauiApp1.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
9 changes: 9 additions & 0 deletions various/clients/Maui/net9/MauiApp1/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

namespace MauiApp1;

public partial class App : Application
{
public App() => InitializeComponent();

protected override Window CreateWindow(IActivationState? activationState) => new Window(new AppShell());
}
15 changes: 15 additions & 0 deletions various/clients/Maui/net9/MauiApp1/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
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:MauiApp1"
Shell.FlyoutBehavior="Disabled"
Title="MauiApp1">

<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />

</Shell>
9 changes: 9 additions & 0 deletions various/clients/Maui/net9/MauiApp1/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MauiApp1;

public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
33 changes: 33 additions & 0 deletions various/clients/Maui/net9/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>
79 changes: 79 additions & 0 deletions various/clients/Maui/net9/MauiApp1/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using Duende.IdentityModel.Client;
using Duende.IdentityModel.OidcClient;
using System.Text;
using System.Text.Json;

namespace MauiApp1;

public partial class MainPage : ContentPage
{
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)
{
editor.Text = result.Error;
return;
}

_currentAccessToken = result.AccessToken;

var sb = new StringBuilder(128);

sb.AppendLine("claims:");
foreach (var claim in result.User.Claims)
{
sb.AppendLine($"{claim.Type}: {claim.Value}");
}

sb.AppendLine();
sb.AppendLine("access token:");
sb.AppendLine(result.AccessToken);

if (!string.IsNullOrWhiteSpace(result.RefreshToken))
{
sb.AppendLine();
sb.AppendLine("access token:");
sb.AppendLine(result.AccessToken);
}

editor.Text = sb.ToString();
}

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

if (_currentAccessToken != null)
{
var client = new HttpClient();
client.SetBearerToken(_currentAccessToken);

var response = await client.GetAsync("https://demo.duendesoftware.com/api/test");
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var doc = JsonDocument.Parse(content).RootElement;
editor.Text = JsonSerializer.Serialize(doc, new JsonSerializerOptions { WriteIndented = true });
}
else
{
editor.Text = response.ReasonPhrase;
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<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,11 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Android.App;
using Android.Content.PM;

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
@@ -0,0 +1,17 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Android.App;
using Android.Runtime;

namespace MauiApp1;
[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#512BD4</color>
<color name="colorPrimaryDark">#2B0B98</color>
<color name="colorAccent">#2B0B98</color>
</resources>
Loading
Loading