Enable CORS for Azure Rest webapi application

后端 未结 2 1985
猫巷女王i
猫巷女王i 2021-01-24 10:51

I have simple jQuery page that makes calls to azure restful API to get the status of VMs. I\'m facing a problem that it\'s complaining about Cross-Origin Resource Sharin

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-24 11:31

    You cannot use a client secret from front-end Javascript. Your client secret will be public, it's basically your app's password.

    Client credentials grant is for back-end applications.

    You need to use e.g. the implicit grant flow with ADAL.JS/MSAL.JS to acquire tokens. Your front-end app also should be registered as Native since it is a public client.

    Here is a sample app: https://github.com/Azure-Samples/active-directory-javascript-singlepageapp-dotnet-webapi

    Oh, and the CORS error comes from Azure AD's token endpoint. You cannot do anything about it.

提交回复
热议问题