현재 this example을 사용하여 C#의 Microsoft 그래프에 로그온합니다. 어떤 종류의 토큰이 내부적으로 사용되는지 잘 모르겠습니다. 따라서 내 주요 질문은 다음과 같습니다. 새로 고침 토큰의 타이밍에 대해 걱정해야합니까? 리프레시 토큰 수명 구성에 대해 this page이 발견되었습니다.이를 변경해야합니까? 신청서 세입자를 변경 한 경우, 신청서를에 등록한 세입자에게도 적립됩니까? 내가 조금 인증 과정을 수정, 그래서 https://github.com/Azure-Samples/active-directory-dotnet-graphapi-web에서 방법을 사용할 수 있습니다 Microsoft Graph API 멀티 테넌트 토큰 수명
AuthorizationCodeReceived = async (context) =>
{
// We received an authorization code => get token.
var code = context.Code;
ClientCredential credential = new ClientCredential(clientId, appKey);
string tenantID = context.AuthenticationTicket.Identity.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;
string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext authContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(string.Format("https://login.microsoftonline.com/{0}", tenantID), new EFADALTokenCache(signedInUserID));
AuthenticationResult result = await authContext.AcquireTokenByAuthorizationCodeAsync(
code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path).TrimEnd('/')), credential, graphResourceID);
}
:
internal class AuthenticationHelper
{
/// <summary>
/// Async task to acquire token for Application.
/// </summary>
/// <returns>Async Token for application.</returns>
public static async Task<string> AcquireTokenAsync()
{
string clientId = ConfigurationManager.AppSettings["ida:ClientID"];
string appKey = ConfigurationManager.AppSettings["ida:AppKey"];
string graphResourceID = Constants.ResourceUrl;
string signedInUserID = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
string tenantID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;
string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
// get a token for the Graph without triggering any user interaction (from the cache, via multi-resource refresh token, etc)
ClientCredential clientcred = new ClientCredential(clientId, appKey);
// initialize AuthenticationContext with the token cache of the currently signed in user, as kept in the app's EF DB
AuthenticationContext authContext = new AuthenticationContext(string.Format("https://login.microsoftonline.com/{0}", tenantID), new EFADALTokenCache(signedInUserID));
AuthenticationResult result = await authContext.AcquireTokenSilentAsync(graphResourceID, clientcred, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));
return result.AccessToken;
}
/// <summary>
/// Get Active Directory Client for Application.
/// </summary>
/// <returns>ActiveDirectoryClient for Application.</returns>
public static ActiveDirectoryClient GetActiveDirectoryClient()
{
string tenantID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;
Uri baseServiceUri = new Uri(Constants.ResourceUrl);
ActiveDirectoryClient activeDirectoryClient =
new ActiveDirectoryClient(new Uri(baseServiceUri, tenantID),
async() => await AcquireTokenAsync());
return activeDirectoryClient;
}
}
을 (무기명
초기 인증이 (전체 코드 here)처럼 작동) 위의 코드에서 얻은 AccessToken은 요청 시간과 동일한 만료 날짜를 가지며 상당히 길기 때문에 인증 과정에서 실제로 일어나는 일은 나를위한 블랙 박스처럼 보이기 때문에 이해하고 싶습니다.
감사합니다. 이렇게하면 더 명확 해집니다. 고객이 토큰을 취소하는 데 문제가 없습니다. 하지만 내 광고 토큰 수명에 대한 설정이 내 응용 프로그램이 승인 된 고객 AD에 의해 재정의 될 수 있는지 확실하지 않습니다. 전자 메일 보관과 같은 몇 가지 배경 작업을 수행해야하므로 심각한 문제가 될 수 있습니다. – Compufreak