Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task <ActionResult> GetTestUserToken(int id)
        {
            UserProfile profile = await _userProfileService.GetUser(id);

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

            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));
            // Create a test token with long duration
            string token = jwtHandler.GenerateToken(principal, new TimeSpan(0, Convert.ToInt32(1337), 0)).Result;

            return(Ok(token));
        }
Exemplo n.º 2
0
        public ActionResult RefreshJWTCookie()
        {
            logger.LogInformation($"Starting to refresh token...");
            ClaimsPrincipal principal = HttpContext.User;

            logger.LogInformation("Refreshing token....");

            string token = jwtHandler.GenerateToken(principal, new TimeSpan(0, Convert.ToInt32(generalSettings.GetJwtCookieValidityTime), 0));

            logger.LogInformation($"End of refreshing token");
            return(Ok(token));
        }