Skip to content

Instantly share code, notes, and snippets.

@DHowett
Created May 24, 2023 17:09
Show Gist options
  • Save DHowett/7e5c1187da7c33d85edb3da35d35c1c3 to your computer and use it in GitHub Desktop.
Save DHowett/7e5c1187da7c33d85edb3da35d35c1c3 to your computer and use it in GitHub Desktop.

Revisions

  1. DHowett created this gist May 24, 2023.
    13 changes: 13 additions & 0 deletions Program.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    using Windows.Security.Credentials;
    using WinRT;

    namespace CredentialCsWinRtTest {
    internal class Program {
    static void Main(string[] args) {
    Windows.Security.Credentials.WebAccount foo = null /* or somehow get it */;
    Windows.Security.Credentials.IWebAccount2 webAccount2 = foo.As<IWebAccount2>();
    // if webaccount2 is not null . . .
    webAccount2.SignOutAsync("clientId"); // do something with the async task actually
    }
    }
    }
    17 changes: 17 additions & 0 deletions foo.csproj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    <Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0-windows10.0.22000.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <!-- **** IMPORTANT 1 - Add the Windows.Security namespace to the list of generated projections -->
    <CsWinRtIncludes>Windows.Security</CsWinRtIncludes>
    </PropertyGroup>

    <ItemGroup>
    <!-- **** IMPORTANT 2 - This generates the projections -->
    <PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.2" />
    </ItemGroup>

    </Project>