Tôi phải xác thực một ứng dụng dựa vào Azure AD. Tôi đã tạo API web và thêm nó vào phần ứng dụng Azure AD. Thay đổi file manifest, tạo ra một API web và xác thực bằng AD Azure và tạo ra một hình thức Windows, có chứa đoạn mã sau:Ứng dụng có tên HTTPS://test113.onmicrosoft.com/FTP không được tìm thấy trong người thuê nhà có tên là test113.onmicrosoft.com
private async void button1_Click(object sender, EventArgs e)
{
string authority = "https://login.windows.net/test113.onmicrosoft.com";
string resourceURI = "https://test113.onmicrosoft.com/ftp";
string clientID = "5177ef76-cbb4-43a8-a7d0-899d3e886b34";
Uri returnURI = new Uri("http://keoftp");
AuthenticationContext authContext =
new AuthenticationContext(authority);
AuthenticationResult authResult =
authContext.AcquireToken(resourceURI, clientID, returnURI);
string authHeader = authResult.CreateAuthorizationHeader();
// don't do this in prod
System.Net.ServicePointManager.ServerCertificateValidationCallback =
((s, c, c2, se) => true);
HttpClient client = new HttpClient();
HttpRequestMessage request =
new HttpRequestMessage(HttpMethod.Get, "https://localhost:44300/api/tasks");
request.Headers.TryAddWithoutValidation("Authorization", authHeader);
var response = await client.SendAsync(request);
string responseString = await response.Content.ReadAsStringAsync();
MessageBox.Show(responseString);
}
Tôi đã có một ngoại lệ:
Một ngoại lệ của loại 'Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException' xảy ra ở Microsoft.IdentityModel.Clients.ActiveDirectory.dll nhưng không được xử lý theo mã người dùng
thông tin bổ sung: AADSTS5000 1: Ứng dụng có tên https://test113.onmicrosoft.com/ftp không được tìm thấy trong đối tượng thuê có tên là test113.onmicrosoft.com. Điều này có thể xảy ra nếu ứng dụng không được cài đặt được quản trị viên của người thuê hoặc chấp thuận bởi bất kỳ người dùng nào trong đối tượng thuê. Bạn có thể đã gửi yêu cầu xác thực cho người thuê nhà sai.
vết ID: e782d60e-b861-46a3-b32b-f3df78396bd0 Correlation ID: b4809815-2755-4de1-bd1b-0221d74fd0f0 Timestamp: 2016/03/17 11: 20: 08Z
Tôi không chắc chắn lý do tại sao bạn đang sử dụng 'https: // test113.onmicrosoft.com/ftp' làm resourceURI. Thông thường, tôi sử dụng 'https: // management.core.windows.net /' để quản lý dịch vụ Azure và 'https: // graph.windows.net' cho Graph API. –