2

URL http://msdn.microsoft.com/en-us/library/windowsazure/dn151790.aspxで指定されたプロセスを使用して、Active Directory 認証を正常に実装しました。ここでは、https://login.microsoftonline.com/でユーザーを認証して Web サイトに戻ることができますが、認証が成功した後にアクセス トークンを取得できません。次のコードを使用すると、認証が成功した後にユーザー名、姓などにアクセスできますが、アクセストークンにはアクセスできません。認証後にアクセス トークンを取得できるコードを教えてください。

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

        }
}
4

1 に答える 1

3

このコードを使用して、使用されたセキュリティ トークンにアクセスできます。

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>
于 2013-09-04T08:06:19.727 に答える