Exemplo n.º 1
0
        public Task AuthCodeReceived(AuthorizationCodeReceivedNotification notification)
        {
            var oid       = Guid.Parse(notification.JwtSecurityToken.Claims.Single(c => c.Type == "oid").Value);
            var tid       = Guid.Parse(notification.JwtSecurityToken.Claims.Single(c => c.Type == "tid").Value);
            var firstname = notification.JwtSecurityToken.Claims.Single(c => c.Type == "name").Value;

            var context = new DashDocsContext();

            var customer = context.Customers.SingleOrDefault(c => c.Id == tid);

            if (customer != null)
            {
                var user = context.Users.SingleOrDefault(u => u.Id == oid && u.CustomerId == tid);
                if (user == null)
                {
                    // new user first sign-in
                    user = new User
                    {
                        Id         = oid,
                        CustomerId = tid,
                        FirstName  = firstname
                    };

                    context.Users.Add(user);
                    context.SaveChanges();
                }

                // though the application can access the claims from the returned
                // JWTToken, it's better to have custom claim properties as this eases up the usage.
                var applicationClaims = new AppClaims
                {
                    CustomerId   = tid,
                    CustomerName = customer.Name,
                    UserId       = oid,
                    DisplayName  = user.FirstName + user.LastName
                };

                var claim = new Claim("ddcs", JsonConvert.SerializeObject(applicationClaims));
                notification.AuthenticationTicket.Identity.AddClaim(claim);

                var tableStorageService = new TableStorageService();
                tableStorageService.CreateLog(tid, oid, notification.Request.RemoteIpAddress, true, null);
            }
            else
            {
                throw new UserLoggedInWithoutExistingCustomerException()
                      {
                          TenantId  = tid,
                          UserId    = oid,
                          FirstName = firstname
                      };
            }
            return(Task.FromResult(0));
        }
Exemplo n.º 2
0
        public ActionResult AddAppClaim(AppClaims app)
        {
            var apoList = HttpContext.Session.GetObjectFromJson <List <AppClaims> >("app");

            if (apoList != null)
            {
                apoList.Add(app);
                HttpContext.Session.SetObjectAsJson("app", apoList);
            }
            else
            {
                List <AppClaims> aplicationList = new List <AppClaims>();
                aplicationList.Add(app);
                HttpContext.Session.SetObjectAsJson("app", aplicationList);
            }

            //return Json(ServiceResponse.GetSuccessfulResponse());
            return(Json(new { responseCode = 0 }));
        }