Skip to content

Instantly share code, notes, and snippets.

public async Task<T> GetAsync<T>(string url)
{
if (string.IsNullOrWhiteSpace(url))
return default;
var client = _httpClientFactory.CreateClient("MyApiClient");
var tokenResult = await _accessTokenProvider.RequestAccessToken();
if (tokenResult.TryGetToken(out var token))
options.TokenValidationParameters = new TokenValidationParameters() {
ValidateIssuerSigningKey = true,
ValidateIssuer = true,
ValidateAudience = true,
ValidIssuer = Configuration["Authentication:Jwt:Issuer"],
ValidAudience = Configuration["Authentication:Jwt:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Authentication:Jwt:IssuerSigningKey"]))
};
private const int DefaultBufferSize = 4096;
private protected async Task<IActionResult> ReadRangedContentAsync(Func<byte[], Task<Result>> readCallback)
{
if (!Request.HasFormContentType ||
!MediaTypeHeaderValue.TryParse(Request.ContentType, out var contentType) ||
!contentType.Boundary.HasValue ||
!Request.Headers.TryGetValue(HeaderNames.ContentRange, out var contentRangeValues) ||
!ContentRangeHeaderValue.TryParse(contentRangeValues.First(), out var contentRange) ||
!contentRange.HasRange)
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
namespace API.Services
{
public class ProcessIssuersJobSetupWithoutCron : IConfigureOptions<QuartzOptions>
{
public void Configure(QuartzOptions options)
{
var processIssuersJobKey = JobKey.Create("ProcessIssuersJob");
options
.AddJob<ProcessIssuersJob>(jobBuilder => jobBuilder.WithIdentity(processIssuersJobKey))
.AddTrigger(trigger =>
trigger
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie("OktaCookies", options =>
{
options.LoginPath = new PathString("/Account/SignIn");
options.Cookie.Name = "OktaCookies";
})
.AddCookie("EntraCookies", options =>
services.AddAuthentication()
.AddMicrosoftAccount(options =>
{
IConfigurationSection microsoftAuthNSection = configuration.GetSection("Authentication:Microsoft");
options.ClientId = microsoftAuthNSection["ClientId"];
options.ClientSecret = microsoftAuthNSection["ClientSecret"];
options.CallbackPath = new PathString("/Identity/Account/MicrosoftExternalAccountCallBack");
options.AccessDeniedPath = new PathString("/Identity/Account/Login");
options.SaveTokens = true;
using Microsoft.AspNetCore.SignalR;
namespace SignalRTest
{
public class MyHub : Hub
{
// This dictionary could map user connections to active timers if needed for multiple users
private static readonly Dictionary<string, CancellationTokenSource> UserTimers = new Dictionary<string, CancellationTokenSource>();
private static readonly object UserTimersLock = new object();
@code {
[Inject]
private IJSRuntime JSRuntime { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
foreach (var anData in ListOfMyData)
{
RemoteEndpointMessageProperty remoteEndpoint = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
if (remoteEndpoint != null)
{
string clientIPAddress = remoteEndpoint.Address;
int clientPort = remoteEndpoint.Port;
}
else
{
Console.WriteLine("Can't get info from remote endpoint");