In this video, see how to get and renew access tokens, and make calls to Microsoft Graph.
- [Instructor] With the sign in, sign out out of our way, let's start writing the code to actually call the service. Now I hope you may have guessed by now what it's going to go in this method. It's a matter of getting the access token, and making a REST call. Except, this time we'll do it in C#. So, step number one. Well, if the result, the off result is null, that means the user hasn't signed in yet, so, you first need to sign in. So that's the first thing we need to do. Next, we need to acquire the access token.
How do we do that? Well, we say result is equal to await authContext.AcquireTokenSilentAsync. Now, why silent? Because we don't want to prompt the user for another authentication prompt. So, the user has already signed in at this point, so we are getting the access token silently, but then you may say, "whoo, "why do we even need to get the token?" because the token could've expired by now, so you want to make sure that if there is a refreshed token in play, that you renew the token silently, and get the access token, or just return the access token, as usual ADAL will simplify all this for us.
And with these headers now, I can make an http call. So let's go do that. So, as usual, we're simply making an http call to this URL or if you wanted to make a call to a different Microsoft Graph URL, easy, just change this URL, set the permissions in Azure AD, and you can make those calls, not a problem. And then we get the results, and the results we simply write them out as a string, and we set them up in serviceResult.Text.
And if you remember, serviceResult was that big text box that we placed in our user interface. Simple as that. Now to get rid of this red squiggly lines I need to put async up here. Great. And now at this point my project is done, and let's make sure that it builds. Great, it builds, we're ready to run it.
- What is Microsoft Graph?
- Registering a web application in Azure AD
- Adding authentication logic and authentication UI
- Native applications calling Graph
- Reviewing scenarios where web apps involving Graph are useful
- Web applications with application identity and delegated identity calling Graph
- Daemons calling Graph