public getSessionKey ( string $token ) : string | ||
$token | string | The token after successfully connecting to Last.fm |
리턴 | string | The token key |
public function getSessionKey($token)
{
$query = $this->buildAuthCallParams(['method' => 'auth.getSession', 'token' => $token], true);
try {
$response = $this->get("/?{$query}", [], false);
return (string) $response->session->key;
} catch (Exception $e) {
Log::error($e);
return false;
}
}
/** * Serve the callback request from Last.fm. * * @param Request $request * @param Lastfm $lastfm * * @return \Illuminate\Http\Response */ public function callback(Request $request, Lastfm $lastfm) { abort_unless($token = $request->input('token'), 500, 'Something wrong happened.'); // Get the session key using the obtained token. abort_unless($sessionKey = $lastfm->getSessionKey($token), 500, 'Invalid token key.'); $this->auth->user()->savePreference('lastfm_session_key', $sessionKey); return view('api.lastfm.callback'); }