【发布时间】:2021-06-16 04:37:00
【问题描述】:
将以下请求发送给我的 b2c 租户后,我得到了 400。详情见下文:
Microsoft.Graph.ServiceException:代码:methodNotAllowed 消息:此 URL 不支持该方法。
我需要重置用户密码,所以我按照这里描述的:https://docs.microsoft.com/en-us/graph/api/passwordauthenticationmethod-resetpassword?view=graph-rest-beta&tabs=csharp
这是我的代码:
public async Task<string> ResetPassword(string userId)
{
var newPassword = Helpers.PasswordHelper.GenerateNewPassword(4, 8, 4);
var result = await graphClient
.Users[userId]
.Authentication.PasswordMethods["{passwordAuthenticationMethod-id}"]
.ResetPassword(newPassword, null)
.Request()
.PostAsync();
return result.NewPassword;
}
我添加到项目中的包
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Graph.Auth" Version="1.0.0-preview.4" />
<PackageReference Include="Microsoft.Graph.Beta" Version="0.39.0-preview" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.13.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
</ItemGroup>
</Project>
我做错了什么?
【问题讨论】:
-
不允许的方法是 405 :P
-
用户 id 是正确的用户 id,而不是奇怪的东西吗?我想您所遇到的一种解释是 api 将所有内容转换为端点 URI,将用户 ID 替换为路径,并最终匹配不接受帖子的内容。但只是一个想法。
-
您登录的帐户是否具有“全局管理员”或“身份验证管理员”或“特权身份验证管理员”角色?
-
怎么样?您的问题解决了吗?
标签: c# .net-core microsoft-graph-api azure-ad-b2c