Skip to main content

OpenIdConnect through a proxy

1 min read

Having set up OpenIdConnect in a dotnet core project using services.AddOpenIdConnect the log in proces is kiked of in some method of the application via the call to the base controller Challenge(OpenIdConnectDefaults.AuthenticationScheme)

            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return Challenge(OpenIdConnectDefaults.AuthenticationScheme);
            }


Works fine in development. Fails in production because prod goes through a proxy.
How do you set that proxy?


Use the followng:

            .AddOpenIdConnect(options =>
            {
                if (environment != "DEV")             
  {                    var proxy = new WebProxy(proxyUrl); 
                  options.BackchannelHttpHandler = new HttpClientHandler() 
                  {                        Proxy = proxy                   
};               
}
options ......

Not documented ANYWHERE!

 

Sunday Bike run bike

1 min read

 

 

 Cycle to wooton roundabout and back 

 

Route map for Martins To Roundabout by Peter Marshall on plotaroute.com

 

Route map for V Short Run by Peter Marshall on plotaroute.com

Down hill and back up

Route map for Martins Down Hill And Back by Peter Marshall on plotaroute.com

Call Service Fabric endpoint internally

1 min read

        private async Task CallServiceAsync()
        {
            string schedulerServiceName = "fabric:/DataServices/Scheduler";
            var resolver = ServicePartitionResolver.GetDefault();
            var partition = await resolver.ResolveAsync(new Uri(schedulerServiceName), ServicePartitionKey.Singleton, CancellationToken.None);
            var endpoints = JObject.Parse(partition.GetEndpoint().Address)["Endpoints"];
            var endpoint = endpoints[""].ToString().TrimEnd('/');
            string method = "/api/scheduler/classes/sync";
            var client = new HttpClient();
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            var getTask = client.GetAsync(endpoint + method);
            var msg = await getTask;
        }

Call Service Fabric endpoint internally

1 min read

        private async Task CallServiceAsync()
        {
            string schedulerServiceName = "fabric:/DataServices/Scheduler";
            var resolver = ServicePartitionResolver.GetDefault();
            var partition = await resolver.ResolveAsync(new Uri(schedulerServiceName), ServicePartitionKey.Singleton, CancellationToken.None);
            var endpoints = JObject.Parse(partition.GetEndpoint().Address)["Endpoints"];
            var endpoint = endpoints[""].ToString().TrimEnd('/');
            string method = "/api/scheduler/classes/sync";
            var client = new HttpClient();
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            var getTask = client.GetAsync(endpoint + method);
            var msg = await getTask;
        }

Debug Jest tests in Visual Studio Code

1 min read

    {
      "type": "node",
      "request": "launch",
      "name": "Jest All",
      "program": "${workspaceFolder}/node_modules/.bin/jest",
      "args": ["--runInBand"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "windows": {
        "program": "${workspaceFolder}/node_modules/jest/bin/jest",
      }
    }

removing duplicates in sql server

1 min read

Find your duplicates

  SELECT    [col1], [col2], COUNT(*)
  FROM      [db].[mstar].[table1]
  GROUP BY  [col1], [col2]
  HAVING    COUNT(*) > 1
THEN
begin transaction
SET NOCOUNT ON
SET ROWCOUNT 1
while 1 = 1
 BEGIN
   DELETE  
   FROM [mstar].[InvalidFundShareClassAttribute]
   WHERE [FundShareClassId]+ [CustomState] IN
        (SELECT  [FundShareClassId]+ [CustomState]
         FROM    [mstar].[InvalidFundShareClassAttribute]
         GROUP BY [FundShareClassId]+ [CustomState]
         HAVING  COUNT(*) > 1)
      IF @@Rowcount = 0
      BREAK ;
end;
 SET ROWCOUNT 0
 rollback;
or commit;

 

There is another way

;WITH CTE AS 
(
    SELECT EmpName, ROW_NUMBER() OVER 
    (
        PARTITION BY EmpName ORDER BY EmpID
    ) RowNumber
    FROM  dbo.Employee
)
SELECT *FROM CTE WHERE RowNumber > 1
Then
;WITH CTE AS 
(
SELECT EmpName, ROW_NUMBER() OVER 
(
    PARTITION BY EmpName ORDER BY EmpID
) RowNumber
FROM  dbo.Employee
)
DELETE FROM CTE WHERE RowNumber > 1