Esempio n. 1
0
        private async Task OnAuthorizationCodeReceived(AuthorizationCodeReceivedNotification notification)
        {
            // Get the user's object id (used to name the token cache)
            ClaimsPrincipal principal = new ClaimsPrincipal(notification.AuthenticationTicket.Identity);
            string          userObjId = AuthHelper.GetUserId(principal);

            // Create a token cache
            RuntimeTokenCache tokenCache = new RuntimeTokenCache(userObjId);

            // Exchange the auth code for a token
            AuthHelper authHelper = new AuthHelper(tokenCache);

            var response = await authHelper.GetTokensFromAuthority("authorization_code", notification.Code,
                                                                   notification.Request.Uri.ToString());
        }
Esempio n. 2
0
        public void SignOut()
        {
            if (Request.IsAuthenticated)
            {
                // Get the user's token cache and clear it
                string userObjId = AuthHelper.GetUserId(ClaimsPrincipal.Current);

                RuntimeTokenCache tokenCache = new RuntimeTokenCache(userObjId);
                tokenCache.Clear();
            }
            // Send an OpenID Connect sign-out request.
            HttpContext.GetOwinContext().Authentication.SignOut(
                CookieAuthenticationDefaults.AuthenticationType);
            Response.Redirect("/");
        }
Esempio n. 3
0
        public async Task <ActionResult> Graph()
        {
            string userObjId = AuthHelper.GetUserId(ClaimsPrincipal.Current);

            RuntimeTokenCache tokenCache = new RuntimeTokenCache(userObjId);

            AuthHelper authHelper = new AuthHelper(tokenCache);

            ViewBag.AccessToken = await authHelper.GetUserAccessToken(Url.Action("Index", "Home", null, Request.Url.Scheme));

            if (null == ViewBag.AccessToken)
            {
                return(new EmptyResult());
            }

            return(View());
        }
Esempio n. 4
0
 public AuthHelper(RuntimeTokenCache tokenCache)
 {
     TokenCache = tokenCache;
 }