Last active
December 21, 2015 20:59
-
-
Save sreeharikmarar/6365470 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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