azure - 如何在 Windows Azure Active Directory 身份验证后获取访问 token

标签 azure active-directory azure-active-directory

我们已经使用 url http://msdn.microsoft.com/en-us/library/windowsazure/dn151790.aspx 中给出的流程成功实现了事件目录身份验证。 。在这里,我们可以对 https://login.microsoftonline.com/ 上的用户进行身份验证并返回网站,但身份验证成功后我们无法获取访问 token 。通过以下代码,我们可以在成功身份验证后访问用户名、姓氏等,但不能访问访问 token 。 您能否向我提供代码,我们可以通过该代码在身份验证后获取访问 token 。

 public class HomeController : Controller
    {
        public ActionResult Index()
        {

            ClaimsPrincipal cp = ClaimsPrincipal.Current;
            string fullname =
                   string.Format("{0} {1}", cp.FindFirst(ClaimTypes.GivenName).Value,
                   cp.FindFirst(ClaimTypes.Surname).Value);
            ViewBag.Message = string.Format("Dear {0}, welcome to the Expense Note App",
                              fullname);                              

            return View();

        }
}

最佳答案

您可以使用此代码来访问所使用的安全 token :

ClaimsPrincipal cp = ClaimsPrincipal.Current;
ClaimsIdentity ci = cp.Identity as ClaimsIdentity;
BootstrapContext bc = ci.BootstrapContext as BootstrapContext;
SecurityToken securityToken = bc.SecurityToken;

您还需要在配置文件中设置saveBootstrapContext属性:

<system.identityModel>
    <identityConfiguration saveBootstrapContext="true">
    ...
</system.identityModel>

关于azure - 如何在 Windows Azure Active Directory 身份验证后获取访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18437173/

相关文章:

azure - 通过 KQL 在共享仪表板中使用过滤

active-directory - 使用 Microsoft Active Directory 进行群体 LDAP 配置

c# - Azure AD - 将所有用户基本信息提取到列表中

azure - 将 Azure Web App 上的 Azure Active Directory 与 Meteor 结合使用

azure - 我们无法识别此租户 ID 21f3be0a-713c-4b7f-ab75-3cc5ca25846。请仔细检查租户 ID,然后重试。",

typescript - Azure DevOps REST API 获取工作项未返回所有可用字段

Azure函数: Force HTTPS

c# - WebJob 极大地减慢了我的网站速度

c# - DirectoryServices.DirectoryEntry 组调用 ("remove") 和属性 ["member"].remove 之间的差异

c# - 使用c#查找AD中所有被锁定的用户