Skip to content

Commit

Permalink
Last of the fixes for API
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Dec 16, 2024
1 parent ff145e6 commit 46ab31e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 66 deletions.
8 changes: 8 additions & 0 deletions ProjectTemplates/ShinyAspNet/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public static class Constants
{
#if (efpostgres)
public const string DatabaseInvariant = "Npgsql";
#else
public const string DatabaseInvariant = "System.Data.SqlClient";
#endif
}
5 changes: 4 additions & 1 deletion ProjectTemplates/ShinyAspNet/Handlers/Auth/RefreshHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public class RefreshHandler(AppDbContext data, JwtService jwtService) : IRequest
{
public async Task<RefreshResponse> Handle(RefreshRequest request, CancellationToken cancellationToken)
{
var result = await jwtService.ValidateRefreshToken(request.Token);
var result = await jwtService
.ValidateRefreshToken(request.Token, cancellationToken)
.ConfigureAwait(false);

if (!result)
return RefreshResponse.Fail;

Expand Down
14 changes: 9 additions & 5 deletions ProjectTemplates/ShinyAspNet/Handlers/Auth/SignInHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ namespace ShinyAspNet.Handlers.Auth;
"/auth/signin/mobile",
AllowAnonymous = true
)]
public class SignInHandler(AppDbContext data, JwtService jwtService, IHttpContextAccessor httpAccessor) : IRequestHandler<SignInRequest, SignInResponse>
public class SignInHandler(
AppDbContext data,
JwtService jwtService,
IHttpContextAccessor httpAccessor
) : IRequestHandler<SignInRequest, SignInResponse>
{
public async Task<SignInResponse> Handle(SignInRequest request, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -53,18 +57,18 @@ public async Task<SignInResponse> Handle(SignInRequest request, CancellationToke
}
user.FirstName = claims!.First(x => x.Type == ClaimTypes.GivenName).Value;
user.LastName = claims!.First(x => x.Type == ClaimTypes.Surname).Value;
await data.SaveChangesAsync();
await data.SaveChangesAsync(cancellationToken);

var uri = await this.CreateTokenToApp(user, newUser, cancellationToken);
return SignInResponse.Sucessful(uri);
}


async Task<string> CreateTokenToApp(User user, bool newUser)
async Task<string> CreateTokenToApp(User user, bool newUser, CancellationToken cancellationToken)
{
var tokens = await jwtService.CreateJwt(user);
var tokens = await jwtService.CreateJwt(user, cancellationToken);
var url = $"myapp://#newuser={newUser}&access_token={tokens.Jwt}&refresh_token={tokens.RefreshToken}";

return url;
}
}
63 changes: 34 additions & 29 deletions ProjectTemplates/ShinyAspNet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
using Microsoft.Extensions.FileProviders;
using OpenTelemetry.Exporter;
using OpenTelemetry.Logs;
using OpenTelemetry.Trace;
#if (orleans)
using Orleans.Configuration;
#endif
#if (efpostgres)
using Npgsql;
#endif
Expand Down Expand Up @@ -40,6 +44,29 @@
});
});

builder
.Services
.AddOpenTelemetry()
.WithMetrics(metrics =>
{
// metrics
// .AddPrometheusExporter()
// .AddMeter("Microsoft.Orleans");
})
.WithTracing(tracing =>
{
var service = ResourceBuilder.CreateDefault().AddService("WorkflowSystem", "1.0");
tracing.SetResourceBuilder(service);

tracing.AddSource("Microsoft.Orleans.Runtime");
tracing.AddSource("Microsoft.Orleans.Application");

// tracing.AddZipkinExporter(zipkin =>
// {
// zipkin.Endpoint = new Uri("http://localhost:9411/api/v2/spans");
// });
});

builder.Services
.AddHealthChecks()
.AddDbContextCheck<AppDbContext>();
Expand Down Expand Up @@ -103,28 +130,6 @@
};
});

builder
.Services
.AddOpenTelemetry()
.WithMetrics(metrics =>
{
// metrics
// .AddPrometheusExporter()
// .AddMeter("Microsoft.Orleans");
})
.WithTracing(tracing =>
{
var service = ResourceBuilder.CreateDefault().AddService("WorkflowSystem", "1.0");
tracing.SetResourceBuilder(service);

tracing.AddSource("Microsoft.Orleans.Runtime");
tracing.AddSource("Microsoft.Orleans.Application");

// tracing.AddZipkinExporter(zipkin =>
// {
// zipkin.Endpoint = new Uri("http://localhost:9411/api/v2/spans");
// });
});

//#if (google)
builder.Services.AddAuthentication().AddGoogle(options =>
Expand Down Expand Up @@ -179,24 +184,24 @@
.UseDashboard(x => {})
.UseAdoNetReminderService(options =>
{
options.ConnectionString = config.GetConnectionString("Orleans");
options.ConnectionString = builder.Configuration.GetConnectionString("Orleans");
options.Invariant = Constants.DatabaseInvariant;
})
.UseAdoNetClustering(options =>
{
options.ConnectionString = config.GetConnectionString("Orleans");
options.Invariant = Constants.DatabaseInvariant;
options.ConnectionString = builder.Configuration.GetConnectionString("Orleans");
// options.Invariant = Constants.DatabaseInvariant;
})
.AddAdoNetGrainStorage("Default", options =>
{
options.ConnectionString = config.GetConnectionString("Orleans");
options.Invariant = Constants.DatabaseInvariant;
options.ConnectionString = builder.Configuration.GetConnectionString("Orleans");
//options.Invariant = Constants.DatabaseInvariant;
// options.UseJsonFormat = true;
})
.AddAdoNetStreams("Default", options =>
{
options.ConnectionString = config.GetConnectionString("Orleans");
options.Invariant = Constants.DatabaseInvariant;
options.ConnectionString = builder.Configuration.GetConnectionString("Orleans");
//options.Invariant = Constants.DatabaseInvariant;
});
});
//#endif
Expand Down
13 changes: 8 additions & 5 deletions ProjectTemplates/ShinyAspNet/ShinyAspNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
<TargetFramework>{DOTNET_TFM}</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<ShinyExtensionsVersion>2.0.0-preview-0036</ShinyExtensionsVersion>
<MicrosoftVersion>9.0.0</MicrosoftVersion>
<LangVersion>latest</LangVersion>
<!--#if (orleans)-->
<OrleansVersion>9.0.1</OrleansVersion>
<!--#endif-->
<!--#if (email || push)-->
<ShinyExtensionsVersion>2.0.0-preview-0036</ShinyExtensionsVersion>
<!--#endif-->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="$(MicrosoftVersion)" />
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="$(MicrosoftVersion)">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="$(MicrosoftVersion)" />
<!--#if (efmssql)-->
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(MicrosoftVersion)" />
Expand All @@ -32,7 +34,7 @@
<PackageReference Include="Microsoft.Orleans.Reminders" Version="$(OrleansVersion)"/>
<PackageReference Include="Microsoft.Orleans.Reminders.AdoNet" Version="$(OrleansVersion)" />
<PackageReference Include="Microsoft.Orleans.Streaming" Version="$(OrleansVersion)"/>
<PackageReference Include="Microsoft.Orleans.Streaming.AdoNet" Version="$(OrleansVersion)" />
<PackageReference Include="Microsoft.Orleans.Streaming.AdoNet" Version="$(OrleansVersion)-alpha.1" />
<PackageReference Include="OrleansDashboard" Version="8.2.0" />
<!--#endif-->
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="$(MicrosoftVersion)" />
Expand Down Expand Up @@ -62,6 +64,7 @@
<!--#endif-->

<!-- <PackageReference Include="Riok.Mapperly" Version="3.6.0" /> -->
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
Expand Down
30 changes: 4 additions & 26 deletions ProjectTemplates/ShinyAspNet/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
{
"ConnectionStrings": {
"Main": "{CONNECTION_STRING}"
},
//#if (email)
"Mail":{
"Smtp":{
"EnableSsl": true,
"Host": "localhost",
"Post": "587"
}
},
//#endif
//#if (push)
"Push":{
"Apple":{
"Production": false,
"TeamId": "",
"AppBundleIdentifier": "",
"Key": "",
"KeyId": ""
},
"Google":{
"SenderId": "",
"ServerKey": "",
"DefaultChannelId": ""
}
"Main": "{CONNECTION_STRING}",
//#if (orleans)
"Orleans": "{CONNECTION_STRING}"
//#endif
},
//#endif
"Authentication": {
//#if (google)
"Google": {
Expand Down

0 comments on commit 46ab31e

Please sign in to comment.