Situation:
I have a WPF application that have to call an http-trigger function which is secured via Azure Active Directory. While trying to retrieve a bearer token for further calls I get following response (no matter if I do it via postman or code):
AADSTS90014: The required field 'scope' is missing
What I've done:
I read ton of different articles and blog posts explaining how to secure an http-trigger function with Azure AD and retrieve a bearer token via rest request. Following one of those articles which I thought fits best to my needs I created the full setup of azure function app, azure function, azure AD configuration and app registrations.
After that I just wanted to use the azure function by sending the bearer token and some other parameters and get the result but I got stuck in retrieving the bearer token.
Code (just in case):
var restClient = new RestClient("https://login.microsoftonline.com/{myTenant}/oauth2/v2.0/token");
var restRequest = new RestRequest(Method.POST);
restRequest.AddHeader("content-type", "application/x-www-form-urlencoded");
restRequest.AddParameter("grant_type", "client_credentials", ParameterType.GetOrPost);
restRequest.AddParameter("client_id", "{app id from azure ad app}", ParameterType.GetOrPost);
restRequest.AddParameter("client_secret", "{generated secret}", ParameterType.GetOrPost);
restRequest.AddParameter("ressource", "https://{somefunctionname}.azurewebsites.net", ParameterType.GetOrPost);
var restResponse = restClient.Execute(restRequest);
Postman body parameters (x-www-form-urlencoded):
grant_type = "client_credentials"
client_id = {app id from azure ad app}
client_secret = {generated secret}
ressource = "https://somefunctionname.azurewebsites.net"
and the Url I use to get the token:
https://login.microsoftonline.com/{myTenant}/oauth2/v2.0/token
My question:
So having a detailed look on the situation I have two major questions:
- Why does the authentication service expects a "scope" parameter in my case (is there something wrong in my setup or in my rest request)?
- Which scope value to send in case I have to send one?