2013-09-25 2 views
37

DotNetOpenAuth로 많은 작업을 해왔습니다. 먼저 5.0.0-alpha1을 사용했지만 문제를 일으키는 원인을 찾을 수 없어 v4.0.30319로 전환했습니다.DotNetOpenAuth가 MVC 5에서 작동하지 않습니다. RC

우리는 Visual Studio 2013에서 MVC 5 RC가 포함 된 .NET 4.5.1 RC에 C# Web API 프로젝트를 구축하고 있습니다. IAuthorizationServerHost, INonceStoreICryptoKeyStore을 구현했습니다. 우리가

문제는 다음과 같은 경우 주위 : DotNetOpenAuth.Messaging의 기원과 MessagingUtilities 정적 클래스와

public class TokensController : Controller 
{ 
    private readonly AuthorizationServer authorizationServer = new AuthorizationServer(new MyAuthorizationServer()); 

    /// <summary> 
    /// This action will handle all token requests. 
    /// </summary> 
    /// <returns>The action result that will output the token response.</returns> 
    [HttpPost] 
    public ActionResult Index() 
    { 
     var outgoingWebResponse = this.authorizationServer.HandleTokenRequest(this.Request); 
     return outgoingWebResponse.AsActionResult(); 
    } 
} 

return outgoingWebResponse.AsActionResult(); 방법에 관한 것이다. DotNetOpenAuth.Core (이 코드 포함)은 MVC 4.0을 참조하고 HttpResponseMessageActionResult 클래스는 ActionResult에서 상속받습니다.

이것은 MVC 5와 호환되지 않는 DotNetOpenAuth의 현재 버전을 의미합니다. 컴파일하고 실행하려고하면 500 개의 오류가 발생합니다.

누구나 쉽게 해결할 수있는 아이디어가 있습니까?

DotNetOpenAuth Nuget 패키지가 5.0 패키지를 작성한 것을 알지 못했습니다. 패키지를 다시 설치하고 assemblyBinding을 다시 추가 한 후 :

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    <dependentAssembly> 
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="5.0.0.0" /> 
    </dependentAssembly> 
</assemblyBinding> 

이것은 조금 더 있습니다. 'System.Web.Mvc.ActionResult가'실패 보안 중요 유형에 액세스 할 수있는 보안 투명한 방법 'DotNetOpenAuth.Messaging.MessagingUtilities.AsActionResult (DotNetOpenAuth.Messaging.OutgoingWebResponse)'에 의해

시도 : 이제 오류가 내려 온다.

답변

6

더 디버깅 후와 GitHub의 https://github.com/DotNetOpenAuth/DotNetOpenAuth/issues/307 결론에 DotNetOpenAuth에서 사람들 이야기는 MVC (5)가 새로운 보안 모델을 가지고 있다는 것입니다.

바인딩 리디렉션으로 충분하지 않습니다. 더 이상 두 가지 선택 사항이 있습니다 :

1) DotNetOpenAuth 소스 코드를 가져 와서 모든 프로젝트에서 [assembly : AllowPartiallyTrustedCallers]를 제거하십시오. 재 컴파일 및 멤버를 사용하여 강력한 이름 확인 sn -Vr *을 비활성화하십시오. 이 코드는 중간 트러스트 환경에서 실행할 수 없습니다.

2)는 DotNetOpenAuth 소스 코드를 잡고 최고의 미래 솔루션은 별도의 어셈블리에 관련된 모든 MVC 물건을 이동 될 GitHub의에 대한 논의에 따르면 MVC 5.

에 대해 그것을 컴파일.

+0

방금 ​​MVC5로 업그레이드했고이 문제로 인해 충돌했습니다. 주변을 둘러 보니 금주 모임이 프로젝트를 포기했음을 알면 놀랐습니다. 나는 DNOA가 아직 오랫동안 석방되지 않았기 때문에 여전히 활발히 발전하고 있다고 말할 수는 없습니다. 프로젝트의 상태는 어떻습니까? 아직도 DNOA를 사용하고 있습니까? – Jammer

3

해결 방법이 경우에 (현재 베타 nuget 패키지와 함께 사용할 수 있습니다) :

  • 는 ActionResult 클래스 HttpResponseMessage

    public class WrapperHttpResponseMessageResult : ActionResult 
    { 
        private readonly HttpResponseMessage _response; 
    
        public WrapperHttpResponseMessageResult(HttpResponseMessage response) 
        { 
         _response = response; 
        } 
    
        public override void ExecuteResult(ControllerContext context) 
        { 
         HttpResponseBase responseContext = context.RequestContext.HttpContext.Response; 
         responseContext.StatusCode = (int)_response.StatusCode; 
         responseContext.StatusDescription = _response.ReasonPhrase; 
         foreach (KeyValuePair<string, IEnumerable<string>> keyValuePair in (HttpHeaders)_response.Headers) 
         { 
          foreach (string str in keyValuePair.Value) 
           responseContext.AddHeader(keyValuePair.Key, str); 
         } 
    
         if (_response.Content != null) 
         { 
          _response.Content.CopyToAsync(responseContext.OutputStream).Wait(); 
         } 
        } 
    } 
    
  • 변경 return outgoingWebResponse.AsActionResult();-new WrapperHttpResponseMessageResult(outgoingWebResponse);

랩 만들기

코드 WrapperHttpResponseMessageResultAsActionResult에서 복사되므로 동일한 기능을 수행합니다.

50

수정 가능.

NuGet 패키지 DotNetOpenAuth.Mvc5를 설치하고 권한 부여가 제대로 전달되는 것을 보장하기 위해 AsActionResultMvc5()

+2

* unified * 패키지와 함께 사용하는 방법이 있습니까? 아니면 제거하고 모든 개별 구성 요소를 별도로 다시 추가해야합니까? –

+3

이미 DotNetOpenAuth.Ultimate 패키지를 사용할 때 충돌이 있습니다. –

+0

DotNetOpenAuth.Ultimate 패키지 사용. 나는 아직도 그 오류를 얻고있다. 업데이트가 변경 되니? – MoXplod

2

사용이에 AsActionResult()의 모든 용도를 변경합니다. OutgoingWebresponse와 함께 사용하는 경우

public class MvcAuthorizer : WebAuthorizer 
{ 
    public ActionResult BeginAuthorization() 
    { 
     return new MvcOAuthActionResult(this); 
    } 

    public new ActionResult BeginAuthorization(Uri callback) 
    { 
     this.Callback = callback; 
     return new MvcOAuthActionResult(this); 
    } 
} 

'다음 제대로

public class MvcOAuthActionResult : ActionResult 
{ 
    private readonly WebAuthorizer webAuth; 

    public MvcOAuthActionResult(WebAuthorizer webAuth) 
    { 
     this.webAuth = webAuth; 
    } 

    public override void ExecuteResult(ControllerContext context) 
    { 
     webAuth.PerformRedirect = authUrl => 
     { 
      HttpContext.Current.Response.Redirect(authUrl); 
     }; 

     Uri callback = 
      webAuth.Callback == null ? 
       HttpContext.Current.Request.Url : 
       webAuth.Callback; 

     webAuth.BeginAuthorization(callback); 
    } 
} 
0

그것을 검색 (5 dotnetOpenAuth하지만 MVC 예를 업그레이드하지 않은).) (

반환 response.AsActionResult를; 교체 후

public class WrapperHttpResponseMessageResult : ActionResult 
{ 
    private readonly OutgoingWebResponse _response; 

    public WrapperHttpResponseMessageResult(OutgoingWebResponse response) 
    { 
     _response = response; 
    } 

    public override void ExecuteResult(ControllerContext context) 
    { 
     HttpResponseBase responseContext = context.RequestContext.HttpContext.Response; 
     responseContext.StatusCode = (int)_response.Status; 
     responseContext.StatusDescription = _response.Status.ToString(); 
     foreach (string key in _response.Headers.Keys) 
     { 
      responseContext.AddHeader(key, _response.Headers[key]); 
     } 

     if (_response.Body != null) 
     { 
      StreamWriter escritor = new StreamWriter(responseContext.OutputStream); 
      escritor.WriteAsync(_response.Body).Wait(); 
     } 
    } 
} 

그리고 :

이 (langtu의 응답에서 해킹) 클래스를 추가

반환 새로운 WrapperHttpResponseMessageResult (응답)와

;

+0

DotNetOpenAuth.Mvc5 Nuget 패키지를 아래 언급 된 Andrew Arnott으로 설치하는 것이 가장 쉽고 간단합니다. – decocijo

관련 문제