Skip to content

Instantly share code, notes, and snippets.

View kvonkoni's full-sized avatar

Kier von Konigslow kvonkoni

View GitHub Profile
@kvonkoni
kvonkoni / SamlDesktopIntegration.SendCookiesWithAllRequests.cs
Created February 7, 2021 00:23
The C# code for setting the client's default headers using a cookie container
myHttpClient.DefaultRequestHeaders.Add(
"Cookie",
myCookieContainer.GetCookieHeader(myRequestUri));
@kvonkoni
kvonkoni / SamlDesktopIntegration.SendWithCookieHeaders.cs
Created February 7, 2021 00:16
The C# code for sending an HTTP request with WebView2 cookies
// Moving the WebView2 cookies to a cookie container for periodic consumption.
var myCookieContainer = ConvertCookiesToContainer(webView2Cookies);
// Setting the request's URI and creating a GET request message.
var myRequestUri = new Uri("https://my.service.com/path/to/endpoint")
var myMessage = new HttpRequestMessage(HttpMethod.Get, myRequestUri);
// Adding the cookie container's cookie header to the message's header.
myMessage.Headers.Add("Cookie", myCookieContainer.GetCookieHeader(myRequestUri));
@kvonkoni
kvonkoni / SamlDesktopIntegration.ConvertCookiesToContainer.cs
Last active February 7, 2021 00:17
The C# code for converting a list of WebView2 cookies to a CookieContainer
public static CookieContainer ConvertCookiesToContainer(IEnumerable<WebView2Cookie> webView2Cookies)
{
var cookies = new CookieContainer();
foreach (var cookie in WebView2Cookies)
{
cookies.Add(new Cookie
{
Domain = cookie.Domain,
Path = cookie.Path,
@kvonkoni
kvonkoni / SamlDesktopIntegration.LoginViewModel.cs
Last active February 7, 2021 00:11
The C# code for my LoginViewModel
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Caliburn.Micro;
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.Wpf;
namespace MyDesktopApp
{
public class LoginViewModel : Screen
@kvonkoni
kvonkoni / SamlDesktopIntegration.LoginView.xaml
Last active February 7, 2021 00:42
The XAML code for my LoginView
<UserControl x:Class="MyDesktopApp.LoginView"
...
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
xmlns:cal="http://www.caliburnproject.org">
<Grid>
<wv2:WebView2 x:Name="WebView"
cal:Message.Attach="[Event NavigationCompleted] = [Action OnNavigationCompletedAsync($source)]"
Source="{Binding WebAddress}" />
</Grid>
</UserControl>