Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Authentication using username and password #3024

Open
athukuria opened this issue Dec 4, 2023 · 1 comment
Open

Basic Authentication using username and password #3024

athukuria opened this issue Dec 4, 2023 · 1 comment

Comments

@athukuria
Copy link

athukuria commented Dec 4, 2023

Hi,

I am trying to use Authentication using username and password, But I am not sure where can I get those values from the header in my server:
I tried to use WSI_TOKEN_X_AUTH_TOKEN but it is not part of the header:
lws_hdr_copy(wsi, auth_header, sizeof(auth_header), WSI_TOKEN_X_AUTH_TOKEN)
LWS_CALLBACK_VERIFY_BASIC_AUTHORIZATION is not hit my server callback !

here is my client code: But I am not getting these Authorization as part of header. Looks like I am not using it correctly.
how to set Authorization header correctly for Basic Auth?

    info.port = CONTEXT_PORT_NO_LISTEN;
info.protocols = protocols;
info.gid = (gid_t) -1;
info.uid = (uid_t) -1;
info.iface = "wlp1s0";
if (username != "" && password != "") {
	std::string userpass = username + ":" + password;
	std::string base64_userpass = base64_encode(userpass);

	std::cout << "userpass: " << userpass << std::endl;
	std::cout << "usessl: " << use_ssl << std::endl;
	struct lws_protocol_vhost_options basic_auth[2] = { {
	NULL,
	NULL, "Authorization",
			("Basic " + base64_userpass).c_str() },
			{ NULL, NULL, NULL, NULL } };
	info.headers = &basic_auth[0];



	// Append Authorization header to the protocol options
std::string protocol_options = "Authorization: " + base64_userpass; //authorization_header;
info.alpn = protocol_options.c_str();
info.options |=LWSAUTHM_BASIC_AUTH_CALLBACK;

Currently, these are the header params I am getting:

get  = /test
host: = localhost
connection: = Upgrade
upgrade: = websocket
origin: = http://localhost
sec-websocket-protocol: = lws-mirror-protocol
http/1.1  = HTTP/1.1
pragma: = no-cache
cache-control: = no-cache
sec-websocket-key: = 0AotxGYwBt6mbIT+9gluZw==
sec-websocket-version: = 13

Thanks for the Support
@lws-team
Copy link
Member

lws-team commented Dec 4, 2023

No idea what you're trying to do there... setting info.alpn with it...

Instead take a look at how minimal-examples-lowlevel/http-client/minimal-http-client/minimal-http-client.c works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants