2
votes

Hi I have PHP CRM running in Azure server,my requirement is that user should be able to add there own custom domains(they will do the DNS configurations seperately) to app by themselves through CRM site,is there any REST API call to achieve that,i searched a lot but couldn't find any documents from Azure, i did find these from stack Programatically add domain name to azure website

Add a domain to an Azure web site via code

i tried above expample using Chrome Postman app

App(instanceName) name name is "example"

"https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{myResourceGroup}/providers/Microsoft.Web/sites/{instanceName}/config/web?api-version=2015-08-01"

used both POST and PUT method

{ "properties": { "HostNames":"example.com, crm.example.com" } }

i tried these methods but all i am getting a error "Authentication failed. The 'Authorization' header is not present or provided in an invalid format",i believe something wrong with json values,

example.com.au is my existing website and crm.example.com is my domain name i want to add,is it correct, am i missing anything,please help me

1

1 Answers

1
votes

As all of the tasks that you do on resources using the Azure Resource Manager must be authenticated with Azure Active Directory. So To implement Azure Resource Manager Rest APIs, we need to follow the steps in authenticate Azure Recourse Manager requests first to set up authentication.

Generally:

  1. Add an application to the Azure Active Directory tenant.

  2. Set permissions for the application that you added.

  3. Get the token for authenticating requests to Azure Resource Manager.

--Update--

To get the access token for Azure Resource Manager, we should follow the steps shows in Authorization Code Grant Flow:

1,Request an authorization code enter image description here The build-up URL will redirect to the sso page, after login we can get the code value which will be used in next step.

2,Use the Authorization Code to Request an Access Token: enter image description here

3,We can leverage the access token for authorizing the resource REST API: enter image description here

--update1--

To create an app-only without user ui application, you need to follow client_credentials flow, shown in https://msdn.microsoft.com/en-us/library/azure/dn645543.aspx.

And to your authorization issue, you need to assign a Owner role for a written permission. you can leverage azure-cli to do this.

  1. Install the Azure-CLI.
  2. Connect to the Azure-CLI.
  3. Authenticate to your Service Principal using the Azure-CLI. And in the 4th step in this section, you need to change Reader to Owner, like azure role assignment create --objectId 47193a0a-63e4-46bd-9bee-6a9f6f9c03cb -o Owner -c /subscriptions/{subscriptionId}/ to assign a written permission.