![](/img/trans.png)
[英]Given Access Token, how can I get domain / name of 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.