Skip to content

Instantly share code, notes, and snippets.

@runceel
Created December 20, 2018 07:02
Show Gist options
  • Save runceel/03baa3dbf8ecf804ce6377b9af36d4cd to your computer and use it in GitHub Desktop.
Save runceel/03baa3dbf8ecf804ce6377b9af36d4cd to your computer and use it in GitHub Desktop.
using Microsoft.Identity.Client;
using System.Diagnostics;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace MSGraphAPISampleApp
{
public sealed partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
}
private async void SignInButton_Click(object sender, RoutedEventArgs e)
{
var account = (await App.PublicClientApplication.GetAccountsAsync())?.FirstOrDefault();
try
{
AuthenticationResult authResult;
if (account == null)
{
authResult = await App.PublicClientApplication.AcquireTokenAsync(Consts.Scopes);
}
else
{
authResult = await App.PublicClientApplication.AcquireTokenSilentAsync(Consts.Scopes, account);
}
Debug.WriteLine(authResult.AccessToken);
}
catch (MsalClientException ex)
{
Debug.WriteLine(ex);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment