Each WeBWorK course is integrated into a Moodle course as an "External tool". This means that the WeBWorK site can receive user course logins seamlessly and securely from Moodle users, and can automatically send back grade data to a related Moodle course. The connection that enables this seamless integration is called "Learning Tools Interoperability" (LTI).
Here's a brief video describing how the LTI connection works:
As you can see from the video:
Moodle Students are logged into their WeBWork course automatically when they click the "External Activity" link in their Moodle course
WeBWorK automatically publishes each Student's grades back to the Gradebook in their Moodle course
Related Resources:
About Moodle "External Tool" activity: https://docs.moodle.org/en/External_tool
A detailed description of how Moodle and WeBWorK connect: https://webwork.maa.org/wiki/Instructor_tips_for_Moodle-WW_Assignment_module