This is a very simple example to use TOTP as a means of API Authentication.
This is an example of generating a TOTPsecret and validating the TOTP code.
If you want to generate a TOTP, refer this project
The example is based on Java-TOTP by samdjstevens