title: .NET Core 2.1 Azure AD B2C Web and API
body: <p>It is easy to create an Azure AD B2C Web or API App out of the box using <code>VS 2017 15.7.2+</code>. </p>
  
  <p>So I created a solution that has both, but I am trying to get the access token from the Web App and use it to call the API and I cannot find a way.</p>
  
  <p>I tried option 1 (<strong>doesn't work</strong>):</p>
  
  <pre><code>private async Task&lt;string&gt; GetAccessTokenCacheAsync()
  {
      string authority = $"{AzureAdOptions.Instance}{AzureAdOptions.ClientId}/{AzureAdOptions.SignUpSignInPolicyId}/";
      string clientId = AzureAdOptions.ClientId;
      Uri redirectUri = new Uri("https://localhost:12345/");
      string resource = targetApplicationID;
      AuthenticationContext ac = new AuthenticationContext(authority);
      AuthenticationResult result = null;
      try
      {
          result = await ac.AcquireTokenSilentAsync(resource, clientId);
      }
      catch (AdalException adalException)
      {
          if (adalException.ErrorCode == AdalError.FailedToAcquireTokenSilently
              || adalException.ErrorCode == AdalError.InteractionRequired)
          {
              result = await ac.AcquireTokenAsync(resource, clientId, redirectUri,
                                                  new PlatformParameters()); //PromptBehavior.Auto
          }
      }
      return result.AccessToken;
  }
  </code></pre>
  
  <p>And I Got:</p>
  
  <pre><code>System.NotImplementedException: 'The method or operation is not implemented.'
  </code></pre>
  
  <p>I tried option 2 (<strong>doesn't work</strong>), MSAL (Microsoft.Identity.Client):</p>
  
  <pre><code>private async Task&lt;string&gt; GetAccessTokenCacheAsync() {
      string authority = $"{AzureAdOptions.Instance}{AzureAdOptions.ClientId}/{AzureAdOptions.SignUpSignInPolicyId}/";
      PublicClientApplication myApp = new PublicClientApplication(AzureAdOptions.ClientId, authority);
      AuthenticationResult authenticationResult = await myApp.AcquireTokenAsync(
          new[] { $"{ApiScopeUrl}/read", $"{ApiScopeUrl}/write" }
          ,
          myApp.Users.FirstOrDefault()
          ,
          UIBehavior.ForceLogin
          ,null,null
          ,authority
          ).ConfigureAwait(false);
      return authenticationResult.AccessToken;
  }
  </code></pre>
  
  <p>And I Got:</p>
  
  <pre><code>System.NotImplementedException: 'The method or operation is not implemented.'
  </code></pre>
  
  <p>I also tried to adapt the code from Azure samples such as <a href="https://github.com/Azure-Samples/active-directory-b2c-dotnet-webapp-and-webapi" rel="nofollow noreferrer">https://github.com/Azure-Samples/active-directory-b2c-dotnet-webapp-and-webapi</a> (Framework 4.5.1) or <a href="https://github.com/Azure-Samples/active-directory-dotnet-webapp-webapi-openidconnect-aspnetcore" rel="nofollow noreferrer">https://github.com/Azure-Samples/active-directory-dotnet-webapp-webapi-openidconnect-aspnetcore</a> (Core 2.0 and OpenID, no B2C) and fail. </p>
  
  <p>This <a href="https://github.com/Azure-Samples/active-directory-b2c-dotnetcore-webapp" rel="nofollow noreferrer">https://github.com/Azure-Samples/active-directory-b2c-dotnetcore-webapp</a> also mention to implement <code>OnAuthorizationCodeReceived</code>, but Core 2.1 seems to has this implemented with <code>AddAzureADB2C</code> (black-boxed). The documentation on this new library seems to be missing or in progress because I can't find it.</p>
  
  <p>I want to know, how to get the Access Token using built-in features in .NET Core 2.1? </p>
  
  <p>I believe if I know how to implement <code>OnAuthorizationCodeReceived</code>, I will be one step closer to find the answer. Here the code source and ticket that I created relates to this: <a href="https://github.com/aspnet/AADIntegration/issues/21" rel="nofollow noreferrer">https://github.com/aspnet/AADIntegration/issues/21</a></p>