Created
December 20, 2018 07:02
-
-
Save runceel/03baa3dbf8ecf804ce6377b9af36d4cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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