Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
http-permission-injection
Advanced tools
Inject and verify a users permissions coming form an http request, using local or remote resources for verification.
This module is intended to provide a role based access architecture for back-end http services. A username and user permissions object can be passed to the module, and it will inject an encrypted account permission cookie in the http client.
The only pre-requirement that is separate to the module itself is, it you choose to use a cookie to pass the username of the account that requires authorization, this needs to be sent in the http request.
injectPermissions()
.Below is a list of variables that can be used to set-up the module. Please ensure you read them carefuly and perform the setup before invoking any of the module functions.
false
true
, false
no
true
, use this token to pass the Bearer Token
header to the remote API.changeme
any string containing a token for your remote api
yes, if is_source_remote is set to true
http://localhost/get_user_permissions
any valid url
yes, if is_source_remote is set to true
null
check the dedicated section to see the structure, must be a JSON object
yes
changeme
any valid string, it's recommended that this is as complex as possible to improve security
yes
60
any integer > 0
no
auth_
any valid string,
no
false
true
, false
no
/
any valid url path
no
Below is a list of functions that are exposed by the module and represent it's core functionality.
callback
):This function is to be used in the event that permissions are fetched from a remote resource and not stored locally.
event
):This is the core function of the module, it is used to, given a username, get user permissions and redirect to a success or fail page provided in the inputs.
event
):This function fetches and decrypts user permissions, allowing for role base access logic to be performed elswhere in the application. The permissions are then passed to a callback function specified, as a JSON object.
Below is an example of the user permission object. The only constraints required by the application is that each object within the array contains the "username" variable, that is then used to match with the username provided when creating the permissions cookie.
Any other structure is free to be customised and, one account object will be stored in the secure cookie and only if there is a match, when the getPermissions()
function is called, the signle object will be returned to the callback function specified.
[
{
"username":"test.user.1",
"other_details": "This could be anything, even what the person likes to have for lunch.",
"permissions": [
"read",
"write"
]
},
{
"username":"test.user.2",
"some_other_detail":"In this case, this is all that's here!"
}
]
Below is an example that uses a local object for permissions.
// Modules used for the example.
var http = require('http');
var url = require('url');
//Import the module.
const http_auth = require('http-permission-injection');
// Demo user object.
http_auth.user_data = [
{
"username":"test.user.1",
"other_details": "This could be anything, even what the person likes to have for lunch.",
"permissions": [
"read"
],
"superuser": false
},
{
"username":"test.user.2",
"some_other_detail":"In this case, this is all that's here!",
"superuser": true
}
]
http_auth.cookie_encryption_key = "UwwkFapH9wCZNnQRRybgPg427u2VZRS9sCvaLGArRzrp5md6sTMtDcVQTKuDJ7S6Ftp5N7XMnEAKfxa5tLmFrVzEgw3Yh25EebbeSV2DWmqT6yxkM7UWYDsCmZsxmZUT";
http_auth.cookie_expiry_minutes = 5;
var server = http.createServer(function(request, response) {
var pathName = url.parse(request.url).pathname;
var url_path = pathName.replace(/\/$/, "");
switch (url_path){
// Perform authorization.
case "/auth":
http_auth.injectPermissions({
request: request,
response: response,
success_url: "/success",
denied_url: "/denied",
username: "test.user.1"
});
break;
// Return auth data if it's a success.
case "/success":
console.log("Permission Success.");
http_auth.getPermissions({
request: request,
callback: function(permissions){
console.log("Permissions:" + JSON.stringify(permissions));
response.writeHeader(200, {"Content-Type": "text/plain"});
response.write(JSON.stringify(permissions));
response.end();
}
});
break;
case "/denied":
console.log("Permission Denied.");
response.writeHeader(200, {"Content-Type": "text/plain"});
response.write(JSON.stringify(permissions));
response.end();
break;
}
});
var port = process.env.PORT || 8080;
server.listen(port);
Below is an example that uses a local remote api to fetch the permissions object used to perform the verification. Because the process is very similar to the above example, I will only provide the differences in the below code snippet:
http_auth.is_source_remote = true;
http_auth.remote_token = "7XMnEAKfxa5tLmFrVzEg";
http_auth.remote_endpoint = "https://some-url-to-api/get_users";
http_auth.fetchRemoteUsers(function(permission){
http_auth.user_data = permission;
});
The essential difference is that we call fetchRemoteUsers()
before performing other actions, that way we can reteive a list of current permissions. This call can be repeated at any point to refresh the list.
FAQs
Inject and verify a users permissions coming form an http request, using local or remote resources for verification.
The npm package http-permission-injection receives a total of 7 weekly downloads. As such, http-permission-injection popularity was classified as not popular.
We found that http-permission-injection demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.