Flarum\Forum\AuthenticationResponseFactory::make PHP Method

make() public method

public make ( Psr\Http\Message\ServerRequestInterface $request, array $identification, array $suggestions = [] )
$request Psr\Http\Message\ServerRequestInterface
$identification array
$suggestions array
    public function make(Request $request, array $identification, array $suggestions = [])
    {
        if (isset($suggestions['username'])) {
            $suggestions['username'] = $this->sanitizeUsername($suggestions['username']);
        }
        $user = User::where($identification)->first();
        $payload = $this->getPayload($identification, $suggestions, $user);
        $response = $this->getResponse($payload);
        if ($user) {
            $session = $request->getAttribute('session');
            $this->authenticator->logIn($session, $user->id);
            $response = $this->rememberer->rememberUser($response, $user->id);
        }
        return $response;
    }

Usage Example

 /**
  * @param Request $request
  * @return \Psr\Http\Message\ResponseInterface|RedirectResponse
  */
 public function handle(Request $request)
 {
     $redirectUri = (string) $request->getAttribute('originalUri', $request->getUri())->withQuery('');
     $server = new Twitter(['identifier' => $this->settings->get('flarum-auth-twitter.api_key'), 'secret' => $this->settings->get('flarum-auth-twitter.api_secret'), 'callback_uri' => $redirectUri]);
     $session = $request->getAttribute('session');
     $queryParams = $request->getQueryParams();
     $oAuthToken = array_get($queryParams, 'oauth_token');
     $oAuthVerifier = array_get($queryParams, 'oauth_verifier');
     if (!$oAuthToken || !$oAuthVerifier) {
         $temporaryCredentials = $server->getTemporaryCredentials();
         $session->set('temporary_credentials', serialize($temporaryCredentials));
         $session->save();
         // Second part of OAuth 1.0 authentication is to redirect the
         // resource owner to the login screen on the server.
         $server->authorize($temporaryCredentials);
         exit;
     }
     // Retrieve the temporary credentials we saved before
     $temporaryCredentials = unserialize($session->get('temporary_credentials'));
     // We will now retrieve token credentials from the server
     $tokenCredentials = $server->getTokenCredentials($temporaryCredentials, $oAuthToken, $oAuthVerifier);
     $user = $server->getUserDetails($tokenCredentials);
     $identification = ['twitter_id' => $user->uid];
     $suggestions = ['username' => $user->nickname, 'avatarUrl' => str_replace('_normal', '', $user->imageUrl)];
     return $this->authResponse->make($request, $identification, $suggestions);
 }
All Usage Examples Of Flarum\Forum\AuthenticationResponseFactory::make