Giter VIP home page Giter VIP logo

google_oauth's Introduction

README

Google Oauth without any Library Files ๐Ÿ˜ƒ :

Alt text

Steps:

1.Go to https://console.developers.google.com

2.Create New Project

3.Get your app client_id and client_secret id

Google Login for Web and Mobile Devices Using Ruby on Rails :

include the gem in your Gemfile:

gem 'rest-client'

And then execute:

$ bundle install

Steps:

1.rails g model oauth

2.rake db:migrate

3.rails g controller oauth google_oauth

google_oauth Functions :

Oauth.rb File

 # Get accesstoken 
  def self.googleAccessTokenCheckWithCode(code,redirect_uri)
  
    code = URI.decode(code)
    user = Hash.new
    begin
      params = {"code" => code, 'client_id' => '1234', "client_secret" => "1234" , "redirect_uri" => redirect_uri , "grant_type" => "authorization_code"}
      response = RestClient.post 'https://www.googleapis.com/oauth2/v3/token', params
      token_res = JSON.parse(response.body)
      accessToken = token_res["access_token"]
      user = googleAccessTokenCheck(accessToken)
      return user
    rescue Exception => e
      user["message"] = e.message
      user["status"] = false
    end
    return user

 end

# Get information 
 def self.googleAccessTokenCheck(accessToken)
 
     require 'rest_client'
     response = ""
     user = Hash.new
     begin
      response = RestClient.get 'https://www.googleapis.com/oauth2/v2/userinfo?token_type=Bearer&access_token='+ accessToken
      if (response.code == 200)
        user_deta = JSON.parse(response.body)
        user["unique_id"] = user_deta["id"]
        user["name"] = user_deta["name"]
        user["email"] = user_deta["email"]
        user["provider"] = "google"
        user["access_token"] = accessToken
        user["status"] = true
      end
     rescue Exception => e
	    user["message"] = e.message
	    user["status"] = false
     end
    return user

end

routes.rb File:

post 'oauth' => "oauth#google_oauth"

Sample Response :

Alt text

google_oauth's People

Watchers

James Cloos avatar Anas Poovalloor avatar

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.