A client in js for PolicyServer1
npm install --save policy-client
Posc is a javascript library that manage client interaction with a Policy Server. The user need to have a user token from something like a OpenID server.
The PolicyManager is there to receive all permission from the server.
Required settings
- authority (string): The URL of the PolicyServer provider.
- clientId (string): Your client application's idenfier. Need to be the same as the token.
- requireHttpsMetadata (boolean, default: true): Does the provider need to have an https connection.
The PolicyServer need to accept request with CORS settings.
var config = {
authority: "http://localhost:5002",
clientId: 'spa',
requireHttpsMetadata: false
}
var mgr = new Posc.PolicyManager(config);
Methods
- setToken: set the current token
- removeToken: remove the current token
- getPolicy: get the current policy
- removePolicy: remove the current policy
- getPermssionEndpoint: find the permission endpoint
The permission object return from the endpoint should look like this :`
export interface Permission {
issuer: string;
clientId: string;
expireIn: number;
created?: number;
policyHash: string;
lastPolicyChangeDate: Date;
roles: string[];
permissions: string[];
}
When you want to get a policy for the current logged user you can use this logic :
mgr.setToken('TOKEN');
mgr.getPolicy().then(p => {
console.log('this is the policy', p);
});