Sometimes, instead of using username and password, we need an Sharepoint App registration to automate some scripts.
Here is an example how you can register SharePoint Application, grant permissions to application and in the end Remove the Application.
In this example I have used Global Admin permissions.
Registering an Application
First step is to Sign In to / Go to/ Navigate to SharePoint Admin Center.

Next thing is to follow this link to get to page where you will generate id, Client Secret and other data needed:
https://TENANTNAME.sharepoint.com/_layouts/15/appregnew.aspx
Link will guide you to this screen:

Generate Client Id, secret and enter any other needed information. After that – click on Create on right side of the page.
Next Page is really important as in this steps you need to save all data that is needed to use data in the future. For Example save it in some protected files.:

Confirm with Ok button and the app is now registered.
The Only problem is that this app does not have any permissions so at the moment it is useless.
Grant permissions to application
To grant permissions to newly created app follow this link:
https://TENANTNAME-admin.sharepoint.com/_layouts/15/appinv.aspx
On this site you can lookup app by Client Id:

After you lookup the app paste following into Permission Request XML box and click Create. This will grant Full Control to your app.
To Finish the process of granting permissions you need to Trust the App:

Remove the Application
To remove the Application follow this link:
https://TEANANTNAME-admin.sharepoint.com/_layouts/15/appprincipals.aspx?Scope=Web
Here you can find the Application and delete it.
Thank you for reading this article!
I hope I have helped you and that you made your work faster by help of this article 🙂