GithubHelp home page GithubHelp logo

google_oauth_calendar's Introduction

GoogleOauthCalendar

This provides a generator that installs everything you need to be able to authenticate users against their Google identity (via oauth2), and then use the google apis to start interacting with their calendars. This isn't limited to Google Calendars, but it's a nice starter example to demonstrate their services.

Rather than the individual instructions at each in each gem, and stubbing your toe a half dozen times in the process, this is a one-stop generator.

Specifically, it

  • creates a User model with name & email pulled from Google, and a place to store their access and refresh token
  • initializes omniauth to use the google-oauth2 strategy for signin
  • creates a SessionsController to react to signin/signout
  • installs a basic root controller that has view showing signin/signout links, and queries the list of the user's calendars via the google/api_client

This gem allows you to install these features after your app already exists, rather than using an application template such as rails_apps_composer. This way, it makes fewer assumptions about your other app preferences.

Configuring Google API

You need to configure an API instance at Google for your app's use. This becomes the trust link between the systems. You can use a regular google identity for this, Google Apps for Business or other paid services are not required, assuming you can deal with their usage limits.

  1. Go to to the Google API Console, and create a new project. (The name doesn't matter, but will probably match your rails project name)

  2. Go to the service tab, and enable Calendar API

  3. Go to the API Access tab, and create an OAuth 2.0 client ID

    1. pick a project name

    2. choose "web application" as the application type

    3. for "your site or hostname" choose "more options" and use

      http://localhost:3000/auth/google_oauth2/callback

  4. copy the client ID and secret into environment variables, for example

     export GOOGLE_CLIENT_ID = "YOUR_CLIENT_ID"
     export GOOGLE_CLIENT_SECRET = "YOUR_CLIENT_SECRET"
    

Installation

Add this line to your application's Gemfile:

gem 'google_oauth_calendar' , :git => '[email protected]:deafgreatdane/google_oauth_calendar.git'

And then execute:

$ bundle
$ rails generate google_oauth_calendar:install
$ rake db:migrate
$ rails server

When you click the "signin" link, you'll be redirected to google, asked to confirm your app's use of calendar APIs, then it direct back to your home page, signed in, and list your calendars.

At this point, you can remove the gem from your gemfile, since it's only the generator

Where to go from here

Now you can get to work at adding the real features using your preferred patterns. Some things you'll probably end up doing:

  • add a UserController for seeing who has connected
  • add "filter authenticate_user!" to your secure controllers
  • learn more about the calendar or other google apis via the google-api-client
  • add more "redirect URLs" to your Google API console, corresponding to your stage & production urls.
  • add error handling for chatting with Google

Feedback and contributions are welcome, just file an issue or create pull request

google_oauth_calendar's People

Contributors

deafgreatdane avatar

Stargazers

Naveen avatar Jerry Tao avatar Ajmal Afif avatar Max Mitchell avatar Greg Connour avatar Richard Ortega avatar Dmytro Kovalov (uk: Дмитро Ковальов) avatar Jonathan Gottfried avatar Raphael Caldas avatar Originate avatar Michalis Polakis avatar Jason Charnes avatar Roman Shipiev avatar  avatar  avatar Jorge Ramos avatar Yuta Miyama avatar Mike Coutermarsh avatar  avatar Larry Scott avatar Alex Bain avatar Lukas Stejskal avatar Jean-Francois Couture avatar

Watchers

Andrea Soto avatar James Cloos avatar Adrian Ene avatar Jan Hrabal avatar

google_oauth_calendar's Issues

No route matches [GET] "/auth/google_oauth2"

I have looked high and low and I appreciate your generator, but I can't for the life of me solve the problem of where the actual route for the /auth/google_oauth2 is supposed to be.

rake routes shows this.

auth_failure        /auth/failure(.:format)                sessions#failure
signout        /signout(.:format)                     sessions#destroy
signin        /signin(.:format)                      sessions#new
                /auth/:provider/callback(.:format)     sessions#create

refresh_token

So the offline access generates the refresh_token.

Are there any plans to add the request of new auth token using the refresh_token for persistent authorization?

Error when install template to do with "match"

When I try to install this template, I get this error:

rails generate google_oauth_calendar:install
/Users/salexander/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5.2/lib/action_dispatch/routing/mapper.rb:238:in add_request_method': You should not use thematchmethod in your router without specifying an HTTP method. (ArgumentError) If you want to expose your action to both GET and POST, addvia: [:get, :post]option. If you want to expose your action to GET, useget` in the router:
Instead of: match "controller#action"
Do: get "controller#action"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.