public async Task <IActionResult> Index()
        {
            StartAppModel model = new StartAppModel();

            model.TestApps = await GetAppsList();

            Application app = await _applicationRepository.FindOne("", "");

            model.TestUsers = await GetTestUsersForList();

            model.AppPath            = _localPlatformSettings.AppRepsitoryBasePath;
            model.StaticTestDataPath = _localPlatformSettings.LocalTestingStaticTestDataPath;

            if (!model.TestApps.Any())
            {
                model.InvalidAppPath = true;
            }

            if (!model.TestUsers.Any())
            {
                model.InvalidTestDataPath = true;
            }

            if (app != null)
            {
                model.Org = app.Org;
                model.App = app.Id.Split("/")[1];
            }

            return(View(model));
        }
        public async Task <ActionResult> LogInTestUser(StartAppModel startAppModel)
        {
            UserProfile profile = await _userProfileService.GetUser(startAppModel.UserId);

            List <Claim> claims = new List <Claim>();
            string       issuer = "altinn3local.no";

            claims.Add(new Claim(ClaimTypes.NameIdentifier, profile.UserId.ToString(), ClaimValueTypes.String, issuer));
            claims.Add(new Claim(AltinnCoreClaimTypes.UserId, profile.UserId.ToString(), ClaimValueTypes.String, issuer));
            claims.Add(new Claim(AltinnCoreClaimTypes.UserName, profile.UserName, ClaimValueTypes.String, issuer));
            claims.Add(new Claim(AltinnCoreClaimTypes.PartyID, profile.PartyId.ToString(), ClaimValueTypes.Integer32, issuer));
            claims.Add(new Claim(AltinnCoreClaimTypes.AuthenticationLevel, "2", ClaimValueTypes.Integer32, issuer));

            ClaimsIdentity identity = new ClaimsIdentity(_generalSettings.GetClaimsIdentity);

            identity.AddClaims(claims);
            ClaimsPrincipal principal = new ClaimsPrincipal(identity);

            string token = _authenticationService.GenerateToken(principal, int.Parse(_generalSettings.GetJwtCookieValidityTime));

            CreateJwtCookieAndAppendToResponse(token);

            Application app = GetAppItem(startAppModel.AppPathSelection + "/config");

            _appSelectionService.SetAppPath(startAppModel.AppPathSelection);

            return(Redirect($"{_generalSettings.GetBaseUrl}/{app.Id}/"));
        }
Beispiel #3
0
        public async Task <ActionResult> LogInTestUser(StartAppModel startAppModel)
        {
            if (startAppModel.AuthenticationLevel != "-1")
            {
                UserProfile profile = await _userProfileService.GetUser(startAppModel.UserId);

                List <Claim> claims = new List <Claim>();
                string       issuer = _generalSettings.Hostname;
                claims.Add(new Claim(ClaimTypes.NameIdentifier, profile.UserId.ToString(), ClaimValueTypes.String, issuer));
                claims.Add(new Claim(AltinnCoreClaimTypes.UserId, profile.UserId.ToString(), ClaimValueTypes.String, issuer));
                claims.Add(new Claim(AltinnCoreClaimTypes.UserName, profile.UserName, ClaimValueTypes.String, issuer));
                claims.Add(new Claim(AltinnCoreClaimTypes.PartyID, profile.PartyId.ToString(), ClaimValueTypes.Integer32, issuer));
                claims.Add(new Claim(AltinnCoreClaimTypes.AuthenticationLevel, startAppModel.AuthenticationLevel, ClaimValueTypes.Integer32, issuer));

                ClaimsIdentity identity = new ClaimsIdentity(_generalSettings.GetClaimsIdentity);
                identity.AddClaims(claims);
                ClaimsPrincipal principal = new ClaimsPrincipal(identity);

                string token = _authenticationService.GenerateToken(principal, int.Parse(_generalSettings.GetJwtCookieValidityTime));
                CreateJwtCookieAndAppendToResponse(token);
            }

            Application app = await _localApp.GetApplicationMetadata(startAppModel.AppPathSelection);

            // Ensure that the documentstorage in LocalTestingStorageBasePath is updated with the most recent app data
            await _applicationRepository.Update(app);

            return(Redirect($"{_generalSettings.GetBaseUrl}/{app.Id}/"));
        }
Beispiel #4
0
        public async Task <IActionResult> Index()
        {
            StartAppModel model = new StartAppModel();

            try
            {
                model.TestApps = await GetAppsList();
            }
            catch (HttpRequestException e)
            {
                model.HttpException = e;
            }

            model.TestUsers = await GetTestUsersForList();

            model.AppPath            = _localPlatformSettings.AppRepositoryBasePath;
            model.StaticTestDataPath = _localPlatformSettings.LocalTestingStaticTestDataPath;
            model.LocalAppUrl        = _localPlatformSettings.LocalAppUrl;
            var defaultAuthLevel = _localPlatformSettings.LocalAppMode == "http" ? await GetAppAuthLevel(model.TestApps) : 2;

            model.AuthenticationLevels = GetAuthenticationLevels(defaultAuthLevel);

            if (!model.TestApps?.Any() ?? true)
            {
                model.InvalidAppPath = true;
            }

            if (!model.TestUsers?.Any() ?? true)
            {
                model.InvalidTestDataPath = true;
            }

            return(View(model));
        }
        public async Task <ActionResult> LogInTestUser(StartAppModel startAppModel)
        {
            UserProfile profile = await _userProfileService.GetUser(startAppModel.UserId);


            List <Claim> claims = new List <Claim>();
            string       issuer = "altinn3local.no";

            claims.Add(new Claim(AltinnCoreClaimTypes.UserId, profile.UserId.ToString(), ClaimValueTypes.String, issuer));
            claims.Add(new Claim(AltinnCoreClaimTypes.UserName, profile.UserName, ClaimValueTypes.String, issuer));
            claims.Add(new Claim(AltinnCoreClaimTypes.PartyID, profile.PartyId.ToString(), ClaimValueTypes.Integer32, issuer));
            claims.Add(new Claim(AltinnCoreClaimTypes.AuthenticationLevel, "2", ClaimValueTypes.Integer32, issuer));

            ClaimsIdentity identity = new ClaimsIdentity(_generalSettings.GetClaimsIdentity);

            identity.AddClaims(claims);
            ClaimsPrincipal principal = new ClaimsPrincipal(identity);

            DateTime later = DateTime.UtcNow.AddMinutes(int.Parse(_generalSettings.GetJwtCookieValidityTime));

            await HttpContext.SignInAsync(
                JwtCookieDefaults.AuthenticationScheme,
                principal,
                new AuthenticationProperties
            {
                ExpiresUtc   = later,
                IsPersistent = false,
                AllowRefresh = false,
            });

            Application app = this._applicationRepository.FindOne("", "").Result;

            return(Redirect($"{_generalSettings.GetBaseUrl}/{app.Org}/{app.Id.Split("/")[1]}"));
        }