我们正在使用microsoft Graph SDK。在控制台应用程序中实现了POC,该代码可以正常工作,但是在MVC中添加此代码后,它无法正常工作。代码卡在等待调用中
以
的身份从控制器中调用 [HttpPost]
public actionResult InviteUser([Bind(Include = "EmailId")] UserLogin userLogin)
{
if (ModelState.IsValid)
{
string result = AzureADUtil.InviteUser(userLogin.EmailId);
}
return View();
}
方法实现如下
public static string InviteUser(string emailaddress)
{
string result = string.Empty;
result = InviteNewUser(emailaddress).Result;
return result;
}
private static async Task<string> InviteNewUser(string emailaddress)
{
string result = string.Empty;
try
{
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantID)
.WithClientSecret(clientSecret)
.Build();
ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
GraphServiceclient graphClient = new GraphServiceclient(authProvider);
// Send Invitation to new user
var invitation = new Invitation
{
InvitedUserEmailaddress = emailaddress,InviteRedirectUrl = "https://myapp.com",SendInvitationmessage = true,InvitedUserType = "Member"
};
// It stucks at this line
await graphClient.Invitations
.Request()
.AddAsync(invitation);
}
catch (Exception ex)
{
result = ex.Message;
}
return result;
}