Skip to content

Instantly share code, notes, and snippets.

@DHowett
Created May 24, 2023 17:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DHowett/7e5c1187da7c33d85edb3da35d35c1c3 to your computer and use it in GitHub Desktop.
Save DHowett/7e5c1187da7c33d85edb3da35d35c1c3 to your computer and use it in GitHub Desktop.
IWebAccount2 - C#/WinRT
<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>
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
}
}
}
@DHowett
Copy link
Author

DHowett commented May 24, 2023

It is probably important to set the TFM to include -windows10.0.xxxxx, where that number is one of the Windows SDKs you have installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment