Scenario
It's more easily to log in your application via OAuth and OpenID provider in ASP.NET MVC 4 now. Microsoft has few build-in client for Microsoft, Twitter, Facebook, Google. The Google client is based on OpenID and not OAuth. That's mean you can not access Google Data API. There is a post talk about how to implement custom Google client with Google+ login via OAuth in ASP.NET MVC 4. (http://www.beabigrockstar.com/google-signin-for-asp-net-mvc/ Google+ Signin for ASP.NET MVC - Be A Big Rockstar )Register a Client ID for web application in Google Developer Console
In order to access Google Data API for web application. You need to register a Client ID to get Client ID an Client Secret for setting in your application.As above snapshot show, you need to assign redirect URIs for grap OAuth access token callback also. Here we setup Rirect URIs as
http://localhost:57271/Account/ExternalLoginCallback
Google Client Library for .NET
The Google APIs Client Library for .NET is generic .NET runtime client for Google Services. The library supports OAuth2.0 authentication, and is able to generate strongly typed client libraries for Discovery-based services.Google Client library is a higher level library for using Google Data API. You can download beta version from Nuget in visual studio.
https://www.nuget.org/packages/Google.Apis.Calendar.v3/It's more difficult to handle Google Client Library for .NET with few documents and sample now. Here, just using Google.Apis.Calendar.v3.Data namespace to our strong type class for data binding in deserialize object from API response.
private Event GoogleEventHandle(string token, string method, string requestURL, string requestBody = null) { var jsonSerializer = new JavaScriptSerializer(); var request = WebRequest.Create(requestURL) as HttpWebRequest; request.KeepAlive = true; request.ContentType = "application/json"; request.Method = method; request.Headers.Add("Authorization", "Bearer " + token); if(requestBody != null) { Stream ws = request.GetRequestStream(); using (var streamWriter = new StreamWriter(ws, new UTF8Encoding(false))) { streamWriter.Write(requestBody); } } var response = request.GetResponse(); var stream = new StreamReader(response.GetResponseStream()); var googleEvent = Newtonsoft.Json.JsonConvert.DeserializeObjectAbove is methods how we are accessing Google Calendar v3 API via webrequest.(stream.ReadToEnd().Trim()); return googleEvent; } private Event CreateGoogleEvent(string token, string calendarId, string requestBody) { var requestURL = string.Format("https://www.googleapis.com/calendar/v3/calendars/{0}/events", calendarId); return GoogleEventHandle(token, "POST", requestURL, requestBody); }
MVC view
Now, we are be able to access Google Calendar API via OAuth. Nest step, we will create a simple CRUD UI by AngularJS.
The Google Event we created and save to database also.
You should choose which calendar you want to create a new event.
You can modify event anytime you want.
What you will see in your Google Calendar.
Summary
- It a good topic to discuss where do you store the Access token from Google OAuth. Session or database?
- Google Client Library for .NET is a convienient library to access Google Data API with OAuth include. It's still in developing and i hope that there have more documents and samples to show how to use it.
Reference
- http://www.asp.net/mvc/tutorials/security/using-oauth-providers-with-mvc (Using OAuth Providers with MVC 4 : The Official Microsoft ASP.NET Site)
- http://www.beabigrockstar.com/google-signin-for-asp-net-mvc/ (Google+ Signin for ASP.NET MVC - Be A Big Rockstar)
- http://coding.anyun.tw/2012/03/14/asp-net-mvc-using-oauth-2-0-connect-google-api/ (【oAuth 2.0 實作系列】ASP.Net MVC 實作使用 oAuth 2.0 連接 Google API « Coding 之路,不由分說)
- https://code.google.com/p/google-api-dotnet-client/ (google-api-dotnet-client - Google APIs Client Library for .NET - Google Project Hosting)
Github repository
As always, all source code can be found in Github in the repository
https://github.com/cage1016/ASPNETMvc4GoogleOAuth
https://github.com/cage1016/ASPNETMvc4GoogleOAuth
work like a charm.
ReplyDeleteAwesome solution. simple and did the job.
This comment has been removed by the author.
ReplyDeleteyour github solution was worked.but does not create a event and not sync my google calender
ReplyDeleteNot suitable for me because your github solution was worked.but does not create a event and not sync my google calender
ReplyDeleteBig Data and Hadoop is an ecosystem of open source components that fundamentally changes the way enterprises store, process, and analyze data.
ReplyDeletepython training in bangalore
aws training in bangalore
artificial intelligence training in bangalore
data science training in bangalore
machine learning training in bangalore
hadoop training in bangalore
devops training in bangalore
corporate training companies
ReplyDeletecorporate training companies in mumbai
corporate training companies in pune
corporate training companies in delhi
corporate training companies in chennai
corporate training companies in hyderabad
corporate training companies in bangalore
Gaining Python certifications will validate your skills and advance your career.
ReplyDeletepython certification
Thanks for posting keep updating. We are Excellent company for
ReplyDeleteWebsite Development Company in Delhi | Website Designing Company in Delhi
Thanks for provide great informatic and looking beautiful blog
ReplyDeletepython training in bangalore | python online training
aws online training in bangalore | aws online training
artificial intelligence training in bangalore | artificial intelligence online training
machine learning training in bangalore | machine learning online training
data science training in bangalore | data science online training
Excellent content! Thanks for sharing such a useful information.
ReplyDeletePython Training In Pune
python training institute in pune
I was very happy to find this site. I really enjoyed reading this article today and think it might be one of the best articles I have read so far. I wanted to thank you for this excellent reading !! I really enjoy every part and have bookmarked you to see the new things you post. Well done for this excellent article. Please keep this work of the same quality.
ReplyDeleteData Science Course in Bangalore
The content of this website was really informative. 50 High Quality Backlinks for just 50 INR
ReplyDelete2000 Backlink at cheapest
5000 Backlink at cheapest
Boost DA upto 15+ at cheapest
Boost DA upto 25+ at cheapest
Boost DA upto 35+ at cheapest
Boost DA upto 45+ at cheapest
Informative blog
ReplyDeletedata scientist course in Bangalore
Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
ReplyDeleteData Science Course in Bangalore
i am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
ReplyDeletebest data science courses in bangalore
Annabelle loves to write and has been doing so for many years.Cheapest and Fastest Link Building and Link Indexing Service TECKUM IS ALL ABOUT TECH NEWS AND MOBILE REVIEWS. Best GPL Store
ReplyDeleteAnnabelle loves to write and has been doing so for many years.Cheapest and fastest Backlink Indexing Best GPL Store TECKUM IS ALL ABOUT TECH NEWS AND MOBILE REVIEWS
ReplyDeletei am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.
ReplyDeletedata scientist course in bangalore
I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page!
ReplyDeletedata analytics course in bangalore
I want to leave a little comment to support and wish you the best of luck.we wish you the best of luck in all your blogging enedevors.
ReplyDeletedata analytics courses in bangalore
I am glad to discover this page. I have to thank you for the time I spent on this especially great reading !! I really liked each part and also bookmarked you for new information on your site.
ReplyDeleteData Science Training in Chennai
I am a new user of this site, so here I saw several articles and posts published on this site, I am more interested in some of them, hope you will provide more information on these topics in your next articles.
ReplyDeletedata analytics training in bangalore
Impressive blog to be honest definitely this post will inspire many more upcoming aspirants. Eventually, this makes the participants to experience and innovate themselves through knowledge wise by visiting this kind of a blog. Once again excellent job keep inspiring with your cool stuff.
ReplyDeletedata science certification in bangalore
Thank you so much for ding the impressive job here, everyone will surely like your post.
ReplyDeletebusiness analytics course
Great blog,
ReplyDeleteDigital Marketing Course in Hyderabad
ReplyDelete
Not just theory, we help you launch a live campaign, so you gain practical knowledge on Adwords and crack the job or certifications easily.
ReplyDeleteImpressive. Your story always bring hope and new energy. Keep up the good work.
ReplyDeletedata science training
Impressive. Your story always bring hope and new energy. Keep up the good work.
ReplyDeleteofficialPanda
Impressive blog to be honest definitely this post will inspire many more upcoming aspirants. Eventually, this makes the participants to experience and innovate themselves through knowledge wise by visiting this kind of a blog. Once again excellent job keep inspiring with your cool stuff.
ReplyDeletefun138
Informative blog
ReplyDeleteai training in hyderabad
Great Post Thanks For Sharing, have a look at it for free digital marketing training..
ReplyDeletedigital marketing training in hyderabad
digital marketing course in hyderabad
Welcome to CapturedCurrentNews – Latest & Breaking India News 2021
ReplyDeleteHello Friends My Name Anthony Morris.latest and breaking news drupepower.com
Sir apki website par original content diya jata ha muje apke dyra di gyi jankari bhout acchi lagi agar ap moje yh bta ske ki agla airtical kab ayega your very very knowledge full airtical thanks sir:
ReplyDeleteshort story in hindi motivational
Glad to chat your blog, I seem to be forward to more reliable articles and I think we all wish to thank so many good articles, blog to share with us.
ReplyDeletedata science training
Informative blog
ReplyDeletebusiness analytics course in agra
Here is the best AWS Solution Architect Training in Chennai from Infycle Technologies, the best software training institute in Chennai. And we circulate the topmost demanding courses like Graphic Design and Animation, Power BI, Combo of Python + Oracle with Java, Blockchain, Artificial Intelligence, Big data, Azure Certifications, Python, Selenium Automation Testing, Machine Learning, Medical Coding, etc., with 100+ Live Practical Sessions. Reach us on call at +91-7504633633, +91-7502633633 for best offers.
ReplyDeletewow, great, I was wondering how to cure acne naturally. and found your site by google, learned a lot, now i’m a bit clear. I’ve bookmark your site and keep us updated.
ReplyDeletefull stack web development course in malaysia
Amazingly by and large very interesting post. I was looking for such an information and thoroughly enjoyed examining this one. Keep posting.
ReplyDeleteAn obligation of appreciation is all together for sharing.data analytics course in gwalior
This post is easy to peruse and acknowledge without forgetting about any subtleties. Extraordinary work!https://360digitmg.com/course/certification-program-on-digital-marketing
ReplyDeleteI would also motivate just about every person to save this web page for any favorite assistance to assist posted the appearance. data science training in surat
ReplyDeleteThis is an excellent post I seen thanks to share it. It is really what I wanted to see hope in future you will continue for sharing such a excellent post.
ReplyDeletecyber security certification malaysia