우리는 Azure AD B2C와 OAuth를 사용하여 애플리케이션을 설정했지만이 서비스는 정상적으로 작동하지만 서비스 호출로 서비스를 인증하기 위해 노력하고 있습니다. 나는 약간 새로운데, Pluralsight에서 "정상적인"Azure Active Directory에서이 작업을 수행하는 방법에 대한 몇 가지 과정을 수행했지만 제대로 작동 할 수 있지만 B2C와 동일한 원칙을 따르면 작동하지 않습니다. Azure AD B2C로 서비스 인증하기
나는이 빠른 콘솔 응용 프로그램이 있습니다class Program
{
private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"]; //APIClient ApplicationId
private static string appKey = ConfigurationManager.AppSettings["ida:appKey"]; //APIClient Secret
private static string aadInstance = ConfigurationManager.AppSettings["ida:aadInstance"]; //https://login.microsoftonline.com/{0}
private static string tenant = ConfigurationManager.AppSettings["ida:tenant"]; //B2C Tenant
private static string serviceResourceId = ConfigurationManager.AppSettings["ida:serviceResourceID"]; //APP Id URI For API
private static string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
private static AuthenticationContext authContext = new AuthenticationContext(authority);
private static ClientCredential clientCredential = new ClientCredential(clientId, appKey);
static void Main(string[] args)
{
AuthenticationResult result = authContext.AcquireToken(serviceResourceId, clientCredential);
Console.WriteLine("Authenticated succesfully.. making HTTPS call..");
string serviceBaseAddress = "https://localhost:44300/";
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
HttpResponseMessage response = httpClient.GetAsync(serviceBaseAddress + "api/location?cityName=dc").Result;
if (response.IsSuccessStatusCode)
{
string r = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(r);
}
}
}
을 그리고 서비스는 다음과 같이 고정 :
내 B2C 세입자에private void ConfigureAuth(IAppBuilder app)
{
var azureADBearerAuthOptions = new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters()
{
ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
}
};
app.UseWindowsAzureActiveDirectoryBearerAuthentication(azureADBearerAuthOptions);
}
나는이 같은 꽤 많이 설치 두 개의 서로 다른 응용 프로그램이 있습니다
두 응용 프로그램 모두 "키"옵션에서 오는 비밀로 설정되었습니다. 생성 된 키는 Azure Active Directory를 사용하는 경우와 약간 다르게 구성됩니다.
토큰을 성공적으로 가져올 수 있지만 다른 서비스에 연결하려고하면 401이 표시됩니다. Azure Active Directory에 비해 B2C를 사용할 때 인증면에서 다른 것을해야합니까? API를 응용 프로그램에 웹 또는 네이티브 응용 프로그램의 접근에 대한 액세스 토큰을 발행 할 수
[헤드리스 인증 Azure AD b2c] (https://stackoverflow.com/questions/35072371/headless-authentication-azure-ad-b2c)의 가능한 복제본 – spottedmahn