How can I get started using OpenID/OAuth with my WebMatrix site?
Asked Answered
B

3

6

If I misuse or confuse the terms OpenID and OAuth, I apologize, I am still new to this whole decentralized login process.

I have been trying for days now to get my site (built in WebMatrix) to recognize a Google login. The problem is I need this line of code (from what I've researched) in my _AppStart.cshtml file:

OAuthWebSecurity.RegisterGoogleClient();

But when I try to run this site after this statement is in place, I simply get a server error stating that OAuthWebSecurity.RegisterGoogleClient(); does not exist in the current context.

I thought I might need the OAuth library, a different helper, or some other package, but the only relevant package I see (Microsoft WebPages OAuth library 2.0.20710.0) I can't get, because WebMatrix doesn't support the version of NuGet it says that I need (2.0).

I have never used this method for a log in before and I want to learn how as I build this functionality for my clients. What I do not want to do is open up the starter template, and copy my files over. I have a problem using code that I don't understand. I feel that this would be a terrible habit for me to get into (it took some convincing myself before I would even use jQuery plug-ins). It also might bear mentioning that I will not be using any other third party service for this login. We use gmail for our employees' company email accounts so I need only Google logins for this solution.

Things I have tried:

  • Googling for other scenarios like mine. Fails because no relevant search results are found (i.e., I am unable to find results that match my scenario)
  • Searching for earlier versions of the Microsoft WebPages OAuth library 2.0.20710.0 package. Fails because my search returns no such packages.
  • Using OAuthWebSecurity.RegisterOpenIDClient(BuiltInOpenIDClient.Google); instead of OAuthWebSecurity.RegisterGoogleClient(); Fails for the same reason as when using OAuthWebSecurity.RegisterGoogleClient();
  • Visiting Site Administration and downloading the OAuth Library. Fails because NuGet needs an update
  • Update Nuget Fails because of what is mentioned here (apparently, a known bug for WebMatrix): http://forums.asp.net/t/1836913.aspx/1?Error+updating+DotNetOpenAuth+updates+with+NuGet+Gallery
  • Opening up the Starter Site Template, which already has OAuth built in and functional.Fails to teach me as to why this site recognizes OAuthWebSecurity.RegisterGoogleClient() and mine doesn't, because there is no clear way (that I am aware of) to tell what pacakages, updates, and/or versions of third party software might be different.
  • Creating a new Starter Site and copying any OAuth based missing files from the *"App_Data"* and "bin" folders. Fails in that no behavioral changes were observed.

-----------------------------------------UPDATE----------------------------------------

So far, to date, the best solution for this problem, at least for me, has been to just use the "Starter Site" template in WebMatrix, whether I like it or not.

One of my biggest worries for doing this, however, was that there were so many extraneous files that I wasn't sure what I could and couldn't delete to keep the site clean while still leaving the OAuthWebSecurity() class fully accessible and functional. I have, however kept only the "bin" and "App_Data" folders (including all of their contents, of course) from the "Starter Site" template and deleted everything else (including the web.config file) before moving my files over, and this has appeared to work very well for me, so far.

Using the above mentioned steps, I have kept my site clean of unnecessary code, while still having access to the OAuthWebSecurity() class.

In the future (I imagine when WebMatrix 3 is released) this bug will probably be fixed and a simple admin site install of the OAuth library will not require a version of NuGet that WebMatrix does not support, but until then, this has been the best answer for me.

Beaded answered 28/3, 2013 at 13:56 Comment(1)
Excellent question. Sorry I don't have any ideas.Bashaw
P
2

Does this GitHub project help : WorldDomination.Web.Authentication ??

enter image description here

there's also an MVC and NancyFX nuget package which does some auto wiring up, if that takes your fancy.

DISCLAIMER: I've never tried this in Webmatrix and will never plan on trying it, in that. That said, it might still work! :)

Primrosa answered 28/3, 2013 at 14:8 Comment(11)
Thanks for the help, but I'm just going to be honest. I have no idea what I'm supposed to do with this. I think if I type that command into anything and hit enter, the universe will collapse on itself.Beaded
All joking aside, I really can't think of any WebMatrix interface that would accept a command like that. Also, I've generally found that solutions outside of the environment of WebMatrix seldom work within the environment of WebMatrix. I have irreversibly broken things this way before.Beaded
While this answer has yet to solve my problem, I think I have to +1 this, because it very well may be the closest solution to this problem out there, to date.Beaded
Sorry @Beaded - that's a NuGet package. In WebMatrix, can you find a NuGet GUI? If so, search for WorldDomination.Web.Authentication etc.. and see if that can get 'added' to your project. (I never use the NuGet GUI in visual studio, just the NuGet package window, in visual studio).Primrosa
Ok, I will try that and let you know! Thnx!Beaded
Well, I was able to search for (and subsequently install) WorldDomination.Web.Authentication, however the method call OAuthWebSecurity.RegisterGoogleClient(); is still causing a YSOD for the same reason as before (OAuthWebSecurity.RegisterGoogleClient(); does not exist in the current context), so I can assume that this is unsuccessful.Beaded
lol dude. do NOT call that method :) that's not my code (provided in the nuget package). That's the other code. my package replaces that code-call.Primrosa
xD OIC... You'll have to forgive me, I told you I am new to this whole decentrilized login approach, and I didn't realize this was code you had written. What then, should I use? Is there a link that can get me working with this package?Beaded
/me points up to the FIRST LINE in my answer :) :) also.. the samples are ure using the latest unstable nuget package. (at the time of me posting this comment).Primrosa
LOL my apologies again, it has been a long weekend :) I am checking into that now, as well. One thing though, I do not understand what you mean when you say the samples are ure using the latest unsable nuget packageBeaded
Nice solution, but I'm afraid I don't have enough technical knowledge to implement this solution. I simply don't understand how your package integrates into the WebMatrix environment. Let me know if you come up with any other ideas, and thanks again for all your help!Beaded
S
1

Have you tried following package?

PM> Install-Package Microsoft.AspNet.WebPages.OAuth
Santee answered 11/4, 2014 at 14:26 Comment(0)
M
-1

Install the Microsoft.AspNet.WebPages.OAuth package.

You can install it using the Package Manager Console, or in the GUI Package Manager.

Mattingly answered 15/10, 2015 at 4:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.