2017-05-01 9 views
1

でOwin.Security.ActiveDirectoryライブラリを使用するのは正しい方法ですか?「New」と「Old」ポータルで同じAAD B2Cテナントに登録されている2つのアプリケーションがあります。AAD B2C

"古い"アプリケーションの資格情報での認証が正しく機能します。 「新しい」アプリケーションの資格情報で - エラーが表示されます。

IDX10500:署名の検証に失敗しました。 'SecurityKeyIdentifier ( IsReadOnlyの= Falseに、 カウント= 1、 句[0] = System.IdentityModel.Tokens.NamedKeySecurityKeyIdentifierClause ) '

はそれがMicrosoft.Owinを使用するための正しい方法です:SecurityKeyIdentifierを解決することができません。 AAD B2Cテナントに登録されたアプリケーションを持つ.Security.ActiveDirectorライブラリ(ASP.Net Web APIを保護するため)

P.S.私の質問はこのpostに基づいています。

答えて

0

アプリケーションは、new Azure portal (portal.azure.com)のAzure AD B2Cブレードでのみ作成してください。

古典的なAzureポータル(manage.windowsazure.com)を使用してAzure AD B2Cのアプリケーションを作成しないでください。

ウェブアプリケーションを保護する場合は、OwinのOpenIdConnectAuthenticationを使用する必要があります。この文書では、これを行う方法の詳細を持っていますSign-Up & Sign-In in a ASP.NET Web App

あなたはWebAPIのを確保したい場合は、OwinのOAuthBearerAuthenticationを使用する必要があります。この文書では、これを行う方法の詳細を持っています。Web APIの

public void ConfigureAuth(IAppBuilder app) 
{ 
    app.UseCookieAuthentication(new CookieAuthenticationOptions()); 
    app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); 

    app.UseOpenIdConnectAuthentication(
     new OpenIdConnectAuthenticationOptions 
     { 
      // Generate the metadata address using the tenant and policy information 
      MetadataAddress = String.Format(AadInstance, Tenant, DefaultPolicy), 

      // These are standard OpenID Connect parameters, with values pulled from web.config 
      ClientId = ClientId, 
      RedirectUri = RedirectUri, 
      PostLogoutRedirectUri = RedirectUri, 

      // Specify the callbacks for each type of notifications 
      Notifications = new OpenIdConnectAuthenticationNotifications 
      { 
       RedirectToIdentityProvider = OnRedirectToIdentityProvider, 
       AuthorizationCodeReceived = OnAuthorizationCodeReceived, 
       AuthenticationFailed = OnAuthenticationFailed, 
      }, 

      // Specify the claims to validate 
      TokenValidationParameters = new TokenValidationParameters 
      { 
       NameClaimType = "name" 
      }, 

      // Specify the scope by appending all of the scopes requested into one string (separated by a blank space) 
      Scope = $"{OpenIdConnectScopes.OpenId} {YourScope1} {YourScope2}" 
     } 
    ); 
} 

サンプル構成:WebAppののBuild a .NET web API


サンプル構成を

public void ConfigureAuth(IAppBuilder app) 
    { 
     TokenValidationParameters tvps = new TokenValidationParameters 
     { 
      // Accept only those tokens where the audience of the token is equal to the client ID of this app 
      ValidAudience = ClientId, 
      AuthenticationType = Startup.DefaultPolicy 
     }; 

     app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions 
     { 
      // This SecurityTokenProvider fetches the Azure AD B2C metadata & signing keys from the OpenIDConnect metadata endpoint 
      AccessTokenFormat = new JwtFormat(tvps, new OpenIdConnectCachingSecurityTokenProvider(String.Format(AadInstance, Tenant, DefaultPolicy))) 
     }); 
    } 
+0

ありがとうございました非常に – user1776813

+0

ちょっと@ user1776813、あなたはこの質問に答えてフラグを立てることができますか? – Saca

関連する問題