I've successfully connected to SharePoint Online using PHP. It looks to me like you're combining two different methods to do so. Here is what I did:
- Register my app in Azure AD on the Management Portal to get client_id, client_secret, redirectUri and the right permissions on Office 365 for sites.
- Call the authorization endpoint at https://login.windows.net/common/oauth2/authorizehttps://login.microsoftonline.com/common/oauth2/authorize
- Call the token service endpoint at https://login.windows.net/common/oauth2/tokenhttps://login.microsoftonline.com/common/oauth2/token
- Call the SharePoint REST endpoint with the access token.
- The resource should be simply the URL of your SharePoint site.
The appregnew.aspx and appprincipals.aspx pages are used for apps for SharePoint but it doesn't look like you're building one.