我们已经使用 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/