Skip to content

Instantly share code, notes, and snippets.

@joewashington75
joewashington75 / PlaywrightAzureAdBasicAuth.cs
Created February 22, 2022 13:44
Basic Authentication automation using Playwright
using Cocona;
using Microsoft.Playwright;
using PlaywightAzureAdBasicAuth;
var builder = CoconaApp.CreateBuilder();
var app = builder.Build();
app.AddCommand(async ([Argument(Description = "Username to login with")] string userName,
[Argument(Description = "Password to login with")] string password,
[Argument(Description = "The url of your application as a starting point where your login button is located")] string applicationUrl,
@joewashington75
joewashington75 / SeleniumAzureAdAuth.cs
Created February 22, 2022 13:21
Basic Authentication using Selenium
public static IWebDriver AzureAdRedirectWithAuthDetails(this IWebDriver driver, string userName, string password, string domainToReplace)
{
Thread.Sleep(TimeSpan.FromSeconds(5));
var newUrlWithUserCredentials = driver.Url.Replace(domainToReplace, $"{WebUtility.HtmlEncode(userName)}:{password}@{domainToReplace}");
driver.Navigate().GoToUrl(newUrlWithUserCredentials);
return driver;
}
@joewashington75
joewashington75 / apim-to-azure-service-bus-on-api-error.xml
Created July 13, 2021 15:17
APIM send message to Azure Service Bus when backend API is down
<policies>
<inbound>
<base />
<set-backend-service base-url="https://yourapihere.com" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<choose>
@joewashington75
joewashington75 / apim-to-azure-service-bus-policy.xml
Created July 13, 2021 14:53
Writing to Azure Service Bus using APIM Policy
<!--
IMPORTANT:
- Policy elements can appear only within the <inbound>, <outbound>, <backend> section elements.
- To apply a policy to the incoming request (before it is forwarded to the backend service), place a corresponding policy element within the <inbound> section element.
- To apply a policy to the outgoing response (before it is sent back to the caller), place a corresponding policy element within the <outbound> section element.
- To add a policy, place the cursor at the desired insertion point and select a policy from the sidebar.
- To remove a policy, delete the corresponding policy statement from the policy document.
- Position the <base> element within a section element to inherit all policies from the corresponding section element in the enclosing scope.
- Remove the <base> element to prevent inheriting policies from the corresponding section element in the enclosing scope.
- Policies are applied in the order of their appearance, from the top down.
@joewashington75
joewashington75 / shared-access-signature-token.ps1
Created July 13, 2021 14:29
Generating a shared access signature token using Powershell
$URI="https://{{service-bus-name-here}}.servicebus.windows.net/{{queue-name-here}}"
$Access_Policy_Name="{{access-policy-name-here}}"
$Access_Policy_Key="{{access-policy-key-here}}"
$Expires=([DateTimeOffset]::Now.ToUnixTimeSeconds())+7568640
$SignatureString=[System.Web.HttpUtility]::UrlEncode($URI)+ "`n" + [string]$Expires
$HMAC = New-Object System.Security.Cryptography.HMACSHA256
$HMAC.key = [Text.Encoding]::ASCII.GetBytes($Access_Policy_Key)
$Signature = $HMAC.ComputeHash([Text.Encoding]::ASCII.GetBytes($SignatureString))
$Signature = [Convert]::ToBase64String($Signature)
$SASToken = "SharedAccessSignature sr=" + [System.Web.HttpUtility]::UrlEncode($URI) + "&sig=" + [System.Web.HttpUtility]::UrlEncode($Signature) + "&se=" + $Expires + "&skn=" + $Access_Policy_Name
@joewashington75
joewashington75 / Program.cs
Created May 26, 2020 20:25
DbUp Program.cs
using DbUp;
using Microsoft.Extensions.Configuration;
using System;
using System.Linq;
using System.Reflection;
namespace DatabaseReleaseAutomation.DbUpDemo
{
class Program
{
{
"ConnectionStrings": {
"DbUpSqlConnectionString": "Server=127.0.0.1,1589;Database=sqldb-databasereleaseautomation;User Id=sa;Password=YourPassword123;"
}
}
using EFCoreSeparateProject.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using System.IO;
namespace EFCoreSeparateProject.Migrations
{
public class ExampleDbContextFactory : IDesignTimeDbContextFactory<ExampleDbContext>
{
{
"SqlConnectionString": "Server=127.0.0.1,5433;Database=EFCoreSeparateProjectDb;User Id=sa;Password=yourStrong(!)Password;"
}
using EFCoreSeparateProject.Core.Domain;
using EFCoreSeparateProject.Infrastructure.EntityConfigurations;
using Microsoft.EntityFrameworkCore;
namespace EFCoreSeparateProject.Infrastructure
{
public class ExampleDbContext : DbContext
{
public ExampleDbContext(DbContextOptions options) : base(options)
{