/** * @param array $apiConfig * @param array $config */ private function registerSoundcloudFacade(array $apiConfig, array $config) { $this->app->singleton(SoundcloudFacade::class, function () use($apiConfig, $config) { $soundcloud = new SoundcloudFacade($apiConfig['client_id'], $apiConfig['client_secret'], $apiConfig['callback_url']); if ($config['auto_connect']) { $soundcloud->userCredentials($config['username'], $config['password']); } return $soundcloud; }); $this->app->alias(SoundcloudFacade::class, 'Soundcloud'); }
/** * Send an empty request here * * The API will forward the request to the SoundCloud API, prompt the user to login * Return the token and login URL to the consumer for reference * We are now logged in with SoundCloud, and can start scraping user data */ public function get() { $callback = 'http://' . Config::getConfig('Hostname') . '/User/Auth/Login/SoundCloud/index.php'; $facade = new SoundcloudFacade(Config::getConfig('SoundCloudAppId'), Config::getConfig('SoundCloudSecret'), $callback); $url = $facade->getAuthUrl(); if (isset($_GET['code'])) { $code = $_GET['code']; $token = $facade->codeForToken($code); $rBody = $token->bodyArray(); $accessToken = $rBody['access_token']; $me = $facade->get('/me')->request(); $scBody = $me->bodyArray(); $clientId = $scBody['id']; $body['soundcloudAccessToken_text'] = $accessToken; $body['soundcloudUserId_text'] = $clientId; $body['soundcloudName_text'] = $scBody['full_name']; $this->request->response->body = $body; $this->request->response->code = r_success; return $this->request; } else { header('Location: ' . $url); } }
/** * Show the application welcome screen to the user. * * @return Response */ public function index(SoundcloudFacade $soundcloud) { $url = $soundcloud->getAuthUrl(array('scope' => 'non-expiring')); return view('welcome')->with('url', $url); }