Skip to content

Instantly share code, notes, and snippets.

@sreeharikmarar
Last active December 21, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sreeharikmarar/6365470 to your computer and use it in GitHub Desktop.
Save sreeharikmarar/6365470 to your computer and use it in GitHub Desktop.
class GithubController < ApplicationController
def authorize
@github = Github.new :client_id => "app_id", :client_secret => "secret_key"
address = @github.authorize_url :redirect_uri => "http://#{request.host_with_port}/github/callback", :scope => 'repo'
redirect_to address
end
def callback
authorization_code = params[:code].to_s
@github = Github.new :client_id => "app_id", :client_secret => "secret_key"
token = @github.get_token(authorization_code)
access_token = token.token
# EX: https://api.github.com/user/repos?access_token=xxxxx
response = RestClient.get("https://api.github.com/user/repos?access_token=#{access_token}")
datas = JSON.parse(response)
puts "datas : #{datas}" # It will print the whole github response details as a json
redirect_to root_path # any path that you want to redirect the user after importing
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment