私はマルチテナントアプリケーションを正常にセットアップしました。 今のところ、私はユーザーを認証し、トークンを使用して他のリソースにアクセスすることができます。 (Microsoft Graph & Microsoft AD Graph)マルチテナントアプリケーションでのB2Bアクセス
今、私はB2Bを稼働させたいと思っています。 電流の流れ: - におけるユーザー兆し - AuthorizationCodeReceivedは($ commonAuthorityエンドポイントを経由して)トークンを取得を取得し - とき$ tenantAuthority広告グラフのトークンを要求するとき、私は$ tenantAuthorityに
を使用しています。これは完璧に動作します
しかし、私は別のテナントから(実際のテナントに信頼を置いて)ログインし、$ tenantAuthority = trusted authorityを使用すると、私は常に次のエラーが表示されます。 リフレッシュトークンに失敗しました: AADSTS65001:ユーザーまたは管理者は、
$ tenantAuthorityを、ユーザーが作成された「ソース」テナント機関に変更すると、すべて正常に動作します。
ご協力いただければ幸いです。
更新:コードサンプル
のAppは2つのテナント(tenantAエンtenantB)を持っており、私は、このユーザーに信頼与えtenantAでtenantBからユーザーを使用します。
AuthorizationCodeReceived = async context =>
{
TenantContext.TenantId = "someguid";
var tenantId =
TenantContext.TenantId;
// get token cache via func, because the userid is only known at runtime
var getTokenCache = container.Resolve<Func<string, TokenCache>>();
var userId = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.ObjectIdentifier).Value;
var tokenCache = getTokenCache(userId);
var authenticationContext = new AuthenticationContext($"{configuration.Authority}",
tokenCache);
await authenticationContext.AcquireTokenByAuthorizationCodeAsync(
context.Code,
new Uri(context.Request.Uri.GetLeftPart(UriPartial.Authority)),
new ClientCredential(configuration.ClientId, configuration.ClientSecret),
configuration.GraphResourceId);
}
このコードは完全に機能します。両方のテナントからのユーザーとのログインは完全に機能します。
しかし、私はグラフサービスクライアントまたはActiveDirectoryClientが必要なときに、特定のテナントのAPIに対処できるようにアクセストークンを取得する必要があります。私は2つのクライアントSDK年代のひとつで要求を行うと
public IGraphServiceClient CreateGraphServiceClient()
{
var client = new GraphServiceClient(
new DelegateAuthenticationProvider(
async requestMessage =>
{
Logger.Debug("Retrieving authentication token to use in Microsoft Graph.");
string token;
var currentUserHomeTenantId = TenantContext.TenantId;
var currentUserObjectId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.ObjectIdentifier).Value;
var authenticationContext =
new AuthenticationContext($"{_configuration.TenantAuthorityPrefix}{currentUserHomeTenantId}",
_tokenCacheFactoryMethod(currentUserObjectId));
var clientCredential = new ClientCredential(_configuration.ClientId, _configuration.ClientSecret);
try
{
token = await GetTokenSilently(authenticationContext, _configuration.GraphResourceId, currentUserObjectId);
}
catch (AdalSilentTokenAcquisitionException e)
{
Logger.Error("Failed to retrieve authentication token silently, trying to refresh the token.", e);
var result = await authenticationContext.AcquireTokenAsync(_configuration.GraphResourceId, clientCredential);
token = result.AccessToken;
}
requestMessage.Headers.Authorization = new AuthenticationHeaderValue(AuthenticationHeaderKeys.Bearer, token);
}));
return client;
}
public IActiveDirectoryClient CreateAdClient()
{
var currentUserHomeTenantId = TenantContext.TenantId;
var currentUserObjectId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.ObjectIdentifier).Value;
var graphServiceUrl = $"{_configuration.AdGraphResourceId}/{currentUserHomeTenantId}";
var tokenCache = _tokenCacheFactoryMethod(currentUserObjectId);
var client = new ActiveDirectoryClient(new Uri(graphServiceUrl),
() => GetTokenSilently(
new AuthenticationContext(
$"{_configuration.TenantAuthorityPrefix}{ClaimsPrincipal.Current.FindFirst(ClaimTypes.TenantId).Value}", tokenCache
),
_configuration.AdGraphResourceId, currentUserObjectId
));
return client;
}
、私は次のエラーを得た:AADSTS65001: は、リフレッシュトークンを失敗したユーザーまたは管理者は、に同意していない私はこのようなアクセストークンを取得しますIDを持つアプリケーションを使用します。
あなたが同意ページを見ました他のテナントから?そうでない場合は、ログインについてどうすればよいでしょうか? –