0

認証が成功した後に、別のアプリケーションにGET/POST要求を使って送信できるID Tokenを取得したいとします。IDトークンを別のアプリケーションに転送する

シナリオは次のとおりです。

  • 異なるURLを使用して、複数のWebアプリケーション(* .domain.com)
  • すべてのアプリケーションは、それらのすべてを置くためのAzureのActive Directoryに対して認証
  • あまりにも多くのURLのを必要としますredirect_url(すべてのホスト名に1つ必要)
  • アイデアは、ログインを処理し、IDトークンを* .domain.comアプリケーションに転送する「login」アプリケーション(login.domain.com)を使用します(状態フィールド)
  • * .domain.comはその後、IDトークンを検証し、ユーザーMicrosoft.AspNetCore.Authentication.OpenIdConnectを使用して

を許可、私はそれを正しく転送できるように、私はIDトークンを取得する方法を見つけ出すことはできません。

私は(これは動作します)適切ASP.NETコア1.0 Webアプリケーションと設定されている認証用のVS2015のテンプレートを使用しました

は今、私は何とかトークンを取得する必要がありますが、私はどのように把握することはできません。

app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions() 
     { 
      ClientId = Configuration["Authentication:AzureAd:ClientId"], 
      Authority = Configuration["Authentication:AzureAd:AADInstance"] + "Common", 
      CallbackPath = Configuration["Authentication:AzureAd:CallbackPath"], 

      TokenValidationParameters = new TokenValidationParameters 
      { 
       // Instead of using the default validation (validating against a single issuer value, as we do in line of business apps), 
       // we inject our own multitenant validation logic 
       ValidateIssuer = false, 

       // If the app is meant to be accessed by entire organizations, add your issuer validation logic here. 
       //IssuerValidator = (issuer, securityToken, validationParameters) => { 
       // if (myIssuerValidationLogic(issuer)) return issuer; 
       //} 
      }, 
      Events = new OpenIdConnectEvents 
      { 
       OnTicketReceived = (context) => 
       { 
        // If your authentication logic is based on users then add your logic here 
        return Task.FromResult(0); 

       }, 
       OnAuthenticationFailed = (context) => 
       { 
        context.Response.Redirect("/Home/Error"); 
        context.HandleResponse(); // Suppress the exception 
        return Task.FromResult(0); 
       }, 
       // If your application needs to do authenticate single users, add your user validation below. 
       //OnTokenValidated = (context) => 
       //{ 
       // return myUserValidationLogic(context.Ticket.Principal); 
       //} 
      } 
     }); 

私はTicketReceivedContextを使用してOnTicketReceivedイベントでそれを得ることができる必要がありますね?

答えて

1

私は間違ったイベントを使用していました。 OnTokenValidatedイベントでは、受け取った生のトークンであるcontext.SecurityToken.RawDataにアクセスできます。これは、必要なものです。

0

また、これを試すことができます。

string idToken = string.Empty; 
if (ctx.Properties.Items.ContainsKey(".Token.id_token")) 
{ 
    idToken = ctx.Properties.Items[".Token.id_token"]; 
} 
関連する問題