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 (Get access on behalf of a user - Microsoft Graph | Microsoft Learn). 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("https://login.microsoftonline.com/{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;
Console.WriteLine(Code);
And:
var tokenClient = new RestClient("https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/token");
var tokenRequest = new RestRequest(Method.POST);
tokenRequest.AddHeader("Content-Type", "application/x-www-form-urlencoded");
tokenRequest.AddHeader("Host", "login.microsoftonline.com");
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;
Console.WriteLine(Bearer);
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 (Microsoft Office 365 - RPA Component | UiPath Marketplace) Component does not support API calls such a manner.
I hope someone can help me, thank you!