2011-12-13 13 views
5

現在、DotNetOpenAuth CTPバージョンを使用してOAuth2認証サーバーを開発しています。私の認証サーバーはasp.net MVC3にあり、ライブラリによって提供されたサンプルに基づいています。アプリがコンシューマクライアントを認証するポイントに達するまで、すべてのことがうまく動作します。PrepareResponse()。AsActionResult()はサポートされていない例外をスローしますDotNetOpenAuth CTP

承認プロセスの世話をする、試料中の同等のアクションに非常によく似ている私のOAuthコントローラ内部のアクションがあります:

[Authorize, HttpPost, ValidateAntiForgeryToken] 
    public ActionResult AuthorizeResponse(bool isApproved) 
    { 
     var pendingRequest = this.authorizationServer.ReadAuthorizationRequest(); 

     if (pendingRequest == null) 
     { 
      throw new HttpException((int)HttpStatusCode.BadRequest, "Missing authorization request."); 
     } 

     IDirectedProtocolMessage response; 
     if (isApproved) 
     { 
      var client = MvcApplication.DataContext.Clients.First(c => c.ClientIdentifier == pendingRequest.ClientIdentifier); 
      client.ClientAuthorizations.Add(
       new ClientAuthorization 
       { 
        Scope = OAuthUtilities.JoinScopes(pendingRequest.Scope), 
        User = MvcApplication.LoggedInUser, 
        CreatedOn = DateTime.UtcNow, 
       }); 
      MvcApplication.DataContext.SaveChanges(); 
      response = this.authorizationServer.PrepareApproveAuthorizationRequest(pendingRequest, User.Identity.Name); 
     } 
     else 
     { 
      response = this.authorizationServer.PrepareRejectAuthorizationRequest(pendingRequest); 
     } 

     return this.authorizationServer.Channel.PrepareResponse(response).AsActionResult(); 
    } 

は毎回プログラムがこの行に到達:

this.authorizationServer.Channel.PrepareResponse(response).AsActionResult(); 

システムは私が研究した例外をスローし、成功しません。例外は次のとおりです。 LINQ to Entitiesでは、パラメータのないコンストラクタと初期化子のみがサポートされています。

スタックトレース:http://pastebin.com/TibCax2t

私はサンプルとは異なってやった唯一の事は、私は、私はサンプルがエンティティを自動生成デザイナーを使用して行われていたと思いますが、エンティティフレームワークのコードの最初のアプローチを使用したことです。

ありがとうございます。

+0

これを把握しましたか?私は同じ問題を抱えています。 – fuzz

答えて

1

あなたのICryptoKeyStore実装がCryptoKeyを直接格納しようとしているように見えますが、それは(デフォルトのコンストラクタが公開されていないため)Entityフレームワークと互換性のあるクラスではありません。代わりに、データを格納する独自のエンティティクラスをCryptoKeyに定義し、ICryptoKeyStoreは、永続性と取得のために2つのデータ型間を移行する必要があります。

+0

Duh!ありがとうアンドリュー... :) – Jammer

5

例から始めた場合、Andrewが話している問題はDatabaseKeyNonceStore.csにとどまります。私は、クエリの外で初期化を動かす解決した

public CryptoKey GetKey(string bucket, string handle) { 
     // It is critical that this lookup be case-sensitive, which can only be configured at the database. 
     var matches = from key in MvcApplication.DataContext.SymmetricCryptoKeys 
         where key.Bucket == bucket && key.Handle == handle 
         select new CryptoKey(key.Secret, key.ExpiresUtc.AsUtc()); 

     return matches.FirstOrDefault(); 
    } 

    public IEnumerable<KeyValuePair<string, CryptoKey>> GetKeys(string bucket) { 
     return from key in MvcApplication.DataContext.SymmetricCryptoKeys 
       where key.Bucket == bucket 
       orderby key.ExpiresUtc descending 
       select new KeyValuePair<string, CryptoKey>(key.Handle, new CryptoKey(key.Secret, key.ExpiresUtc.AsUtc())); 
    } 

public CryptoKey GetKey(string bucket, string handle) { 
     // It is critical that this lookup be case-sensitive, which can only be configured at the database. 
     var matches = from key in db.SymmetricCryptoKeys 
         where key.Bucket == bucket && key.Handle == handle 
         select key; 

     var match = matches.FirstOrDefault(); 

     CryptoKey ck = new CryptoKey(match.Secret, match.ExpiresUtc.AsUtc()); 

     return ck; 
    } 

    public IEnumerable<KeyValuePair<string, CryptoKey>> GetKeys(string bucket) { 
     var matches = from key in db.SymmetricCryptoKeys 
       where key.Bucket == bucket 
       orderby key.ExpiresUtc descending 
       select key; 

     List<KeyValuePair<string, CryptoKey>> en = new List<KeyValuePair<string, CryptoKey>>(); 

     foreach (var key in matches) 
      en.Add(new KeyValuePair<string, CryptoKey>(key.Handle, new CryptoKey(key.Secret, key.ExpiresUtc.AsUtc()))); 

     return en.AsEnumerable<KeyValuePair<string,CryptoKey>>(); 
    } 

私はこれが最善の方法であることをわからないんだけど、それ例外はこれらの2つの方法のいずれかによって発生します作品!

+0

ちょうど...ちょうど...ありがとうございます! – joshcomley

関連する問題