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 #2
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}/"));
        }
        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]}"));
        }
Beispiel #4
0
        public async Task <ActionResult> Get(int userID)
        {
            UserProfile result = await _userProfilesWrapper.GetUser(userID);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
Beispiel #5
0
        /// <inheritdoc/>
        public async Task <UserProfile> GetUser(int userId)
        {
            string uniqueCacheKey = "User_UserId_" + userId;

            if (_memoryCache.TryGetValue(uniqueCacheKey, out UserProfile user))
            {
                return(user);
            }

            user = await _decoratedService.GetUser(userId);

            if (user != null)
            {
                _memoryCache.Set(uniqueCacheKey, user, _cacheOptions);
            }

            return(user);
        }