양식 필드를 통해 사용자의 사용자 이름과 암호를 허용하는 간단한 ASP.NET MVC 기반 응용 프로그램을 작성한 다음 Office 365에 인증하고 간단한 달력 조회를 수행하고자합니다. 그 사용자. 위의 논리 이외에 어떤 멋진 논리가 필요하지 않습니다. 사용자가 어떤 사이트로 리디렉션되는 것을 원하지 않습니다. 이미 사용자의 Office 365 사용자 이름/비밀번호가 있습니다.MVC에서 Office 365로 간단한 인증을 수행하는 방법
내 코드까지 -하지만 개체 참조가 처음 authContext.AquireTokenAsync 호출에 설정되지 실패 :
internal static async Task<OutlookServicesClient> EnsureOutlookServicesClientCreatedAsync(string capabilityName,
string username, string password)
{
var signInUserId = username;
AuthenticationContext authContext = new AuthenticationContext(SettingsHelper.Authority,
new NaiveSessionCache(signInUserId));
try
{
DiscoveryClient discClient = new DiscoveryClient(SettingsHelper.DiscoveryServiceEndpointUri,
async() =>
{
var authResult =
await
authContext.AcquireTokenAsync(SettingsHelper.DiscoveryServiceResourceId,
SettingsHelper.ClientId, new UserCredential(signInUserId, password));
return authResult.AccessToken;
});
var dcr = await discClient.DiscoverCapabilityAsync(capabilityName);
return new OutlookServicesClient(dcr.ServiceEndpointUri,
async() =>
{
var authResult = await authContext.AcquireTokenAsync(dcr.ServiceResourceId,
SettingsHelper.ClientId, new UserCredential(signInUserId, password));
return authResult.AccessToken;
});
}
catch (AdalException exception)
{
//Handle token acquisition failure
if (exception.ErrorCode == AdalError.FailedToAcquireTokenSilently)
{
authContext.TokenCache.Clear();
throw exception;
}
return null;
}
}
아무도 내가 할 수있는 사용자를 리디렉션 할 필요없이이 인증 로직을 수행하는 방법을 조언 해 줄 수 있습니다 일부 포털?