2016-06-17 9 views
3

Azure B2C를 웹 API와 함께 사용하여 본 적이있는 예제는 아래 그림과 같이 app.UseOAuthBearerAuthentication을 표시하지만 내 ASP .NET 5 웹 API 프로젝트는 IApplicationBuilder (IAppBuilder가 아님)를 사용하고 UseOAuthBearerAuthentication은 그렇지 않습니다. 있다. 나는 app.UseOpenIdConnectAuthentication을 시도했지만 쿠키를 사용한다고 믿고 있으며 Xamarin 앱을 클라이언트로 사용하여 작동시키지 못했습니다. app.UseWindowsAzureActiveDirectoryBearerAuthentication을 시도했지만 표준 Azure (B2C가 아님)에 해당한다고 생각하십니까? Azure B2C를 최신 ASP .NET 웹 API로 작업하는 방법에 대한 아이디어가 있습니까?웹 API가 포함 된 Azure B2C

감사합니다 !!!

답변

5

이것은 저에게 효과적입니다. 다음 웹 API에 JwtBearerAuthentication을 사용할 수 있으며, JWT 토큰은 클라이언트에서 사용할 수있는 경우

public void ConfigureAuth(IApplicationBuilder app, IOptions<PolicySettings> policySettings) 
{ 
    app.UseJwtBearerAuthentication(new JwtBearerOptions 
    { 
     AuthenticationScheme = JwtBearerDefaults.AuthenticationScheme, 
     AutomaticAuthenticate = true, 
     AutomaticChallenge = true, 
     MetadataAddress = "https://login.microsoftonline.com/[my-tenant].onmicrosoft.com/v2.0/.well-known/openid-configuration?p=B2C_1_my-signup-signin-policy", 
     Audience = "[My-Azure-App-Guid]", 
     Events = new JwtBearerEvents 
     { 
      OnTokenValidated= ctx => 
      { 
       var nameClaim = ctx.AuthenticationTicket.Principal.FindFirst("name"); 
       if (nameClaim != null) 
       { 
        var claimsIdentity = (System.Security.Claims.ClaimsIdentity)ctx.AuthenticationTicket.Principal.Identity; 
        claimsIdentity.AddClaim(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Name, nameClaim.Value)); 
       } 
       return Task.FromResult(0); 
      }, 
      OnAuthenticationFailed = ctx => 
      { 
       ctx.SkipToNextMiddleware(); 
       return Task.FromResult(0); 
      } 
     } 
    }); 
} 
+0

https://dzimchuk.net/post/setting-up-your-aspnet-core-apps-and-services-for-azure- ad-b2c – aherrick

+0

이 답변은 .NetCore를 사용하는 것으로 보입니다. 표준 .Net Jwt 라이브러리를 사용하는 모든 솔루션? – petryuno1

0

: 나는 최신 .NET 웹 API 프레임 워크 푸른 B2C를 사용 찾고 다른 사람에게 도움이되기를 바랍니다. Azure B2C (소셜 로그인)에서 발행 한 JWT는 웹 API에서 인증 받기위한 토큰으로 사용할 수 있습니다.

클라이언트가 웹 응용 프로그램입니다이 샘플에서 https://github.com/sendhilkumarg/AzureB2CWebAppAndAPIAuthentication 를 참조하십시오