Create completely fresh Access + Refresh tokens.

@TODO Implement proper error handling

@return array
6690
protected function createNewTokens()
    {
        $logger = $this->getLogger();
        $logger->debug('Starting request to create fresh access & refresh tokens');

        $body = [
            'client_id' => 'anonymous',
            'grant_type' => 'password',
            'response_type' => 'token',
            'scope' => 'openid',
            'username' => $this->credentials->getUsername(),
            'password' => $this->credentials->getPassword(),
        ];

        $response = $this->sendPostRequest($body);

        $logger->debug('Successfully retrieved new access & refresh tokens', $response);

        return [
            'accessToken' => new Token(
                $response['access_token'],
                $this->tokenExtractor->extract($response['access_token'])
            ),
            'refreshToken' => new Token(
                $response['refresh_token'],
                $this->tokenExtractor->extract($response['refresh_token'])
            ),
        ];
    }
800844
public function requestAccessTokenRefresh($refreshToken)
    {
        $params = array(
            'refresh_token' => $refreshToken,
            'grant_type' => 'refresh_token',
            'scope' => $this->_getScope()
        );

        return $this->_makeRequest($this->_tokenEndPoint, $params);
    }
989288
public function getRefreshToken()
    {
        if ($this->has('refresh_token')) {
            $token = $this->get('refresh_token');

            return Crypt::decrypt($token);
        }

        throw new MissingRefreshTokenException(sprintf('No refresh token stored in current session. Verify you have added refresh_token to your scope items on your connected app settings in Salesforce.'));
    }
877852
public function refreshAccessToken(string $refresh_token): void
    {
        $data = [
            'appid' => $this->app_id,
            'grant_type' => 'refresh_token',
            'refresh_token' => $refresh_token,
        ];
        $url = self::REFRESH.http_build_query($data);
        $data = json_decode($this->curl->get($url));

        $access_token = $data->access_token;
        $expires_in = $data->expires_in;
        $refresh_token = $data->refresh_token;
        $open_id = $data->openid;
        $scope = $data->scope;
    }
665509
public function refreshAccessToken($refresh_token = null) {
        $return = array();
        if ($refresh_token) {
            // todo get access_token via refresh_token request
            $params['client_id']     = $this->getClientID();
            $params['client_secret'] = $this->getClientSecret();
            $params['redirect_uri']  = $this->getRedirectUri();
            $params['grant_type']    = 'refresh_token';
            $params['scope']         = '';
            $params['state']         = '';
            $params['refresh_token'] = $refresh_token;
            $return = (array) json_decode($this->makeRequest($this->getTokenURL(), $params));
        }
        if (is_array($return) && isset($return['access_token'])) {
            $this->session = $return;
            if (isset($return['access_token'])) {
                $this->setAccessToken($return['access_token']);
            }
            if (isset($return['refresh_token'])) {
                $this->setRefreshToken($return['refresh_token']);
            }
        } else {
            // No success! Defaults to
            $this->setAccessToken($this->getClientID());
        }
        return $this->getAccessToken();
    }
331842
public function freshen()
    {
        if (! isset($this->endpoints['all'])) {
            return \React\Promise\reject(new \Exception('You cannot freshen this repository.'));
        }

        $deferred = new Deferred();

        $this->http->get(
            $this->replaceWithVariables(
                $this->endpoints['all']
            )
        )->then(function ($response) {
            $this->fill([]);

            foreach ($response as $value) {
                $value = array_merge($this->vars, (array) $value);
                $part = $this->factory->create($this->part, $value, true);

                $this->push($part);
            }
        }, function ($e) use ($deferred) {
            $deferred->reject($e);
        });
    }
199279
public function create()
	{
		// create a new session
		$this->keys['session_id']	= $this->_new_session_id();
		$this->keys['previous_id']	= $this->keys['session_id'];	// prevents errors if previous_id has a unique index
		$this->keys['ip_hash']		= md5(\Input::ip().\Input::real_ip());
		$this->keys['user_agent']	= \Input::user_agent();
		$this->keys['created'] 		= $this->time->get_timestamp();
		$this->keys['updated'] 		= $this->keys['created'];

		return $this;
	}
1252891
public function connect() {
		if (! isset ( $this->apiTokens )) {
			$this->apiTokens = $this->_loadApiTokens ();
		}
		$token = $this->apiTokens->addToken ();
		$this->_addHeaderToken ( $token );
		return [ "access_token" => $token,"token_type" => "Bearer","expires_in" => $this->apiTokens->getDuration () ];
	}
778306
public function getAccessTokenData()
    {
        if ($this->isOauth1()) {
            return array(
                'access_token'        => $this->_access_token,
                'access_token_secret' => $this->_access_token_secret,
                'expires'             => $this->_expires,
            );
        }

        return array(
            'access_token'  => $this->_access_token,
            'expires'       => $this->_expires,
            'token_type'    => $this->_token_type,
            'refresh_token' => $this->_refresh_token
        );
    }
1120704
protected function createAuthData()
    {
        return [
            'clientId' => $this->config['client_id'],
            'apiKey' => $this->config['api_key'],
            'requestTime' => time(),
            'sha' => sha1($this->config['api_key'] . $this->config['client_id'] . $this->config['api_secret'])
        ];
    }
846344
public function refresh()
    {
        //Create the namespace if it doesn't exist
        $namespace = $this->getNamespace();

        if(!isset($_SESSION[$namespace])) {
            $_SESSION[$namespace] = array();
        }

        //Re-load the session containers
        foreach($this->_containers as $container)
        {
            $namespace = $this->getNamespace();
            $container->load($_SESSION[$namespace]);
        }

        return $this;
    }
257235
public static function refreshToken(AccessToken $token, $params = null)
    {
        if ($token->expires_at > new \DateTime()) {
            return $token;
        }

        $requestor = new ApiRequestor(Sumup::$connectBase, true);
        $params = [
            'grant_type' => 'refresh_token',
            'client_id' => self::_getConnectParam('client_id', $params),
            'client_secret' => self::_getConnectParam('client_secret', $params),
            'refresh_token' => $token->refresh_token
        ];
        $response = $requestor->request('post', '/token', $params);

        if ($response->raw->getStatusCode() !== 200) {
            throw new Error\AuthenticationError('Token request error');
        }

        return new AccessToken($response);
    }
871297
public function refreshToken()
    {
        if (!$this->_restclient) {
            $this->_restclient = new RestClient();
        }
        $data = ['grant_type'    => 'refresh_token',
                'refresh_token'     => $this->get('REFRESH_TOKEN'),
                'client_secret' => $this->get('ACCESS_TOKEN')];
        $this->_restclient->setHttpParam('address', $this->get('base_url'));
        $response = $this->_restclient->post("/oauth/token", ['json_data' => json_encode($data)]);
        if (isset($response['access_token']) && isset($response['refresh_token']) && isset($response['client_id']) && isset($response['client_secret'])) {
            parent::set('ACCESS_TOKEN', $response['access_token']);
            parent::set('REFRESH_TOKEN', $response['refresh_token']);
        }
        return $response['body'];
    }
750294
public function refreshToken()
    {
        if (is_null($this->token) || is_null($this->token->getRefreshToken())) {
            return null;
        }

        $grant = new RefreshToken();
        $refreshToken = $this->provider->getAccessToken($grant, [
            'refresh_token' => $this->token->getRefreshToken()
        ]);

        $this->token = $refreshToken;


        return $this->token;
    }
1219364
public function refresh()
    {
        $tokenURL = $this->credentials['loginURL'] . '/services/oauth2/token';
        $authToken = $this->getAuthToken($tokenURL);

        $this->tokenRepo->put($authToken);
    }
718451
public function create()
    {

        $callback = $this->callback;

        if (is_callback_function($callback)) {
            $callback($this);
        }

        $params = [

            'index' => $this->name,

            'body' => [
                "settings" => [
                    'number_of_shards' => $this->shards,
                    'number_of_replicas' => $this->replicas
                ]
            ],

            'client' => [
                'ignore' => $this->ignores
            ]
        ];

        if (count($this->mappings)) {
            $params["body"]["mappings"] = $this->mappings;
        }

        return $this->connection->indices()->create($params);
    }
835962
private function tokenCanBeRenewed()
    {
        return $this->tokenExists()
            && (time() < ($this->requestTimestamp + $this->data[self::RESPONSE_KEY_REFRESH_TOKEN_TTL]));
    }