私は2つのAzureアクティブディレクトリアプリケーションを設定しています。Azureアクティブディレクトリ単一テナント別webapiアプリケーションへのアクセス
簡潔さのために、App-A
およびApp-B
。
A
はwebappであり、B
はsomedomain.azurewebsites.net
に公開されており、webapiを公開しています。
の両方が持つ設定されている:今
app.UseCookieAuthentication(new CookieAuthenticationOptions(){
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions{
AutomaticAuthenticate = true,
AutomaticChallenge = true,
ClientId = Configuration["Authentication:AzureAd:ClientId"],
Authority = Configuration["Authentication:AzureAd:AADInstance"] + Configuration["Authentication:AzureAd:TenantId"],
CallbackPath = Configuration["Authentication:AzureAd:CallbackPath"],
TokenValidationParameters = new TokenValidationParameters{
SaveSigninToken = true,
},
Events = new OpenIdConnectEvents{
OnAuthenticationFailed = OnAuthenticationFailed,
OnAuthorizationCodeReceived = OnAuthorizationCodeReceived,
OnMessageReceived = OnMessageReceived,
OnTicketReceived = OnTicketRecieved,
OnTokenValidated = OnTokenValidated,
OnUserInformationReceived = OnUserInformationReceived,
OnTokenResponseReceived = OnTokenResponseRecieved,
OnRemoteFailure = OnRemoteFailure
}
});
App-B
はApp-A
に委任権限を可能にし、その逆。私はまた、「
App-A
は[Authorize]
アクセスしようとするとhttp://localhost:5000/signin-oidc
、App-B
への返信URL」彼らはサインインする必要がありますし、MicrosoftからのサインインページにルーティングされているDコントローラをApp-A
を追加しました。今すぐこのログインページで、最初のログイン時にApp-B
web-apiにすぐにアクセスできますか?最初のハンドシェイク/ログインから何らかの形でアクセストークンを送信することができますか、または以下のようなトークンを収集するために別の往復を行う適切な方法ですか?
もう一度往復する必要がある場合は、最新のどこかにサンプルコードブロックがありますか?コードを動作させるようなことはできません。私が見つけてる
すべての例は次のようなものです:
private Task OnAuthorizationCodeReceived(AuthorizationCodeReceivedContext context){
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;
AuthenticationContext authContext = new AuthenticationContext(string.Format("https://login.windows.net/{0}", tenantID), new EFADALTokenCache(signedInUserID));
AuthenticationResult result = authContext.AcquireTokenByAuthorizationCode(code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceID);
しかし、私はしても、コンテキストのプロパティであることcode
が表示されませんか? 私は現在、最新バージョンのnetcoreを使用しています。
私の主な目標は、初期の署名から何とか取得したトークンでApp-B
エンドポイントへHttpClient
電話をかけることです
、手動で上記ブロック内の行を呼び出すことによって取得して意味ですか?私がそのビットを除外しようとしたときにauthContext.AcquireTokenSilentAsyncを使用すると、トークンがキャッシュにないというエラーが発生したためです。 – cjsmith
トークンキャッシング実装を認証コンテキストに渡してコードを使用していない場合、このインスタンスで後続のリクエストでAcquireTokenSilentAsyncを使用することはできません。 – davidcarr
そして、私が自動で意味するとき、私はキャッシュからの意味です。 – davidcarr