带有ADAL库的Azure Active Directory注销

编程入门 行业动态 更新时间:2024-10-18 05:58:59
本文介绍了带有ADAL库的Azure Active Directory注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用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注销

本文发布于:2023-11-15 05:38:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1591619.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Azure   ADAL   Directory   Active

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!