summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/framework/src/models
diff options
context:
space:
mode:
authorHerbert Eiselt <herbert.eiselt@highstreet-technologies.com>2019-03-12 18:00:21 +0100
committerHerbert Eiselt <herbert.eiselt@highstreet-technologies.com>2019-03-12 18:01:06 +0100
commit2d4424c28ac35763ef44c42ae2f01664d42b268c (patch)
tree4e6ebdc2e57c1c8f2c91d3ec094b340c89dfe5c5 /sdnr/wt/odlux/framework/src/models
parentcaf781999351fc6a3e2acb5b2fe47fe04a291d2d (diff)
Security provider for UX-Client-Login
Use ODL provided oauth2/token for UX clients Change-Id: I9f9ae931fc5e74dc13076bd23551d163c0685606 Issue-ID: SDNC-648 Signed-off-by: Herbert Eiselt <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/odlux/framework/src/models')
-rw-r--r--sdnr/wt/odlux/framework/src/models/authentication.ts59
1 files changed, 25 insertions, 34 deletions
diff --git a/sdnr/wt/odlux/framework/src/models/authentication.ts b/sdnr/wt/odlux/framework/src/models/authentication.ts
index 44b5ae436..6c463ad05 100644
--- a/sdnr/wt/odlux/framework/src/models/authentication.ts
+++ b/sdnr/wt/odlux/framework/src/models/authentication.ts
@@ -1,50 +1,41 @@
-import * as JWT from 'jsonwebtoken';
-
-export interface IUserInfo {
- iss: string,
- iat: number,
- exp: number,
- aud: string,
- sub: string,
- firstName: string,
- lastName: string,
- email: string,
- role: string[]
+
+export type AuthToken = {
+ username: string;
+ access_token: string;
+ token_type: string;
+ expires: number;
}
export class User {
- public _userInfo: IUserInfo | null;
-
- constructor(private _bearerToken: string) {
- //const pem = require('raw-loader!../assets/publicKey.pem');
- const pem = "kFfAgpf806IKa4z88EEk6Lim7NMGicrw99OmIB38myM9CS44nEmMNJxnFu3ImViS248wSwkuZ3HvrhsPrA1ZFRNb1a6CEtGN4DaPJbfuo35qMp50tIEpy8nsSFpayOBE";
-
- try {
- const dec = (JWT.verify(_bearerToken, pem)) as IUserInfo;
- this._userInfo = dec;
- } catch (ex) {
- this._userInfo = null;
- }
+ constructor (private _bearerToken: AuthToken) {
+
}
public get user(): string | null {
- return this._userInfo && this._userInfo.email;
+ return this._bearerToken && this._bearerToken.username;
};
- public get roles(): string[] | null {
- return this._userInfo && this._userInfo.role;
- }
public get token(): string | null {
- return this._userInfo && this._bearerToken;
+ return this._bearerToken && this._bearerToken.access_token;
}
- public isInRole(role: string | string[]): boolean {
- return false;
+ public get tokenType(): string | null {
+ return this._bearerToken && this._bearerToken.token_type;
}
-}
+ public get isValid(): boolean {
+ return (this._bearerToken && (new Date().valueOf()) < this._bearerToken.expires) || false;
+ }
-// key:kFfAgpf806IKa4z88EEk6Lim7NMGicrw99OmIB38myM9CS44nEmMNJxnFu3ImViS248wSwkuZ3HvrhsPrA1ZFRNb1a6CEtGN4DaPJbfuo35qMp50tIEpy8nsSFpayOBE
-// token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPRExVWCIsImlhdCI6MTUzODQ2NDMyMCwiZXhwIjoxNTcwMDAwMzIwLCJhdWQiOiJsb2NhbGhvc3QiLCJzdWIiOiJsb2NhbGhvc3QiLCJmaXJzdE5hbWUiOiJNYXgiLCJsYXN0TmFtZSI6Ik11c3Rlcm1hbm4iLCJlbWFpbCI6Im1heEBvZGx1eC5jb20iLCJyb2xlIjpbInVzZXIiLCJhZG1pbiJdfQ.9e5hDi2uxmIXNwHkJoScBZsHBk0jQ8CcZ7YIcZhDtuI \ No newline at end of file
+ public toString() {
+ return JSON.stringify(this._bearerToken);
+ }
+
+ public static fromString(data: string) {
+ return new User(JSON.parse(data));
+ }
+
+
+}