Scope - globules-io/OGX.JS GitHub Wiki
Scope
Scope is designed to test and verify a scope against an entity
Set
If you use
JWTtokens, you can set your scope globally based on the token. The scope is then shared across the entire framework.
OGX.Scope.token(jwt_access_token_object, string_issuer);
Note that starting at version
1.57.0, if you do not set theissuer, it will be considered that the issuer is the main label of the current domain. For instance if the hostname iswww.something.comthen the issuer will be considered to besomething. It must match the issuer of the token. Also note that the issuer can only be passed once. A newer token with a different scope can be passed later on when the app is running but the issuer cannot be overwritten.
Eval
You can otherwise do some manual checks based on a given scope
OGX.Scope.eval(_SCOPE_EXPRESSION_, _SCOPE_);
Scope Expression
A Scope Expression is a string that contains the testing part. For instance, if you wish to test an entity scope and check if it has the required scope:
OGX.Scope.eval('manager', entity.scope);
Consider the entity
let entity = {scope:'admin'};
You can test if the scope matches admin
const has_required_scope = OGX.Scope.eval('admin', entity.scope);
//true
Test if at least one scope matches,
adminormanager
const has_required_scope = OGX.Scope.eval('admin|manager', entity.scope);
//true
Test if at least the scope matches,
supportandcsuite
const has_required_scope = OGX.Scope.eval('support+csuite', entity.scope);
//false
You can also use regular expressions, such as
const has_required_scope = OGX.Scope.eval('/(cluster|company)_(admin|manager|support)/', entity.scope);
//false