Пример #1
0
std::istream& WebSocketMessage::in()
{
  return webSocket()->in();
}
Пример #2
0
const char *WebSocketMessage::headerValue(const char *name) const
{
  return webSocket()->headerValue(name);
}
Пример #3
0
std::vector<Wt::Http::Message::Header> WebSocketMessage::headers() const
{
  return webSocket()->headers();
}
Пример #4
0
const std::string& WebSocketMessage::remoteAddr() const
{
  return webSocket()->remoteAddr();
}
Пример #5
0
Wt::WSslInfo *WebSocketMessage::sslInfo() const
{
  return webSocket()->sslInfo();
}
Пример #6
0
const std::string& WebSocketMessage::scriptName() const
{
  return webSocket()->scriptName();
}
Пример #7
0
const std::string& WebSocketMessage::pathInfo() const
{
  return webSocket()->pathInfo();
}
Пример #8
0
//==========================================================================
// Class:			OAuth2Interface
// Function:		RequestRefreshToken
//
// Description:		Requests a refresh token from the server.
//
// Input Arguments:
//		None
//
// Output Arguments:
//		None
//
// Return Value:
//		UString::String containing refresh token, or emtpy UString::String on error
//
//==========================================================================
UString::String OAuth2Interface::RequestRefreshToken()
{
	assert(!authURL.empty() &&
		!tokenURL.empty());

	if (IsLimitedInput())
	{
		std::string rawReadBuffer;
		if (!DoCURLPost(authURL, UString::ToNarrowString(AssembleRefreshRequestQueryString()), rawReadBuffer))
			return UString::String();

		const UString::String readBuffer(UString::ToStringType(rawReadBuffer));

		if (ResponseContainsError(readBuffer))
			return UString::String();

		AuthorizationResponse authResponse;
		if (!HandleAuthorizationRequestResponse(readBuffer, authResponse))
			return UString::String();

		UString::String queryString = AssembleAccessRequestQueryString(authResponse.deviceCode);

		time_t startTime = time(nullptr);
		time_t now = startTime;
		while (!HandleRefreshRequestResponse(readBuffer, true))
		{
#ifdef _WIN32
			Sleep(1000 * authResponse.interval);
#else
			sleep(authResponse.interval);
#endif
			now = time(nullptr);
			if (difftime(now, startTime) > authResponse.expiresIn)
			{
				Cerr << "Request timed out - restart application to start again\n";
				return UString::String();
			}

			if (!DoCURLPost(tokenURL, UString::ToNarrowString(queryString), rawReadBuffer))
				return UString::String();

			if (ResponseContainsError(readBuffer))
				return UString::String();
		}
	}
	else
	{
		assert(!responseType.empty());

		UString::String stateKey;// = GenerateSecurityStateKey();// Not sure why it doesn't work with the state key...

		const UString::String assembledAuthURL(authURL + UString::Char('?') + AssembleRefreshRequestQueryString(stateKey));
		CPPSocket webSocket(CPPSocket::SocketType::SocketTCPServer);
		if (RedirectURIIsLocal())
		{
			if (!webSocket.Create(StripPortFromLocalRedirectURI(), UString::ToNarrowString(StripAddressFromLocalRedirectURI()).c_str()))
				return UString::String();
#ifdef _WIN32
			ShellExecute(nullptr, _T("open"), assembledAuthURL.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
#else
			system(UString::ToNarrowString(UString::String(_T("xdg-open '")) + assembledAuthURL + UString::String(_T("'"))).c_str());
#endif
		}
		else// (for example, with redirect URI set to "oob")
		{
			// The benefit of doing it the way we're doing it now, though, is
			// that the browser used to authenticate does not need to be on the
			// same machine that is running this application.
			Cout << "Enter this address in your browser:" << std::endl << assembledAuthURL << std::endl;
		}

		UString::String authorizationCode;
		if (RedirectURIIsLocal())
		{
			if (!webSocket.WaitForClientData(60000))
			{
				Cerr << "No response... aborting\n";
				return UString::String();
			}

			std::string message;
			{
				std::lock_guard<std::mutex> lock(webSocket.GetMutex());
				const auto messageSize(webSocket.Receive());
				if (messageSize <= 0)
					return UString::String();
				message.assign(reinterpret_cast<char*>(webSocket.GetLastMessage()), messageSize);
			}

			if (message.empty())
				return UString::String();

			authorizationCode = ExtractAuthCodeFromGETRequest(message);
			const auto successResponse(BuildHTTPSuccessResponse(successMessage));
			assert(successResponse.length() < std::numeric_limits<unsigned int>::max());
			if (!webSocket.TCPSend(reinterpret_cast<const CPPSocket::DataType*>(successResponse.c_str()), static_cast<int>(successResponse.length())))
				Cout << "Warning:  Authorization code response failed to send" << std::endl;
		}
		else
		{
			Cout << "Enter verification code:" << std::endl;
			Cin >> authorizationCode;
		}

		std::string readBuffer;
		if (!DoCURLPost(tokenURL, UString::ToNarrowString(AssembleAccessRequestQueryString(authorizationCode)), readBuffer) ||
			ResponseContainsError(UString::ToStringType(readBuffer)) ||
			!HandleRefreshRequestResponse(UString::ToStringType(readBuffer)))
		{
			Cerr << "Failed to obtain refresh token\n";
			return UString::String();
		}
	}

	Cout << "Successfully obtained refresh token" << std::endl;
	return refreshToken;
}
Пример #9
0
const std::string& WebSocketMessage::serverPort() const
{
  return webSocket()->serverPort();
}
Пример #10
0
PassRefPtr<WebSocket> WebSocket::create(ScriptExecutionContext* context)
{
    RefPtr<WebSocket> webSocket(adoptRef(new WebSocket(context)));
    webSocket->suspendIfNeeded();
    return webSocket.release();
}
Пример #11
0
const char *WebSocketMessage::envValue(const char *name) const
{
  return webSocket()->envValue(name);
}
Пример #12
0
std::ostream& WebSocketMessage::err()
{
  return webSocket()->err();
}
Пример #13
0
std::ostream& WebSocketMessage::out()
{
  return webSocket()->out();
}
Пример #14
0
void VJSDedicatedWorkerClass::_Construct (VJSParms_construct &ioParms)
{
	XBOX::VString		url;
	bool				reUseContext;
	XBOX::VJSObject		webSocket(ioParms.GetContext());
	bool				isOk;
	
	if (!ioParms.CountParams() || !ioParms.IsStringParam(1) || !ioParms.GetStringParam(1, url)) {

		XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_STRING, "1");
		isOk = false;

	} else {

		reUseContext = false;
		isOk = true;

	}

	if (isOk && ioParms.CountParams() >= 2) {

		if (ioParms.IsBooleanParam(2)) {

			if (!ioParms.GetBoolParam(2, &reUseContext)) {
				
				XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_BOOLEAN, "2");
				isOk = false;

			}

		} else if (!ioParms.GetParamObject(2, webSocket) || !webSocket.IsOfClass(VJSWebSocketClass::Class())) {

			XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER, "2");
			isOk = false;

		} else if (ioParms.CountParams() >= 3 
		&& !(ioParms.IsBooleanParam(3) && ioParms.GetBoolParam(3, &reUseContext))) {
			
			XBOX::vThrowError(XBOX::VE_JVSC_WRONG_PARAMETER_TYPE_BOOLEAN, "3");
			isOk = false;

		}

	}

	if (isOk) {

		VJSWorker			*outsideWorker;
		VJSWebWorkerObject	*workerProxy;
		XBOX::VJSContext	context(ioParms.GetContext());
#if USE_V8_ENGINE
		XBOX::VJSObject constructedObject = ioParms.fConstructedObject;
#else
		XBOX::VJSObject	constructedObject(context);
#endif
		VJSWebSocketObject	*webSocketObject;

		outsideWorker = VJSWorker::RetainWorker(context);
		xbox_assert(outsideWorker != NULL);

		if (!webSocket.HasRef()) 

			webSocketObject = NULL;

		else {

			webSocketObject = webSocket.GetPrivateData<VJSWebSocketClass>();
			xbox_assert(webSocketObject != NULL);

		}

		if ((workerProxy = VJSWebWorkerObject::_CreateWorker(context, outsideWorker, reUseContext, webSocketObject, url, true)) != NULL) {

			constructedObject = VJSDedicatedWorkerClass::ConstructInstance(ioParms, workerProxy);

			if (!webSocket.IsOfClass(VJSWebSocketClass::Class())) {

				workerProxy->fOnMessagePort->SetObject(outsideWorker, constructedObject);
				workerProxy->fOnErrorPort->SetObject(outsideWorker, constructedObject);

			}
			_AddToList(context, "Worker", constructedObject);

		}
		
		ioParms.ReturnConstructedObject(constructedObject);

		XBOX::ReleaseRefCountable<VJSWorker>(&outsideWorker);

	}
}