Microsoft.Graph.ServiceException: Code: methodNotAllowed

Jolienai Ribeiro Viegas 1 Reputation point
2021-03-17T23:53:05.307+00:00

I am getting 400 after sending the request below to my b2c tenant. see below more details:

Microsoft.Graph.ServiceException: Code: methodNotAllowed
Message: The method is not supported for this URL.

I need to reset the user password, so I am following what is described here: https://learn.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;  
           }  

and here is the packages I am using

   <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>  
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,521 questions
Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,633 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JamesTran-MSFT 36,361 Reputation points Microsoft Employee
    2021-03-29T21:56:03.923+00:00

    @Jolienai Ribeiro Viegas
    Thank you for your detailed post and I apologize for the delayed response!

    Based off your error message and our supported B2C Graph API operations article, the "passwordAuthenticationMethod: resetPassword" API is not supported for B2C. As of right now, only the GET/Update APIs are supported via the - User flow authentication methods (beta).

    Error Message:
    Microsoft.Graph.ServiceException: Code: methodNotAllowed
    Message: The method is not supported for this URL.

    If you'd like, I'd recommend leveraging our User Voice forum to create a feature request so our engineering team can take a look at implementing this.

    If you have any other questions, please let me know.
    Thank you for your time and patience throughout this issue.

    ----------

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.