I'm not sure how you're wanting to use the details you're attempting to fetch but I'm assuming you want to have an application that can access or modify resources. For security reasons, it is always recommended to use Service Principals with automated tools rather than allowing them to log in with a user identity. So I would recommend that you start by creating a service principal identity to handle that.
This article shows you how to create a new Azure Active Directory (Azure AD) application and service principal that can be used with the role-based access control:
https://learn.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal