简体   繁体   English

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

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

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 . 我们已经使用URL http://msdn.microsoft.com/zh-cn/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. 在这里,我们能够在https://login.microsoftonline.com/上对用户进行身份验证,然后返回到网站,但是成功进行身份验证后,我们将无法获得访问令牌。 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;

You also need to set the saveBootstrapContext attribute in your config file: 您还需要在配置文件中设置saveBootstrapContext属性:

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

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

相关问题 给定访问令牌,如何获取Windows Azure Active Directory的域名/名称 - Given Access Token, how can I get domain / name of Windows Azure Active Directory 如何在Angular2的Azure Active Directory中获取访问令牌 - How to get access token in azure Active directory in Angular2 Azure Active Directory 获取访问令牌 - Azure Active Directory get access token 如何挑战Windows Azure Active Directory身份验证? - How to challenge Windows Azure Active Directory authentication? Azure Active Directory和Windows身份验证 - Azure Active Directory and Windows Authentication Azure 活动目录 - 使用 Azure CLI 获取访问令牌 - Azure active directory - Get access token using Azure CLI 从Powershell获取Azure Active Directory访问令牌 - Get Azure Active Directory Access Token from Powershell 如何从 Azure Active Directory 获取我的 API 和 Microsoft Graph 的有效访问令牌? - How to Get a valid access token for my API and Microsoft Graph from Azure Active Directory? npm mssql是否支持认证类型azure-active-directory-access-token连接azure sql服务器 - Does npm mssql supports authentication type azure-active-directory-access-token to connect to azure sql server 如何使用 Azure Active Directory 在 Web 应用程序中刷新访问令牌 - How to refresh access token in web application using Azure Active Directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM