As @4c74356b41 provided, you could use Web Apps - Create Or Update Host Name Binding to achieve what you want. I test in my site and it works fine, you could refer to the following steps.
1.Go to the webapp that you have created in portal and add permission to the app registered in Azure AD.
2.Go to your DNS configuration UI for your custom domain and follow that instructions.
3.You could follow the code as below.
Note:The hostNameBindings name here is the whole CNAME in your custom domain DNS zone like joey.example.com
var appId = "xxxxxxxxxxxxxxxxx";
var secretKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
var tenantId = "xxxxxxxxxxxxxxxxxxxxxxxx";
var context = new AuthenticationContext("https://login.windows.net/" + tenantId);
ClientCredential clientCredential = new ClientCredential(appId, secretKey);
var tokenResponse = context.AcquireTokenAsync("https://management.azure.com/", clientCredential).Result;
var accessToken = tokenResponse.AccessToken;
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
var baseUrl = new Uri($"https://management.azure.com/");
var requestURl = baseUrl +@"subscriptions/xxxxxxxxxxxxxxxxxxx/resourceGroups/xxxxxxxxxxxx/providers/Microsoft.Web/sites/xxxxxxxxxx/hostNameBindings/xxxxxxxxxxxxxx?api-version=2016-08-01";
string body = "{\"properties\": {\"azureResourceName\": \"joey\"}}";
var stringContent = new StringContent(body, Encoding.UTF8, "application/json");
var response = client.PutAsync(requestURl, stringContent).Result;
}
The output: