
You can use the Graph API, although the license operations therein are a bit more convoluted compared to good old MSOnline module: https://learn.microsoft.com/en-us/graph/api/user-assignlicense?view=graph-rest-1.0&tabs=http
Alternatively, if you have AAD P1 license, look into group-based licensing: https://learn.microsoft.com/en-us/azure/active-directory/enterprise-users/licensing-groups-assign