title: Change user password for using Azure Graph API
body: <p>I am not able to change the password of the logged in Azure AD B2C user.
  I have Azure B2C tenant which is used for dev and QA.Also, i have two applications something-Local and something-QA used for DEV and QA respectively in Azure B2C as shown below and I have verified the settings of both the apps they are same <a href="https://i.stack.imgur.com/zKL4k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zKL4k.png" alt="enter image description here"></a>
  Below are the configurations of the applications 
  Here is my code which is used for B2C connection</p>
  
  <pre><code> private OpenIdConnectAuthenticationOptions CreateOptionsFromPolicy(string policy)
      {
          return new OpenIdConnectAuthenticationOptions
          {
              // For each policy, give OWIN the policy-specific metadata address, and
              // set the authentication type to the id of the policy
              // meta data
              MetadataAddress = "https://login.microsoftonline.com/" + "mytenant" + "/v2.0/.well-known/openid-configuration?p=" + policy,
              AuthenticationType = policy,
  
              // These are standard OpenID Connect parameters, with values pulled from web.config
              ClientId = AzureAdConfig.ClientId,
              Notifications = new OpenIdConnectAuthenticationNotifications
              {
                  AuthorizationCodeReceived = OnAuthorizationCodeReceived,
                  AuthenticationFailed = OnAuthenticationFailed,
                  SecurityTokenValidated = OnSecurityTokenValidated,
                  RedirectToIdentityProvider = OnRedirectToIdentityProvider,
              },
              Scope = "openid",
              ResponseType = "id_token",
  
              // This piece is optional - it is used for displaying the user's name in the navigation bar.
              TokenValidationParameters = new TokenValidationParameters
              {
                  NameClaimType = "name",
              }
          };
      }
  </code></pre>
  
  <p><strong>in the above code the ClientID used for QA and Dev are different.</strong>
  Below is the code used to change the user password using graph API.</p>
  
  <pre><code> public async Task&lt;HttpResponseMessage&gt; ChangePassword(string currentPassword, string newPassword)
      {
          string userId = ClaimValues.ObjectIdentifier();
          var adUser = _activeDirectoryClient.Users
              .Where(u =&gt; u.ObjectId.Equals(userId))
              .ExecuteAsync().Result.CurrentPage.FirstOrDefault();
  
          string upn = adUser.UserPrincipalName;
          var client = new HttpClient();
          string uriString = "https://login.microsoftonline.com/"+ AzureAdConfig.Tenant + "/oauth2/token";
          Uri requestUri = new Uri(uriString);
          string requestString = "resource=https%3a%2f%2fgraph.windows.net&amp;client_id=" + AzureAdConfig.AppId + "&amp;grant_type=password&amp;username=" + upn + "&amp;password=" + currentPassword + "&amp;client_secret=" + AzureAdConfig.AppKey;
          var tokenResult = await client.PostAsync(requestUri, new StringContent(requestString, Encoding.UTF8, "application/x-www-form-urlencoded"));
          if (tokenResult.IsSuccessStatusCode)
          {
              var stringResult = await tokenResult.Content.ReadAsStringAsync();
              GraphApiTokenResult objectResult = JsonConvert.DeserializeObject&lt;GraphApiTokenResult&gt;(stringResult);
              client = new HttpClient();
              string requestUrl = AzureAdConfig.GraphResourceId + AzureAdConfig.Tenant + "/me/changePassword?" + AzureAdConfig.GraphVersion;
              Uri graphUri = new Uri(requestUrl);
              client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", objectResult.access_token);
              requestString = JsonConvert.SerializeObject(new
              {
                  currentPassword = currentPassword,
                  newPassword = newPassword
              });
              var response = await client.PostAsync(graphUri, new StringContent(requestString, Encoding.UTF8, "application/json"));
              return response;
          }
          else
          {
              return tokenResult;
          }
      }
  </code></pre>
  
  <p>Also, i wanted to understand what is the difference between Application Registrations in Azure Active directory service of azure and the Application in Azure AD B2C of azure?</p>
  
  <p>Thanks in advance </p>