度々質問失礼致します。
現在、laravelにてLineログイン認証機能を導入しています。
参考にしたサイト
https://github.com/SocialiteProviders/Line/blob/master/Provider.php
下記エラーで詰まっています...
Call to undefined method Laravel\Socialite\Two\User::setAccessTokenResponseBody()
<?php namespace app\Socialite; use Laravel\Socialite\Two\AbstractProvider; use Laravel\Socialite\Two\ProviderInterface; use Laravel\Socialite\Two\User; //use SocialiteProviders\Manager\OAuth2\AbstractProvider; //use SocialiteProviders\Manager\OAuth2\User; class LineProvider extends AbstractProvider implements ProviderInterface { /** * Unique Provider Identifier. */ const IDENTIFIER = 'LINE'; /** * The separating character for the requested scopes. * * @var string */ protected $scopeSeparator = ' '; /** * The scopes being requested. * * @var array */ protected $scopes = [ 'openid', 'profile', 'email', ]; /** * Get the authentication URL for the provider. * * @param string $state * * @return string */ protected function getAuthUrl($state) { return $this->buildAuthUrlFromBase( 'https://access.line.me/oauth2/v2.1/authorize', $state ); } /** * Get the token URL for the provider. * * @return string */ protected function getTokenUrl() { return 'https://api.line.me/oauth2/v2.1/token'; } /** * Get the raw user for the given access token. * * @param string $token * * @return array */ protected function getUserByToken($token) { $response = $this->getHttpClient()->get( 'https://api.line.me/v2/profile', [ 'headers' => [ 'Authorization' => 'Bearer '.$token, ], ]); return json_decode($response->getBody()->getContents(), true); } /** * Map the raw user array to a Socialite User instance. * * @param array $user * * @return \Laravel\Socialite\User */ protected function mapUserToObject(array $user) { return (new User())->setRaw($user)->map([ 'id' => $user['userId'] ?? $user['sub'] ?? null, 'nickname' => null, 'name' => $user['displayName'] ?? $user['name'] ?? null, 'avatar' => $user['pictureUrl'] ?? $user['picture'] ?? null, 'email' => $user['email'] ?? null, ]); } /** * Get the POST fields for the token request. * * @param string $code * * @return array */ protected function getTokenFields($code) { return array_merge(parent::getTokenFields($code), [ 'grant_type' => 'authorization_code', ]); } /** * @return \SocialiteProviders\Manager\OAuth2\User */ public function user() { if ($this->hasInvalidState()) { throw new InvalidStateException(); } $response = $this->getAccessTokenResponse($this->getCode()); if ($jwt = $response['id_token'] ?? null) { list($headb64, $bodyb64, $cryptob64) = explode('.', $jwt); $user = $this->mapUserToObject(json_decode(base64_decode($bodyb64), true)); } else { $user = $this->mapUserToObject($this->getUserByToken( $token = $this->parseAccessToken($response) )); } $this->credentialsResponseBody = $response; if ($user instanceof User) { $user->setAccessTokenResponseBody($this->credentialsResponseBody); } return $user->setToken($this->parseAccessToken($response)) ->setRefreshToken($this->parseRefreshToken($response)) ->setExpiresIn($this->parseExpiresIn($response)); } }
このsetAccessTokenResponseBodyメソッドは、参考にしたサイトのSocialite\ManagerのUser.phpにあるそうなのですが、
こちらには入っていません。
Socialiteに入っていないので、Managerをcomposerでインストールすればよろしいのでしょうか?....
configのapp.phpに記載しても、undefinedです。
'provider' => [ App\Socialite\SocialiteServiceProvider::class, \SocialiteProviders\Manager\ServiceProvider::class, ]
だいぶはまっていて、自分でもごっちゃになってきたので...
ぜひお助けいただければ幸いです><;
追記
Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\Models\User given, called in /Users/hxxx.yxxx/Ac/aclive/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php on line 292

回答1件
あなたの回答
tips
プレビュー