Ejemplo n.º 1
0
        //private async Task OnAuthorizationCodeRecieved(AuthorizationCodeReceivedNotification context)
        //{
        //    Upon successful sign in, get & cache a token using MSAL
        //    string userId = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
        //    Microsoft.Identity.Client.TokenCache userTokenCache = new MsalSessionTokenCache(userId, context.OwinContext.Environment["System.Web.HttpContextBase"] as HttpContextBase).GetMsalCacheInstance();
        //    ConfidentialClientApplication cc = new ConfidentialClientApplication(ClientId, RedirectUri, new Microsoft.Identity.Client.ClientCredential(ClientSecret), userTokenCache, null);
        //    Microsoft.Identity.Client.AuthenticationResult result = await cc.AcquireTokenByAuthorizationCodeAsync(context.Code, new[] { "user.readbasic.all" });
        //}

        public ActionResult Index()
        {
            if (HttpContext.User == null || !HttpContext.User.Identity.IsAuthenticated)
            {
                HttpContext.GetOwinContext().Authentication.Challenge(
                    new AuthenticationProperties {
                    RedirectUri = "/"
                },
                    OpenIdConnectAuthenticationDefaults.AuthenticationType);

                return(View());
            }
            else
            {
                string strEmail = HttpContext.User.Identity.Name;
                //var r= AddADAccountClick(strEmail);
                //Session["Email"] = strEmail;
                var r = Utility.AddADAccountClick(strEmail);
                ViewBag.TenantId = r;


                List <oMenuAccess> authobj = null;
                ViewData["email"] = r.value[0].userPrincipalName;
                HttpCookie mailCookie = new HttpCookie("AUTH_PTEmail");
                mailCookie.Value   = r.value[0].userPrincipalName;
                mailCookie.Expires = DateTime.Now.AddDays(1d);
                Response.Cookies.Add(mailCookie);

                HttpCookie mailCookies = new HttpCookie("AUTHADMIN");

                mailCookies.Value = "";

                if (CheckIsAdminUser(r.value[0].userPrincipalName))
                {
                    mailCookies.Value = "Admin";
                }

                mailCookies.Expires = DateTime.Now.AddDays(1d);
                Response.Cookies.Add(mailCookies);

                //if (r.value[0].userPrincipalName.ToLower() != "*****@*****.**")
                if (mailCookies.Value != "Admin")
                {
                    authobj = Utility.getRoleAccessbyEmailID(r.value[0].userPrincipalName);

                    if (authobj != null)
                    {
                        return(View(authobj));
                    }
                    else
                    {
                        return(RedirectToAction("UnAuthorized"));
                    }
                }
                else
                {
                    return(View());
                }
            }
        }
Ejemplo n.º 2
0
        public JsonResult GetEmailIdFromName(string searchtext)
        {
            UserResponse res = null;

            try
            {
                //res = AddADAccountClick(searchtext);

                res = Utility.AddADAccountClick(searchtext);
                ViewBag.TenantId = res;

                return(Json(JsonConvert.SerializeObject(res), JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                JsonExceptionResult jsonexc = new JsonExceptionResult();
                return(Json(JsonConvert.SerializeObject(new CABPTException(ex, out jsonexc))));
            }
        }