Login to PlayStation network using a refresh token or 2FA.

@param string $ticketUuidOrRefreshToken Ticket UUID for 2FA, or the refresh token.
@param string $code 2FA code sent to your device (ignore if using refresh token).
@return void
434907
public function login(string $ticketUuidOrRefreshToken, string $code = null) 
    {
        if ($code === null) {
            $response = $this->httpClient()->post(self::AUTH_API . 'oauth/token', [
                "app_context" => "inapp_ios",
                "client_id" => self::CLIENT_ID,
                "client_secret" => self::CLIENT_SECRET,
                "refresh_token" => $ticketUuidOrRefreshToken,
                "duid" => self::DUID,
                "grant_type" => "refresh_token",
                "scope" => self::SCOPE
            ]);
        } else {
            $response = $this->httpClient()->post(self::AUTH_API . 'ssocookie', [
                'authentication_type' => 'two_step',
                'ticket_uuid' => $ticketUuidOrRefreshToken,
                'code' => $code,
                'client_id' => self::CLIENT_ID
            ]);

            $npsso = $response->npsso;

            $response = $this->httpClient()->get(self::AUTH_API . 'oauth/authorize', [
                'duid' => self::DUID,
                'client_id' => self::CLIENT_ID,
                'response_type' => 'code',
                'scope' => self::SCOPE,
                'redirect_uri' => 'com.playstation.PlayStationApp://redirect'
            ], [
                'Cookie' => 'npsso=' . $npsso
            ]);

            if (($response instanceof Response) === false) {
                throw new \Exception('Unexpected response');
            }

            $grant = $response->getHeaderLine('X-NP-GRANT-CODE');

            if (empty($grant)) {
                throw new \Exception('Unable to get X-NP-GRANT-CODE');
            }

            $response = $this->httpClient()->post(self::AUTH_API . 'oauth/token', [
                'client_id' => self::CLIENT_ID,
                'client_secret' => self::CLIENT_SECRET,
                'duid' => self::DUID,
                'scope' => self::SCOPE,
                'redirect_uri' => 'com.playstation.PlayStationApp://redirect',
                'code' => $grant,
                'grant_type' => 'authorization_code'
            ]);

        }

        $this->accessToken = $response->access_token;
        $this->refreshToken = $response->refresh_token;
        $this->expiresIn = $response->expires_in;

        $handler = \GuzzleHttp\HandlerStack::create();
        $handler->push(Middleware::mapRequest(new TokenMiddleware($this->accessToken(), $this->refreshToken(), $this->expireDate())));

        $newOptions = array_merge(['handler' => $handler], $this->options);
    
        $this->httpClient = new HttpClient(new \GuzzleHttp\Client($newOptions));
    }
1092505
protected function setAuthCode($oauthCode, $accountId, $redirectUri, $expires = null, $scope = null)
    {
        if (null === $account = $this->app['repo.api-accounts']->find($accountId)) {
            throw new RuntimeException(sprintf('Account with id %s is not valid', $accountId));
        }
        $code = $this->app['manipulator.api-oauth-code']->create($account, $redirectUri, $expires, $scope);
        $this->app['manipulator.api-oauth-code']->setCode($code, $oauthCode);

        return $this;
    }
963741
public function execute($code = null) {

		if(null !== $code && false === ('-' . intval($code) == '-' . $code)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($code)), E_USER_ERROR);
		}

		$this -> setUrl();

		if(null !== $this -> seconds) {
			return Response :: addHeader('refresh', sprintf('%d;url=%s', $this -> seconds, $this -> url), $code);
		}

		Response :: addHeader('Location', $this -> url, $code);
	}
192084
public function updateCode($code, $card_id, $new_code)
    {
        if (empty($code) || empty($card_id) || $new_code) {
            return false;
        }

        $result = $this->httpPost(static::WECHAT_CARD_CODE_UPDATE_URL . 'access_token=' . $this->getAccessToken(), [
            'code' => $code,
            'card_id' => $card_id,
            'new_code' => $new_code
        ]);

        return isset($result['errmsg']) && $result['errmsg'] === 'ok' ? true : false;
    }
234088
public function apply($code)
    {
        if (!auth()->check()) {
            throw new UnauthenticatedException;
        }

        try {
            if ($promocode = $this->check($code)) {
                if ($this->isSecondUsageAttempt($promocode)) {
                    throw new AlreadyUsedException;
                }

                $promocode->users()->attach(auth()->id(), [
                    'promocode_id' => $promocode->id,
                    'used_at' => Carbon::now(),
                ]);

                return $promocode->load('users');
            }
        } catch (InvalidPromocodeException $exception) {
            //
        }

        return false;
    }
1133033
public function requestAccessToken($authorizationCode)
    {
        $parameters = [
            'client_id' => $this->getClientId(),
            'client_secret' => $this->getClientSecret(),
            'code' => $authorizationCode,
            'grant_type' => 'authorization_code',
            'redirect_uri' => $this->getRedirectUri(),
        ];

        $response = $this->request->account('POST', '/api/token', $parameters, []);
        $response = $response['body'];

        if (isset($response->refresh_token) && isset($response->access_token)) {
            $this->refreshToken = $response->refresh_token;
            $this->accessToken = $response->access_token;
            $this->expirationTime = time() + $response->expires_in;
            $this->scope = isset($response->scope) ? $response->scope : $this->scope;

            return true;
        }

        return false;
    }
1163322
public function getAuthorizationCode($code)
	{
		// auth model
		$authorizationCode = \Components\Developer\Models\Authorizationcode::oneByCode($code);

		// fetch by code
		if (!$authorizationCode->get('id'))
		{
			return false;
		}

		// get the application's client id
		$application = \Components\Developer\Models\Application::oneOrFail($authorizationCode->get('application_id'));
		$authorizationCode->set('client_id', $application->get('client_id'));

		// format expires to unix timestamp for authorization code grant type
		$authorizationCode->set('expires', with(new Date($authorizationCode->get('expires')))->toUnix());

		// return code
		return $authorizationCode->toArray();
	}
723292
public function actionConnect($code) {
    $account = Account::find()->byCode($code)->one();

    if ($account === null || $account->getIsConnected()) {
      throw new NotFoundHttpException();
    }

    /** @var User $user */
    $user = Yii::createObject([
      'class' => User::className(),
      'scenario' => 'connect',
      'username' => $account->username,
      'email' => $account->email,
    ]);

    $event = $this->getConnectEvent($account, $user);

    $this->trigger(self::EVENT_BEFORE_CONNECT, $event);

    if ($user->load(Yii::$app->request->post()) && $user->create()) {
      $account->connect($user);
      $this->trigger(self::EVENT_AFTER_CONNECT, $event);
      Yii::$app->user->login($user, $this->module->rememberFor);
      return $this->goBack();
    }

    return $this->render('connect', [
      'model' => $user,
      'account' => $account,
    ]);
  }
1367917
public function redeem($accountCode) {
    $doc = $this->createDocument();
    $root = $doc->appendChild($doc->createElement('recipient_account'));
    $root->appendChild($doc->createElement('account_code', $accountCode));
    $uri = Recurly_GiftCard::uriForGiftCard($this->redemption_code) . '/redeem';

    $this->_save(Recurly_Client::POST, $uri, $this->renderXML($doc));
  }
838475
public function reset($userId = null, $code = null)
    {
        try {
            if (post('postback')) {
                return $this->reset_onSubmit();
            }

            if (!$userId || !$code) {
                throw new ApplicationException(trans('backend::lang.account.reset_error'));
            }
        }
        catch (Exception $ex) {
            Flash::error($ex->getMessage());
        }

        $this->vars['code'] = $code;
        $this->vars['id'] = $userId;
    }
886378
public function authenticateWithAuthCode($authCode)
    {
        $accessToken = $this->fetchAccessTokenWithAuthCode($authCode);
        $this->getLogger()->debug('Access token with auth code: ' . json_encode($accessToken));

        return !array_key_exists('error', $accessToken);
    }
771301
public function authenticate($code = null)
    {
        if (null === $code) {
            if (isset($_GET['code'])) {
                $code = $_GET['code'];
            }
        }

        $url = 'https://oauth.vk.com/access_token?' . http_build_query(array(
                'client_id' => $this->getClientId(),
                'client_secret' => $this->getClientSecret(),
                'code' => $code,
                'redirect_uri' => $this->getRedirectUri(),
            ));

        $token = $this->curl($url);
        $decodedToken = json_decode($token, true);
        $decodedToken['created'] = time(); // add access token created unix timestamp to array

        $this->setAccessToken($decodedToken);

        return $this;
    }
290367
public function expireAuthorizationCode($code)
	{
		// auth model
		$authorizationCode = \Components\Developer\Models\Authorizationcode::oneByCode($code);

		// fetch by code
		if (!$authorizationCode->get('id'))
		{
			return false;
		}

		return $authorizationCode->destroy();
	}
450999
public function checkCode(UserInterface $user, $code)
    {
        return $this->authenticator->checkCode($user->getTwoStepVerificationCode(), $code);
    }
445057
public function resetPassword($code,$password)
    {
        try
        {
            $user =  $this->sentry->findUserByResetPasswordCode($code);
            $user->password = $password;
            $user->save();

            $this->event->fire('users.password.reset',array($user));

            return $user;
        }
        catch (SentryUserNotFoundException $e)
        {
            throw new UserNotFoundException($e->getMessage());
        }
    }
195477
public function code2session($code){
        if (empty($code)){
            if ($this->business_interface) $this->business_interface->log('code2session code exception');
            return false;
        }
        $url = self::API_CODE2SESSION."appid={$this->config['app_id']}&secret={$this->config['app_secret']}&js_code={$code}&grant_type=authorization_code";
        return $this->curl($url);
    }
1289791
public function findUserByPersistenceCode($code)
    {
        $persistence = $this->findByPersistenceCode($code);

        if ($persistence)
        {
            return $persistence->getUser();
        }

        return false;
    }