我使用Azure Active Directory保护了我的Web API,并在Azure管理门户中创建了本机应用程序.这个本地应用程序基本上是MVC Web应用程序,我使用ADAL库获取令牌并使用该令牌调用api.我用来获取令牌的代码如下所示:
I used the my Azure Active Directory to protect my web API and I create a native application in the Azure management portal. This native application is basically a 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;现在,我需要注销并切换到另一个用户,但是系统会以某种方式记住用户凭据.我在身份验证上下文中清除令牌缓存,并按以下方式发布注销api请求,其中***是我的租户ID.
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 where *** is my tenant ID.
//Log out after api call ac.TokenCache.Clear(); string requestUrl = "login.windows/***/oauth2/logout"; var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, requestUrl); var response = await client.SendAsync(request);api调用成功,但注销不起作用.我应该怎么做才能注销并切换到另一个用户?
The api call succeeds but the logout doesn't work. What should I do to logout and switch to another user?
推荐答案我认为这行不通.您需要将用户重定向到注销URL才能注销.
I don't think this would work. You would need to redirect the user to logout URL for logout to work.
以下是创建注销URI的方法:
Here's how you can create a logout URI:
login.microsoftonline/{0}/oauth2/logout?post_logout_redirect_uri = {1}
位置:
- {0} -Azure Active Directory的全限定名称,例如yourad.onmicrosoft或租户ID.
- {1} -注销后必须将用户重定向到的应用程序URL.这应该经过正确的URL编码.
- {0} - Fully qualified name of your Azure Active Directory e.g. yourad.onmicrosoft or tenant id.
- {1} - The URL of your application where a user must be redirected back after the logout is complete. This should be properly URL encoded.
更多推荐
带有ADAL库的Azure Active Directory注销
发布评论