Microsoft Graph Authentication

I am using UiPath to automate processes within our company. Since UiPath supports the DotNet Framework, I am trying to send a REST Request from UiPath to our Rest API, which runs on Azure.

To create the Request i therefore need to authenticate the user with the Microsoft Graph Authenticator. Since I am very new to online Services, I take my information from here ( Because I am using UiPath I can not use any functions, therefore I have 2 activities, which create an authentication request to generate the authentication code. After this, the authentication code is used to generate my access token.

The Problem is, that UiPath natively does not open the authentication dialog, when I want to fetch my authentication code. Is there a way to force to open the Microsoft Graph Authenticator and return the authentication code in UiPath?

My Activities look like this:

var authCodeClient = new RestClient("{tenant-id}/oauth2/authorize?resource={resource-id}");
var authCodeRequest = new RestRequest(Method.POST);
authCodeRequest.AddHeader("Content-Type", "application/x-www-form-urlencoded");

authCodeRequest.AddParameter("client_id", "{client-id}");
authCodeRequest.AddParameter("redirect_uri", "{callback-uri}");
authCodeRequest.AddParameter("response_mode", "query");
authCodeRequest.AddParameter("response_type", "code");

IRestResponse authCodeResponse= authCodeClient.Execute(authCodeRequest);
Code = authCodeResponse.Content.Code;


var tokenClient = new RestClient("{tenant-id}/oauth2/v2.0/token");
var tokenRequest = new RestRequest(Method.POST);
tokenRequest.AddHeader("Content-Type", "application/x-www-form-urlencoded");
tokenRequest.AddHeader("Host", "");

tokenRequest.AddParameter("client_id", "{client-id}");
tokenRequest.AddParameter("code", Code);
tokenRequest.AddParameter("redirect_uri", "{callback-uri}");
tokenRequest.AddParameter("client_secret", "{client-secret}");
tokenRequest.AddParameter("grant_type", "authorization_code");

IRestResponse token = tokenClient.Execute(tokenRequest);
dynamic data = JObject.Parse(token.Content);
Bearer = data.access_token;

Currently the Response from the first activity returns the HTML for the Authentication, but I did not find a way to directly display this information AND return the needed code. The Request works in Postman, so the only problem I have is the integration in UiPath.

For Reference: This ( Component does not support API calls such a manner.

I hope someone can help me, thank you!

Hey Zumpel,

you should actually use the Microsoft Office 365 Activities to do so. Gives you way more interaction capability and you don’t have to maintain it yourself.

Unfortunately they do not provide a setting for the Application Secret in their Microsoft Office 365 Scope. This is a problem for me. But I don’t see you using it. So go ahead :wink: