SharePoint lifehacks: create SharePoint app registration with client secret which never expires

IMPORTANT: According to the comments, this method doesn't work in all cases. For example, you cannot provide 'App Domain' value to be used inside SharePoint provider-hosted addin. If you need it only for some background jobs (which use app-only authentication), then you still can use below method. 

I bet you know about a page in SharePoint with address AppRegNew.aspx. You use this page to create a new app registration, generate ClientId and ClientSecret. One important thing about ClientSecret generated with AppRegNew.aspx is that secret has expiration time. By default expiration is 1 year. You can easily replace it afterwards, there is an article out there - Replace an expiring client secret in a SharePoint Add-in. You can even generate a new one with maximum of three years of expiration. Sometimes it’s inconvenient, especially if you have to manage multiple SharePoint apps with different expirations. Do you know, that you can generate a secret, which never expires? Well, technically almost never, but 300 years is pretty good, isn’t it? My ex-college found a way to do that, read further to find out how. More...