Monday, September 15, 2014

Google OAuth 2 - The Hard Way

So... Google has deprecated their old single signon code. Unfortunately I'd added that code to 3 different applications. So, we need to move forward!


I tried using the Microsoft WebPages OAuth Library, but the Google provider wouldn't work properly. Tried following the directions here

http://www.beabigrockstar.com/blog/google-signin-for-asp-net-mvc/

... but I was too stupid to "get it" and make it work. Getting weird errors on Google's end. I was already on 2 urgent projects, and now I have to make our Google login work again. It's just web requests, right? I can do some requests, no biggie. Found this site...

https://developers.google.com/oauthplayground/

which is everything the Google OAuth documentation isn't. Gave me everything I needed! Used a lot of code from Jerrie Peelser's blog (http://www.beabigrockstar.com/) which was a huge help. I'm thinking maybe the permissions from the Google dev site just hadn't propagated. Regardless, I created a helper class that just "does it".

You can modify it to suit your needs.

The "GetLoginRedirectUrl" code can be modified to specify which API's you want to access. The "GetAuthenticatedUserEmail" method is just a stupid simple method I use to get the email address. You can request any API that you put in the "GetAuthenticatedUserEmail" method no problem.

I hope you find this useful!