Last active
August 8, 2016 19:34
-
-
Save parthdesai93/47c6e391d013216ae270f7650bd2137d 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 SoundcloudController < ApplicationController | |
def connect | |
client = Soundcloud.new(:client_id => 'ID', | |
:client_secret => 'Secret', | |
:redirect_uri => "http://localhost:3000/login/soundcloud/callback") | |
redirect_to client.authorize_url(:scope => 'non-expiring') | |
end | |
def connected | |
# create client object with app credentials | |
client = Soundcloud.new(:client_id => 'ID', | |
:client_secret => 'Secret', | |
:redirect_uri => "http://localhost:3000/login/soundcloud/callback") | |
code = params[:code] | |
access_token = client.exchange_token(code: code) #i get error from here | |
=begin | |
client = Soundcloud.new(:access_token => access_token["access_token"]) | |
# make an authenticated call | |
soundcloud_user = client.get('/me') | |
unless User.where(:soundcloud_user_id => soundcloud_user["id"]).present? | |
User.create_from_soundcloud(soundcloud_user, access_token) | |
end | |
sign_in_user = User.where(:soundcloud_user_id => soundcloud_user["id"]) | |
#create user sessions | |
session[:user_id] = sign_in_user.first.id | |
=end | |
redirect_to root_url, notice: "Signed in!" | |
end | |
def destroy | |
session[:user_id] = nil | |
redirect_to root_url, notice: "Logged out!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment