コード例 #1
0
            public async Task <UserDto> Handle(Command request, CancellationToken cancellationToken)
            {
                var user = await userManager.FindByIdAsync(userAccessor.GetCurrentUserId());

                if (user == null)
                {
                    return(null);
                }

                var role = await roleAccessor.GetUserRoleAsync(user);

                var tokenBytes   = WebEncoders.Base64UrlDecode(request.RefreshToken);
                var decodedToken = Encoding.UTF8.GetString(tokenBytes);
                var result       = await userAccessor.ConfirmRefreshTokenAsync(user, userManager, decodedToken);

                if (!result.Succeeded)
                {
                    throw new RestException(HttpStatusCode.Unauthorized);
                }

                var newRefreshToken = await userManager.GenerateUserTokenAsync(user, TokenOptions.DefaultProvider, "RefreshToken");

                return(new UserDto(user, role, tokenGenerator, newRefreshToken));
            }