本文介绍了Windows Azure Active Directory身份验证后如何获取访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经使用URL 。在这里,我们可以在上对用户进行身份验证,然后返回网站,但我们无法在成功通过身份验证后获取访问令牌。以下代码,通过它们我们可以在成功认证后访问用户名,姓氏等,但不能访问令牌。
能否提供身份验证后通过其获得访问令牌的代码。

we have successfully implemented the active directory authentication using the process given at the url http://msdn.microsoft.com/en-us/library/windowsazure/dn151790.aspx . Here we are able to authenticate the user on the https://login.microsoftonline.com/ and return back to web site but we are not able to get access token after successful authentication. following code through which we are able to access the user name, surname etc after successful authentication but not the access token.can you provide me the code through which we can get the access token after authentication.

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

        }
}


推荐答案

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

You can use this code to access the security token that was used:

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

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

You also need to set the saveBootstrapContext attribute in your config file:

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

这篇关于Windows Azure Active Directory身份验证后如何获取访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:19