Skip to content

Commit

Permalink
chore: sample updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Jan 31, 2023
1 parent a7266d5 commit 7d29674
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
26 changes: 23 additions & 3 deletions sample/DemoAPI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Diagnostics;
using AvantiPoint.MobileAuth;
using AvantiPoint.MobileAuth.Authentication;
using DemoAPI.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -18,15 +19,34 @@
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var versionInfo = FileVersionInfo.GetVersionInfo(typeof(MobileAuth).Assembly.Location);
var version = $"{versionInfo.FileMajorPart}.{versionInfo.ProductMinorPart}.{versionInfo.ProductBuildPart}";
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc($"v1", new OpenApiInfo
{
Title = "Mobile Auth - Demo",
Contact = new OpenApiContact
{
Name = "AvantiPoint",
Email = "[email protected]",
Url = new Uri("https://avantipoint.com")
},
Description = "This is a demo api for the AvantiPoint Mobile Auth library. Do not use this API for production. For more information please visit https://github.com/avantipoint/mobileauth-lib",
Version = version
});
});

var app = builder.Build();

// Configure the HTTP request pipeline.

app.UseHttpsRedirection();
app.UseSwagger();
app.UseSwaggerUI();
app.UseSwaggerUI(o =>
{
o.InjectStylesheet("https://cdn.avantipoint.com/theme/swagger/style.css");
});

app.UseAuthentication();
app.UseAuthorization();
Expand Down
1 change: 1 addition & 0 deletions sample/DemoMobileApp/DemoMobileApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

<ItemGroup>
<PackageReference Include="AvantiPoint.MauiMicroMvvm" Version="0.1.3" />
<PackageReference Include="CommunityToolkit.Maui" Version="4.0.0" />
<PackageReference Include="Refit" Version="6.3.2" />
</ItemGroup>

Expand Down
9 changes: 7 additions & 2 deletions sample/DemoMobileApp/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:x="http:https://schemas.microsoft.com/winfx/2009/xaml"
xmlns:vm="clr-namespace:DemoMobileApp.ViewModels"
xmlns:converter="clr-namespace:DemoMobileApp.Converters"
xmlns:toolkit="http:https://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:DataType="vm:MainPageViewModel"
x:Class="DemoMobileApp.MainPage">
<ContentPage.Resources>
Expand Down Expand Up @@ -35,10 +36,14 @@
<CollectionView ItemsSource="{Binding Claims}"
IsVisible="{Binding Claims, Converter={StaticResource IsAuthenticated}}">
<CollectionView.Header>
<Image Source="dotnet_bot.png"
<Image
HorizontalOptions="Center"
HeightRequest="150"
Margin="0,15,0,20"/>
Margin="0,15,0,20">
<Image.Source>
<toolkit:GravatarImageSource Email="{Binding Email}" />
</Image.Source>
</Image>
</CollectionView.Header>
<CollectionView.ItemTemplate>
<DataTemplate>
Expand Down
2 changes: 2 additions & 0 deletions sample/DemoMobileApp/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using CommunityToolkit.Maui;
using DemoMobileApp.Services;
using DemoMobileApp.ViewModels;
using Refit;
Expand All @@ -19,6 +20,7 @@ public static MauiApp CreateMauiApp()
.UseMauiMicroMvvm<AppShell>(
"Resources/Styles/Colors.xaml",
"Resources/Styles/Styles.xaml")
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
Expand Down
9 changes: 9 additions & 0 deletions sample/DemoMobileApp/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public MainPageViewModel(ViewModelContext context, ISecureStorage storage, IWebA

public ObservableCollection<string> Claims { get; }

public string Email
{
get => Get<string>();
set => Set(value);
}

public Command<string> LoginCommand { get; }

private async void OnLoginCommandExecuted(string scheme)
Expand All @@ -44,6 +50,9 @@ private async void OnLoginCommandExecuted(string scheme)
var claims = response.Content.Select(x => $"{x.Key}: {x.Value}");
foreach (var claim in claims)
Claims.Add(claim);

if (response.Content.TryGetValue("email", out var email))
Email = email;
}
}
catch (Exception ex)
Expand Down

0 comments on commit 7d29674

Please sign in to comment.