2013-02-14 77 views
1

我使用的是asp.net MVC 4.0和建築OAuth主機使用DotNetOpenAuth庫。 我試圖實現授權方法OAuthControllerAuthorizationServer.ReadAuthorizationRequest返回null

[Authorize, AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)] 
public ActionResult Authorise() 
{ 
    using (OAuth2AuthorizationServer server = (new OAuth2AuthorizationServer(new X509Certificate2(ConfigurationManager.AppSettings["AbsolutePathToPfx"], ConfigurationManager.AppSettings["CertificatePassword"]), new X509Certificate2(ConfigurationManager.AppSettings["AbsolutePathToCertificate"])))) 
    { 
     AuthorizationServer authorizationServer = new AuthorizationServer(server); 

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

和我越來越pendingRequest == null

我知道肯定的方法IClientDescription GetClient(string clientIdentifier)OAuth2AuthorizationServer應該在ReadAuthorizationRequest調用 - 但實際上它不會調用我的情況。

有沒有人猜測爲什麼會這樣?

回答

0

我已經想通了問題。長話短說 - 客戶端沒有正確使用。客戶端是負責含有這些信息爲:

  • CLIENT_ID
  • REDIRECT_URI
  • 狀態
  • 範圍
  • RESPONSE_TYPE

,而不是所有的領域都設立了

0

如果如下所述,您正在使用代碼示例:https://github.com/DotNetOpenAuth/DotNetOpenAuth/wiki/Security-scenarios

下面是一些樣本值來調用OAuthController驗證()動作:

- client_id=RP 
- response_type=code 
- redirect_uri=https://localhost/RP/Secure4ownAuthSvr/OAuth 
- scope=http://localhost/demo 
- state="" 

您的電話是這樣的(使用招):

GET 
http://localhost/OAuth2/Auth?client_id=RP&response_type=code&redirect_uri=https://localhost/RP/Secure4ownAuthSvr/OAuth&state=&scope=http://localhost/demo 

POST 
http://localhost/OAuth2/Auth 
Content-Type: application/x-www-form-urlencoded; charset=utf-8 
client_id=RP&response_type=code&redirect_uri=https://localhost/RP/Secure4ownAuthSvr/OAuth&state=&scope=http://localhost/demo