繁体   English   中英

Windows Azure Active Directory身份验证后如何获取访问令牌

[英]how to get access token after windows azure active directory authentication

我们已经使用URL http://msdn.microsoft.com/zh-cn/library/windowsazure/dn151790.aspx上给出的过程成功地实现了活动目录身份验证。 在这里,我们能够在https://login.microsoftonline.com/上对用户进行身份验证,然后返回到网站,但是成功进行身份验证后,我们将无法获得访问令牌。 以下代码,通过它们我们可以在成功认证后访问用户名,姓氏等,但不能访问令牌。 您能否提供给我代码,以便我们在身份验证后通过该代码获得访问令牌。

 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();

        }
}

您可以使用以下代码访问所使用的安全令牌:

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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM