2016-07-14 6 views
2

Membership 및 폼 인증 모듈을 사용하여 '기존'MVC 프로젝트 (vNext 제외)에 웹 API 서비스를 추가했습니다. 웹용 API를 모바일 용 Azure App Services 용 최신 SDK를 사용하는 모바일 서비스로 만들기로 결정하기 전까지는 괜찮 았습니다.Azure App Service MVC/Forms와 호환되지 않는 모바일 인증

는 지금까지 MVC + 양식 인증이 작동하지 않도록이 응용 프로그램의 나머지 부분을 변경이

//app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions() 
      //{ 

      // SigningKey = CloudConfigurationManager.GetSetting("authSigningKey"), 
      // ValidAudiences = new[] { CloudConfigurationManager.GetSetting("authAudience") }, 
      // ValidIssuers = new[] { CloudConfigurationManager.GetSetting("authIssuer") }, 
      // TokenHandler = GlobalConfiguration.Configuration.GetAppServiceTokenHandler() 
      //}); 

에 문제를 좁혀왔다. 문제를 연구하기 위해 시간이 부족합니다. 모든 단서 ??

+0

같은 문제가 발생했습니다. 해결책을 찾아 주시겠습니까? –

답변

1

다음 솔루션은 나를 위해 노력하고 있습니다 : 당신의 Startup 레지스터 호출에서 UseCookieAuthentication, UseExternalSignInCookie 또는 UseOAuthAuthorizationServerUseAppServiceAuthentication를 호출하기 전에.

두 번째 단계 :

private sealed class CustomAppServiceAuthenticationMiddleware : AppServiceAuthenticationMiddleware 
{ 
    private readonly ILogger _logger; 

    public CustomAppServiceAuthenticationMiddleware(OwinMiddleware next, IAppBuilder appBuilder, AppServiceAuthenticationOptions options) : base(next, appBuilder, options) 
    { 
     _logger = (ILogger)GetType().BaseType.GetField("logger", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this); 
    } 

    protected override AuthenticationHandler<AppServiceAuthenticationOptions> CreateHandler() 
    { 
     return new AppServiceAuthenticationHandler(_logger); 
    } 

    public override Task Invoke(IOwinContext context) 
    { 
     string logLine = $"AppServiceAuthMiddleware: {context.Request.Path}"; 

     if (context.Request.Headers.TryGetValue("Authorization", out var values)) 
      logLine += $"; Authorization: {values.First().Split(' ').FirstOrDefault()}"; 
     if (context.Request.Headers.TryGetValue("X-ZUMO-AUTH", out values)) 
      logLine += $"; X-ZUMO-AUTH: {values.First()}"; 

     _logger.WriteVerbose(logLine); 
     Debug.WriteLine(logLine); 

     if (IsZumoAuth(context)) 
     { 
      return base.Invoke(context); 
     } 

     return Next.Invoke(context); 
    } 

    private bool IsZumoAuth(IOwinContext context) 
    { 
     return context.Request.Headers.ContainsKey("X-ZUMO-AUTH"); 
    } 
} 

Thrid 단계 :

 app.Use(typeof(CustomAppServiceAuthenticationMiddleware), app, new AppServiceAuthenticationOptions 
     { 
      SigningKey = ..., 
      ValidAudiences = ..., 
      ValidIssuers = ..., 
      TokenHandler = ... 
     }); 

이것은 owin pipline 만드는 AppServiceAuthenticationMiddleware를 호출합니다 : 다음과 app.UseAppServiceAuthentication 교체 프로젝트에 다음 클래스를 추가 단지 ZUMO-AUTH 인증 용입니다.

나는 혼합 된 웹 & 모바일 앱을 가지고 있습니다. 이 방법을 사용하면 웹 앱의 회원 인증이 작동합니다. 앱에서 일부 맞춤 oauth (토큰 새로 고침 기반)와 하늘 인증 (facebook, google, ...)이 작동합니다. 같은 asp.net 응용 프로그램 내 모든.

+0

이것은 굉장합니다. – Sentinel

관련 문제