B2C REST API的验证可以通过以下步骤完成:
示例代码:
string authority = "https://login.microsoftonline.com/[Your-B2C-Tenant-Name].onmicrosoft.com/oauth2/v2.0/token";
string clientId = ConfigurationManager.AppSettings["ida:B2CClientId"];
string clientSecret = ConfigurationManager.AppSettings["ida:B2CClientSecret"];
string scope = "[Your-B2C-REST-API-Scopes]";
var clientCredential = new ClientCredential(clientId, clientSecret);
var authenticationContext = new AuthenticationContext(authority, false);
var result = authenticationContext.AcquireTokenAsync(scope, clientCredential).Result;
string accessToken = result.AccessToken;
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
string apiUrl = "[Your-B2C-REST-API-URL]";
HttpResponseMessage response = await httpClient.GetAsync(apiUrl);
string apiResponse = await response.Content.ReadAsStringAsync();