To describe this, it is best to step through the key parts of the code.
The first part was clicking on save on the ODataClient.tt file. This created the class by reading the URL we entered in the metadataDocumentURI variable. When the file is saved, it triggers the generation of code using metadata from Dynamics 365 for Operations. If you click on Save, and then cancel the security warning, the ODataClient.cs file will be emptied.
Within the code we wrote, the first key part is the authentication, which works by authenticating with Azure AD and fetching an authentication, which is used with each submission request. The authorization code was determined in the GetAuthorization method.
The log on URI is always https://login.windows.net/ ...