다음 솔루션은 나를 위해 노력하고 있습니다 : 당신의 Startup
레지스터 호출에서 UseCookieAuthentication
, UseExternalSignInCookie
또는 UseOAuthAuthorizationServer
이 UseAppServiceAuthentication
를 호출하기 전에.
두 번째 단계 :
는
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 응용 프로그램 내 모든.
같은 문제가 발생했습니다. 해결책을 찾아 주시겠습니까? –