Quantcast
Channel: All Developer posts
Viewing all articles
Browse latest Browse all 48104

How to logout from Active Directory that using api powerbi

$
0
0

Hi All

I developed a MVC web application and I use the api.powerbi.com to get the token and call the api with that token. I got clientId & clientSecret from https://dev.powerbi.com/apps .The piece of code I used to get the token is shown below:

string powerbiapiUrl = "https://analysis.windows.net/powerbi/api";
string authorityUri = "https://login.windows.net/common/oauth2/authorize/";
AuthenticationContext ac = new AuthenticationContext(authorityUri);
ClientCredential clientCredential = new ClientCredential(clientId,clientSecret); AuthenticationResult ar = authenticationResult = await authenticationContext.AcquireTokenByAuthorizationCodeAsync(code,new Uri(responseUri), clientCredential); string accessToken = ar.AccessToken;

Now I need to logout and switch to another user but somehow the user credentials are remembered by the system. I clear the token cache in the authentication context and post logout api request as follows.

//Log out after api call
ac.TokenCache.Clear();
string tenant_id = ar.TenantId;
string requestUrl = "https://login.windows.net/" + tenant_id + "/oauth2/logout";

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
var response = await client.SendAsync(request);

The api call succeeds but the logout doesn't work. If I clear my browser's cookies & cache it can prompt another userlogin, we can't destroy cookies/app that are not generated from our app right?

So how can I do to logout and switch to another user?

Thanks


Viewing all articles
Browse latest Browse all 48104

Trending Articles