
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
angular-visor
Advanced tools
#Visor
Visor is an authentication and authorization framework for AngularJS.
It provides a convenient way to authenticate on startup and define which routes are accessible to whom.
Visor works with both ngRoute and ui-router.
Get Visor:
$ bower install visor
from your console$ npm install --save angular-visor
from your consoleSample apps:
API documentation:
###Authenticate with visor:
angular.module("yourModule",["visor","ngRoute"]).
configure(function(visorProvider,$routeProvider){
visorProvider.authenticate = function($http){
return $http.get(<your authentication url>).then(function(res){return res.data;}) //returns user
};
$routeProvider.when("/private",{
restrict: function(user){ return user && user.can_see_private}
})
});
Visor provides two main features:
Authentication:
Authorization:
###Setting up the authenticate method
Visor requires that you define an authentication method that runs before restricted routes are accessed.
Visor exposes an authenticate method in it's provider:
angular.module("yourModule",["visor"]).
configure(function(visorProvider,$routeProvider){
visorProvider.authenticate = function($http){
return $http.get(<your authentication url>).then(function(res){return res.data;})
};
});
The authenticate method is dependency injected, and needs to return a promise.
The result from a successful promise will be sent to future restrict functions.
###Defining restrictions on routes
To define certain routes to be restricted to certain users, Visor requires a "restrict" attribute to exist inside the route or state.
That function will be called with the value returned from the authenticate
promise and should return a boolean indicating if the routing should continue.
If a user was not authenticated the restrict function will be called with no values.
angular.module("yourModule",["ngRoute"]).
configure(function($routeProvider){
$routeProvider.when("/private",{ // will only be shown to users that have `can_see_private`
restrict: function(auth){ return auth && auth.can_see_private}
})
.when("/only_not_authenticated",{ // will only be shown to users who are not authenticated
restrict: function(auth){ return auth === undefined}
})
.when("/public",{}); // will be shown to any user
});
angular.module("yourModule",["ui.router"]).
configure(function($stateProvider){
$stateProvider.state("private",{ // will only be shown to users that have `can_see_private`
restrict: function(auth){ return auth && auth.can_see_private}
})
.state("only_not_authenticated",{ // will only be shown to users who are not authenticated
restrict: function(auth){ return auth === undefined}
})
.state("public",{}); // will be shown to any user
});
Visor also respects restrictions in parent states.
angular.module("yourModule",["ui.router"]).
configure(function($stateProvider){
$stateProvider.state("private",{ // will only be shown to users that have `can_see_private`
restrict: function(auth){ return auth && auth.can_see_private}
})
.state("only_not_authenticated",{ // will only be shown to users that have `can_see_private`
parent:"private"
})
.state("admin",{ // will only be shown to users who have both `can_see_private` and `is_admin`
parent:"private",
restrict: function(auth){ return auth && auth.is_admin}
});
});
Visor provides two default restriction methods as constants:
authenticatedOnly
- only users who are authenticated can see the routenotForAuthenticated
- only users who aren't authenticated can see the route angular.module("yourModule",["ngRoute"]).
configure(function($routeProvider,authenticatedOnly,notForAuthenticated){
$routeProvider.when("/private",{ // will only be shown to users that are authenticated
restrict: authenticatedOnly
})
.when("/only_not_authenticated",{ // will only be shown to users who are not authenticated
restrict: notForAuthenticated
})
.when("/public",{}); // will be shown to any user
});
Visor defines the following situations that can be overriden:
An unauthenticated user tries to access a restricted route.
visorProvider.loginRoute
visorProvider.doOnNotAuthenticated
next
parameter to the redirect to allow returning to the original path after a successful login.next
parameter by settings the visorProvider.shouldAddNext
flag.An authenticated user tries to access a restricted route.
visorProvider.notAuthorizedRoute
visorProvider.doOnNotAuthorized
When a user is manually logged in.
next
parameter exists in the url Visor will redirect to that path otherwise it'll redirect to `/' path.next
is provided can be overriden in visorProvider.homeRoute
visorProvider.doAfterManualAuthentication
###Login and Signup
Visor needs to be notified when a user logs in to the application (as opposed to already being authenticated) in order for restrictions to work.
You inform visor when a user logs in by calling visor.setAuthenticated(authInfo)
.
The value sent to visor.isAuthenticated
to be the same as the value returned in the authenticate
promise.
FAQs
Angular authentication and authorization library
The npm package angular-visor receives a total of 1 weekly downloads. As such, angular-visor popularity was classified as not popular.
We found that angular-visor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.