Beispiel #1
0
        private UserResponseModel GenerateJwtToken
            (string email, IdentityUser user, IList <string> roles)
        {
            var dbUser   = _userRepository.GetUserByEmail(email, "app", _applicationSetting.CreateConnectionString());
            var authUser = _userRepository.GetAuthUserIdByEmail(email, _applicationSetting.AuthConnectionString());

            if (string.IsNullOrEmpty(authUser))
            {
                throw new Exception("The user does not exist.");
            }
            var instanceId = $"A_{authUser}".Replace("-", "_");
            //if (dbUser != null) instanceId = dbUser.InstanceId;
            var name    = dbUser == null ? email : dbUser.FullName;
            var picture = (dbUser == null ? "default" : dbUser.ProfilePicture) ?? "default";

            var claims = _minutzClaimManager.CreateClaims(email, picture, name, roles, instanceId, user.Id);

            var tokenStringResult = _minutzJwtSecurityTokenManager.JwtSecurityToken
                                        (_applicationSetting.ClientSecret, _applicationSetting.AuthorityDomain, claims);

            var userModel = new UserResponseModel
            {
                access_token = tokenStringResult.token,
                expires_in   = tokenStringResult.expires.ToString(CultureInfo.CurrentCulture),
                id_token     = tokenStringResult.token,
                scope        = string.Join(",", roles),
                token_type   = "aspnet"
            };

            return(userModel);
        }