I am eager to dive into Microsoft Azure and Graph by creating a simple application that will utilize the Graph API as a background worker. Although I currently only have a demo account, I believe this should not pose a problem.
I am following along with this tutorial:
https://learn.microsoft.com/en-us/graph/auth-v2-service#4-get-an-access-token
since I do not require a user account for this process. My initial goal is to obtain an access token using Axios. Given that I use NestJs, Axios is encapsulated within an HTTP module.
So far, I have set up the request as follows:
async getToken(): Promise<any> {
const requestURL: string = 'https://login.microsoftonline.com/2c1714e1-1030-4da9-af5e-59630d7fe05f/oauth2/v2.0/token';
const requestBody: object = {
tenant: '2c1714e1-1030-4da9-af5e-59630d7fe05f',
client_id: 'bec52b71-dc94-4577-9f8d-b8536ed0e73d',
scope: 'https://graph.microsoft.com/.default',
client_secret: 'OV/NkBIWH7d3G/BGyJQN3vxQA]fT6qK@',
grant_type: 'client_credentials',
};
const requestConfiguration: object = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
};
const observableResult: Observable<AxiosResponse<any>> = this.httpService.post(requestURL, requestBody, requestConfiguration);
return observableResult.toPromise();
}
Upon execution, I encounter a 400 HTTP error along with the message:
"AADSTS900144: The request body must contain the following parameter: 'grant_type'.\r\nTrace ID: 038a3bf5-9396-4a4c-9dd6-b4608f265800\r\nCorrelation ID: a1871bfc-af0d-470e-b604-f94ea4f10325\r\nTimestamp: 2019-12-21 23:10:11Z"
Have I misinterpreted the documentation? What might be missing or incorrect in my setup? Thank you for any guidance in advance.