I used my Azure Active Directory to protect my web API and create my own application in the Azure Management Portal. This native application is basically an MVC web application, and I use the ADAL library to get the token and call the api with that token. The code I used to get the token is shown below:
AuthenticationContext ac = new AuthenticationContext(authority); AuthenticationResult ar = ac.AcquireToken(resourceID, clientID, redirectURI); string accessToken = ar.AccessToken;
Now I need to go out and switch to another user, but somehow the user credentials are remembered by the system. I clear the cache token in the authentication context and send an api request to exit the system as follows, where *** is my tenant ID.
//Log out after api call ac.TokenCache.Clear(); string requestUrl = "https://login.windows.net/***/oauth2/logout"; var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, requestUrl); var response = await client.SendAsync(request);
The api code completed successfully, but logging out does not work. What to do to log out and switch to another user?
source share