Poeler
Poeler
Explore posts from servers
CC#
Created by Poeler on 7/1/2024 in #help
runtime crashing debugger crashing
i'm using rider, .NET8 and the microsoft jwt package, it run inside docker container, and i'm on apple silicon processor
13 replies
CC#
Created by Poeler on 7/1/2024 in #help
runtime crashing debugger crashing
here's the handler
13 replies
CC#
Created by Poeler on 7/1/2024 in #help
runtime crashing debugger crashing
namespace OpenGMAO.Handlers
{
public class AuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
{
public AuthenticationHandler(
IOptionsMonitor<AuthenticationSchemeOptions> options,
ILoggerFactory logger,
UrlEncoder encoder,
ISystemClock clock)
: base(options, logger, encoder, clock)
{
}

protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
{
if (!Request.Headers.ContainsKey("Authorization"))
{
return AuthenticateResult.Fail("Unauthorized");
}

string authorizationHeader = Request.Headers["Authorization"];
if (string.IsNullOrEmpty(authorizationHeader))
{
return AuthenticateResult.Fail("Unauthorized");
}

if (!authorizationHeader.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
{
return AuthenticateResult.Fail("Unauthorized");
}

var token = authorizationHeader.Substring(7);

try
{
var handler = new JwtSecurityTokenHandler();
var tokenS = handler.ReadToken(token) as JwtSecurityToken;
if (tokenS == null)
{
return AuthenticateResult.Fail("Invalid token");
}

var claims = tokenS.Claims.ToList();
var claimsIdentity = new ClaimsIdentity(claims, Scheme.Name);
var ticket = new AuthenticationTicket(new ClaimsPrincipal(claimsIdentity), Scheme.Name);

return AuthenticateResult.Success(ticket);
}
catch (Exception ex)
{
Logger.LogError(ex, "Error during token validation");
return AuthenticateResult.Fail("Unauthorized");
}
}
}
}
namespace OpenGMAO.Handlers
{
public class AuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
{
public AuthenticationHandler(
IOptionsMonitor<AuthenticationSchemeOptions> options,
ILoggerFactory logger,
UrlEncoder encoder,
ISystemClock clock)
: base(options, logger, encoder, clock)
{
}

protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
{
if (!Request.Headers.ContainsKey("Authorization"))
{
return AuthenticateResult.Fail("Unauthorized");
}

string authorizationHeader = Request.Headers["Authorization"];
if (string.IsNullOrEmpty(authorizationHeader))
{
return AuthenticateResult.Fail("Unauthorized");
}

if (!authorizationHeader.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
{
return AuthenticateResult.Fail("Unauthorized");
}

var token = authorizationHeader.Substring(7);

try
{
var handler = new JwtSecurityTokenHandler();
var tokenS = handler.ReadToken(token) as JwtSecurityToken;
if (tokenS == null)
{
return AuthenticateResult.Fail("Invalid token");
}

var claims = tokenS.Claims.ToList();
var claimsIdentity = new ClaimsIdentity(claims, Scheme.Name);
var ticket = new AuthenticationTicket(new ClaimsPrincipal(claimsIdentity), Scheme.Name);

return AuthenticateResult.Success(ticket);
}
catch (Exception ex)
{
Logger.LogError(ex, "Error during token validation");
return AuthenticateResult.Fail("Unauthorized");
}
}
}
}
13 replies
CC#
Created by Poeler on 4/27/2023 in #help
dotnet build remove all my nuget package (wtf)
hm nvm it seems to build even if the packages are hidden
12 replies
CC#
Created by Poeler on 4/27/2023 in #help
dotnet build remove all my nuget package (wtf)
dotnet restore
Determining projects to restore...
All projects are up-to-date for restore.
dotnet restore
Determining projects to restore...
All projects are up-to-date for restore.
12 replies
CC#
Created by Poeler on 4/27/2023 in #help
dotnet build remove all my nuget package (wtf)
csproj
12 replies
CC#
Created by Poeler on 4/27/2023 in #help
dotnet build remove all my nuget package (wtf)
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>1a169678-01af-4717-954a-853b9228f157</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
</ItemGroup>



</Project>
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>1a169678-01af-4717-954a-853b9228f157</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
</ItemGroup>



</Project>
12 replies