ts-security-identity
A lightweight Typescript Security Identity Framework with Platform-Agnostic purposes (slightly based on WIF).
1. Getting Started
1.1 Installing
Install package from using npm
npm install --save ts-security-identity
1.2 Build
Configure your build system to copy the files from node_modules/ts-security-identity
to your dist/vendor/ts-security-identity
folder.
1.3 Configuring
Recommendation to use SystemJS to load the package at runtime.
System;
or
System;
2. Using
2.1 Initializing
To initialize, is needed to invoke the proper Initialize method.
- With an encoded token:
;;SecurityContextInitializer.InitializeWithEncodedTokens ;
- With an token (any JSON):
;SecurityContextInitializer.InitializeWithTokens ;
2.2 Authentication
Check if the user is authenticated:
console.logSecurityContext.Current.Principal.IsAuthenticated; //falseSecurityContextInitializer.InitializeWithEncodedTokens ;console.logSecurityContext.Current.Principal.IsAuthenticated; //true
2.3 Identity
Identity have a property named Claims of type Array<{key:string,value:any}>
who allow us to check against informations delivered by the tokens.
Sample:
;
- But also, let us tho extend the built-in Identity with aditional static-typed informations:
; console.logcustomizedIdentity.ClientId; // '2380' SecurityContext.Current.Principal.Identity = customizedIdentity;