Reputation: 2922
I have built a small UWP app in C# that contains Azure AD authentication (to our corporate Azure AD account) based off the sample found here - https://github.com/Azure-Samples/active-directory-dotnet-native-uwp-wam/tree/master/NativeClient-UWP-WAM
I have the sample working successfully in my app, but I can't find a way to detect that a user is or isn't signed in (after the sign in is complete). I want to use this to ensure users can't navigate to other pages in the UWP app without being authenticated. If I was doing this in ASP.NET I would check something like the Context.Identity.User object. I just want to be able to do (in pseudo code)
Navigate to Page 1 if user signedIn = true, show page. If false, error/fail.
I've looked up user state, signed in state etc, but nothing really shows up.
Upvotes: 1
Views: 540
Reputation: 7728
Then try:
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
IReadOnlyList<User> users = await User.FindAllAsync();
var current = users.Where(p => p.AuthenticationStatus ==
UserAuthenticationStatus.LocallyAuthenticated &&
p.Type == UserType.LocalUser).FirstOrDefault();
// user may have username
var data = await current.GetPropertyAsync(KnownUserProperties.AccountName);
string displayName = (string)data;
text1.Text = displayName;
}
https://learn.microsoft.com/en-us/uwp/api/Windows.System.User
Upvotes: 1