DotNetOpenAuth: Getting the sample OAuth 2.0 AuthorizationServer Working

瘦欲@ 提交于 2020-01-06 02:39:27

问题


I am in the process of identifying a framework for building a local OAuth (2.0) Provider with a good client library (there aren’t many), at a glance DotNetOpenAuth seems to be ideal and I got excited and wanted to try out the samples.

I spent few days fiddling with the sample and the source itself still I couldn’t figure out a way to get the OAuth2\AuthorizationServer sample working. Sample works fine for all other external providers. I went through numerous posts to figure out ideal setup, inputs, settings to get pass initial login screen but I had no luck.

Can someone please share the initial steps to be followed to get the OAuth2\AuthorizationServer sample up and running. Including the database setup. I tried stepping through the code but lost it.

Appreciate your time. I am very happy to document the steps if I can understand them clearly. I think the framework is excellent but documentation is lacking. Thanks again!

This is the error I am getting,

DotNetOpenAuth.Messaging.ProtocolException: No OpenID endpoint found. ---> System.InvalidOperationException: Sequence contains no elements

I’ve used relying party URI as inputs, http:// localhost:59722 / http:// localhost:59722 /SampleWcf2.aspx

And the full stack trace,

DotNetOpenAuth.Messaging.ProtocolException: No OpenID endpoint found. ---> System.InvalidOperationException: Sequence contains no elements
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) in d:\Temp\dotnetopenid\src\DotNetOpenAuth.OpenId.RelyingParty\OpenId\RelyingParty\OpenIdRelyingParty.cs:line 352
   --- End of inner exception stack trace ---
   at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) in d:\Temp\dotnetopenid\src\DotNetOpenAuth.OpenId.RelyingParty\OpenId\RelyingParty\OpenIdRelyingParty.cs:line 354
   at OAuthAuthorizationServer.Controllers.AccountController.LogOn(LogOnModel model, String returnUrl) in D:\Temp\dotnetopenid\samples\OAuthAuthorizationServer\Controllers\AccountController.cs:line 40
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
   at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
   at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


2012-06-15 16:08:03,490 (GMT+10) [16] DEBUG DotNetOpenAuth.Http - HTTP GET http://localhost:59722/SampleWcf2.aspx
2012-06-15 16:08:03,498 (GMT+10) [16] DEBUG DotNetOpenAuth.Yadis - HTML discovery failed to find any endpoints.
2012-06-15 16:08:03,498 (GMT+10) [16] INFO  DotNetOpenAuth.Yadis - Performing discovery on user-supplied identifier: http://localhost:59722/SampleWcf2.aspx
2012-06-15 16:08:03,498 (GMT+10) [16] DEBUG DotNetOpenAuth.Yadis - Filtering and sorting of endpoints did not affect the list.
2012-06-15 16:08:03,578 (GMT+10) [16] ERROR DotNetOpenAuth.OAuthAuthorizationServer - An unhandled exception occurred in ASP.NET processing: DotNetOpenAuth.Messaging.ProtocolException: No OpenID endpoint found. ---> System.InvalidOperationException: Sequence contains no elements
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) in d:\Temp\dotnetopenid\src\DotNetOpenAuth.OpenId.RelyingParty\OpenId\RelyingParty\OpenIdRelyingParty.cs:line 352
   --- End of inner exception stack trace ---
   at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) in d:\Temp\dotnetopenid\src\DotNetOpenAuth.OpenId.RelyingParty\OpenId\RelyingParty\OpenIdRelyingParty.cs:line 354
   at OAuthAuthorizationServer.Controllers.AccountController.LogOn(LogOnModel model, String returnUrl) in D:\Temp\dotnetopenid\samples\OAuthAuthorizationServer\Controllers\AccountController.cs:line 40
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
   at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
   at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
DotNetOpenAuth.Messaging.ProtocolException: No OpenID endpoint found. ---> System.InvalidOperationException: Sequence contains no elements
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) in d:\Temp\dotnetopenid\src\DotNetOpenAuth.OpenId.RelyingParty\OpenId\RelyingParty\OpenIdRelyingParty.cs:line 352
   --- End of inner exception stack trace ---
   at DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) in d:\Temp\dotnetopenid\src\DotNetOpenAuth.OpenId.RelyingParty\OpenId\RelyingParty\OpenIdRelyingParty.cs:line 354
   at OAuthAuthorizationServer.Controllers.AccountController.LogOn(LogOnModel model, String returnUrl) in D:\Temp\dotnetopenid\samples\OAuthAuthorizationServer\Controllers\AccountController.cs:line 40
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
   at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
   at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

strong text


回答1:


It sounds like you're confusing OAuth 2.0 authorization servers with OpenID 2.0 Providers. They are totally different. When "logging in" to the authorization server sample, which appears to be the failure point in your original question, you need to enter a valid OpenID. The URLs you were trying appear to be URLs to the OAuth 2.0 client sample, which isn't an OpenID.

You should log into the authorization server using identifiers like those supplied by the OpenIdProvider sample, or (most easily) just use "yahoo.com" if you have a Yahoo account or "tinyurl.com/googop" to log in using Google.




回答2:


Unless I'm mistaken (which isn't entirely unlikely) the AuthorizationServer sample pretty much acts as a gateway which validates OAuth requests by authorizing the user against an OpenID provider. Instead of putting the relying party's URL in, you might try putting in an OpenID provider URL. (even for testing, you should be fine using any of the public providers you may have an account with)



来源:https://stackoverflow.com/questions/11067700/dotnetopenauth-getting-the-sample-oauth-2-0-authorizationserver-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!