From the course: Microsoft Graph for Developers
Adding sign out logic
- [Instructor] With the token cache in place, now let's focus on the sign out logic. For that let's head back to MainWindow.xaml.cs, and let's go down to the signInButton_Click. Now I'm going to reuse the same button for both sign in and sign out, and how am I going to differentiate whether or not you're signed in or signed out? Well, this text on line 56 that we have set will help us out. So let's go ahead and use that. so basically the user clicks the sign in button, and you say if signInButton.Context.ToString is sign out, be careful, this has to be case specific. So basically this means that the user is signed in. And how do we sign out? Well, it's actually pretty easy, we just need to clear the tokens, authContext.TokenCache.Clear, and let's go ahead and set the text of the sign in button to sign in. Now I wish this was enough, but it isn't, because there's one problem here, the hosted browser windows may have stored some cookies. So, in addition to doing a TokenCache.Clear, I also need to ClearCookies, and how do we clear browser cookies? Unfortunately in Darknet there's no easy way to do that, so we use P invoke, platform invoke, to do that. So down here I'm going to add a helper method to clear cookies, and basically we are simply using wininet.ddl, an exported method of it, and ClearCookies is simply calling that method. There's is a very good site I like called pinvoke.net that makes these P invoke calls fairly easy. I'd encourage you to check that out. That is where I grabbed this code from as well. And this completes my sign out code. Now it's time to actually call the service.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Scenario3m 29s
-
Protocol flow3m 37s
-
Demo description2m 35s
-
Creating a WPF app and adding nuGet packages2m 32s
-
Registering the native app1m 31s
-
Adding sign in logic5m 6s
-
Managing tokens3m 59s
-
Adding sign out logic2m 16s
-
Calling Microsoft Graph from a native app2m 46s
-
Demonstrate the application running1m 13s
-
-
-
-
-