How to create modern sites with code via app-only or any other mechanism.

Copper Contributor

I am developing a solution which is multi tenant, basically in the application I can register tenants, with a username and password, I save the password in Azure Key vault securely and from my point of view its secure enough as I am not storing passwords anywhere else and only the app itself can read passwords to execute tenant operations, like creation of communication sites, modern sites, etc.


I analyzed a bit the code of the PnP-Powershell and the credentials are actually saved into the windows credential manager.


Almost a year ago I wanted to do this solution with App-Only, but then there is no API for creating modern sites with App-Only thats why I choosed to do it as explained above, there is a uservoice for this:


Analyzing the AuthenticationManager, I see there are some methods that dont use username and password but instead use certificates and return a ClientContext.


Speficially this: GetHighTrustCertificateAppOnlyAuthenticatedContext




Will this method allow creation of modern sites or it has also the same restriction as App-Only?  Is there anyother way that I can access other tenant via CODE without actually having their username and password stored in my design


App-Only would be ideal but its still not implemented.



4 Replies

Hi @Luis Valencia 

you can use Graph API and create an O365 Group Application is supported, with Group.ReadWrite.All permission on your Azure Active Directory Application


Here you can find the reference 

I suggest to you to use graph directly, because of TeamSiteCollectionCreationInformation and PnP CSOM Core component in my experience has some bugs, but feel free to use, maybe in your case it works good :) 




Thanks Federico, but I dont want to create groups, I want to create modern sites without groups.

Would love that somebody from Microsoft can tell us something here.