LTI and Moodle

How to write an authentication for an external tool (LTI tool provider side) ?