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

added Authorization Info to request context #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/ServerRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ function ServerRequest(socket) {
events.EventEmitter.call(this);
this.socket = this.connection = socket;

var clientAuthorizationInfo = this.socket._requestContext.req.clientAuthorization;
if (clientAuthorizationInfo) {
delete this.socket._requestContext.req.clientAuthorizationInfo;
}

var clientCertInfo = this.socket._requestContext.req.clientCertInfo;
if (clientCertInfo) {
delete this.socket._requestContext.req.clientCertInfo;
Expand Down
52 changes: 48 additions & 4 deletions src/httpsys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ Handle<String> v8validFrom;
Handle<String> v8validTo;
Handle<String> v8fingerprint;
Handle<String> v8encoded;
Handle<String> v8clientAuthorization;
Handle<String> v8authStatus;
Handle<String> v8authType;
Handle<String> v8authFlags;
Handle<String> v8authAccessToken;

// Maps HTTP_HEADER_ID enum to v8 string
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa364526(v=vs.85).aspx
Expand Down Expand Up @@ -281,12 +286,12 @@ void httpsys_new_request_callback(uv_async_t* handle, int status)
if (S_OK != overlappedResult)
{
// Async completion failed - notify JavaScript
httpsys_notify_error(
uv_httpsys,
HTTPSYS_ERROR_NEW_REQUEST,
(unsigned int)overlappedResult);
httpsys_free(uv_httpsys, TRUE);
uv_httpsys = NULL;
}
Expand Down Expand Up @@ -360,7 +365,7 @@ void httpsys_new_request_callback(uv_async_t* handle, int status)

req->Set(v8httpVersionMajor, Integer::NewFromUnsigned(request->Version.MajorVersion));
req->Set(v8httpVersionMinor, Integer::NewFromUnsigned(request->Version.MinorVersion));

// Add URL information

req->Set(v8url, String::New(request->pRawUrl, request->RawUrlLength));
Expand All @@ -374,6 +379,17 @@ void httpsys_new_request_callback(uv_async_t* handle, int status)
httpsys_create_client_cert_info(request->pSslInfo->pClientCertInfo));
}

// Add Client Authorization info

for(USHORT i = 0; i < request->RequestInfoCount;++i)
{
if(request->pRequestInfo[i].InfoType != HttpRequestInfoTypeAuth) continue;
HTTP_REQUEST_AUTH_INFO *authInfo = (HTTP_REQUEST_AUTH_INFO *)request->pRequestInfo[i].pInfo;
if (authInfo)
req->Set(v8clientAuthorization, httpsys_create_client_auth_info(authInfo));
break;
}

// Invoke the JavaScript callback passing event as the only paramater

Handle<Value> result = httpsys_make_callback(event);
Expand Down Expand Up @@ -401,6 +417,20 @@ void httpsys_new_request_callback(uv_async_t* handle, int status)
}
}

Handle<Object> httpsys_create_client_auth_info(PHTTP_REQUEST_AUTH_INFO info)
{
HandleScope scope;

Handle<Object> authInfo = Object::New();

authInfo->Set(v8authStatus, Integer::New(info->AuthStatus));
authInfo->Set(v8authType, Integer::New(info->AuthType));
authInfo->Set(v8authFlags, Integer::New(info->Flags));
authInfo->Set(v8authAccessToken, Number::New(static_cast<double>((intptr_t)(info->AccessToken))));

return scope.Close(authInfo);
}

Handle<Object> httpsys_create_client_cert_info(PHTTP_SSL_CLIENT_CERT_INFO info)
{
HandleScope scope;
Expand Down Expand Up @@ -1046,7 +1076,16 @@ Handle<Value> httpsys_listen(const Arguments& args)
&requestQueueLength,
sizeof(requestQueueLength),
0,
NULL));
NULL));

// Enable Negotiate Authentication

HTTP_SERVER_AUTHENTICATION_INFO authConfig = {0};
authConfig.Flags.Present = 1;
authConfig.AuthSchemes = HTTP_AUTH_ENABLE_NEGOTIATE;

CheckError(HttpSetUrlGroupProperty(uv_httpsys_server->groupId,
HttpServerAuthenticationProperty, &authConfig,sizeof(HTTP_SERVER_AUTHENTICATION_INFO)));

// Bind the request queue with the URL group to enable receiving
// HTTP traffic on the request queue.
Expand Down Expand Up @@ -1682,6 +1721,11 @@ void init(Handle<Object> target)
v8validTo = Persistent<String>::New(String::NewSymbol("valid_to"));
v8fingerprint = Persistent<String>::New(String::NewSymbol("fingerprint"));
v8encoded = Persistent<String>::New(String::NewSymbol("encoded"));
v8clientAuthorization = Persistent<String>::New(String::NewSymbol("clientAuthorization"));
v8authAccessToken = Persistent<String>::New(String::NewSymbol("authAccessToken"));
v8authFlags = Persistent<String>::New(String::NewSymbol("authFlags"));
v8authType = Persistent<String>::New(String::NewSymbol("authType"));
v8authStatus = Persistent<String>::New(String::NewSymbol("authStatus"));

// Capture the constructor function of JavaScript Buffer implementation

Expand Down
1 change: 1 addition & 0 deletions src/httpsys.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ HRESULT httpsys_uv_httpsys_init(uv_httpsys_t* uv_httpsys, uv_async_cb callback);
HRESULT httpsys_uv_httpsys_close(uv_httpsys_t* uv_httpsys);
void httpsys_close_uv_async_cb(uv_handle_t* uv_handle);
Handle<Object> httpsys_create_client_cert_info(PHTTP_SSL_CLIENT_CERT_INFO info);
Handle<Object> httpsys_create_client_auth_info(PHTTP_REQUEST_AUTH_INFO info);

// HTTP processing state machine actions and events

Expand Down