UiPath Microsoft Graph身份验证

时间:2020-04-08 14:02:24

标签: .net authentication microsoft-graph-api uipath

我正在使用UiPath来自动化公司内的流程。由于UiPath支持DotNet框架,因此我尝试将REST请求从UiPath发送到我们的Rest API,该API在Azure上运行。

因此,要创建请求,我需要使用Microsoft Graph Authenticator对用户进行身份验证。由于我对在线服务非常陌生,因此我从这里(https://docs.microsoft.com/en-us/graph/auth-v2-user)获取信息。由于我正在使用UiPath,因此无法使用任何功能,因此我有2个活动,它们创建一个身份验证请求以生成身份验证代码。之后,将使用身份验证代码生成我的访问令牌。

问题是,当我想获取身份验证代码时,UiPath本身不会打开身份验证对话框。是否可以强制打开Microsoft Graph Authenticator并在UiPath中返回身份验证代码?

我的活动如下:

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);

并且:

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);

当前,来自第一个活动的响应返回用于身份验证的HTML,但是我没有找到直接显示此信息并返回所需代码的方法。 Request在Postman中有效,所以我唯一的问题是UiPath中的集成。

供参考:此(https://connect.uipath.com/marketplace/components/microsoft-office-365-669054)组件不支持这种方式的API调用。

我希望有人能帮助我,谢谢!

0 个答案:

没有答案