public function getAuthorizeUri(Provider $provider, $userId, $scope, $redirectUri)
    {
        $queryParameters = [
            'client_id' => $provider->getClientId(),
            'redirect_uri' => $redirectUri,
            'scope' => $scope,
            'state' => $this->random->getHex(16),
            'response_type' => 'code',
        ];

        $authorizeUri = \sprintf(
            '%s%s%s',
            $provider->getAuthorizationEndpoint(),
            false === \strpos($provider->getAuthorizationEndpoint(), '?') ? '?' : '&',
            \http_build_query($queryParameters, '&')
        );
        $this->session->set(
            '_oauth2_session',
            \array_merge(
                $queryParameters,
                [
                    'user_id' => $userId,
                    'provider_id' => $provider->getProviderId(),
                ]
            )
        );

        return $authorizeUri;
    }