aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/framework/src/models/authentication.ts
blob: 44b5ae4366f877411d9079c7641ea387fcb2085a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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 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;
    }
  }

  public get user(): string | null {
    return this._userInfo && this._userInfo.email;
  };

  public get roles(): string[] | null {
    return this._userInfo && this._userInfo.role;
  }
  public get token(): string | null {
    return this._userInfo && this._bearerToken;
  }

  public isInRole(role: string | string[]): boolean {
    return false;
  }

}

// key:kFfAgpf806IKa4z88EEk6Lim7NMGicrw99OmIB38myM9CS44nEmMNJxnFu3ImViS248wSwkuZ3HvrhsPrA1ZFRNb1a6CEtGN4DaPJbfuo35qMp50tIEpy8nsSFpayOBE
// token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPRExVWCIsImlhdCI6MTUzODQ2NDMyMCwiZXhwIjoxNTcwMDAwMzIwLCJhdWQiOiJsb2NhbGhvc3QiLCJzdWIiOiJsb2NhbGhvc3QiLCJmaXJzdE5hbWUiOiJNYXgiLCJsYXN0TmFtZSI6Ik11c3Rlcm1hbm4iLCJlbWFpbCI6Im1heEBvZGx1eC5jb20iLCJyb2xlIjpbInVzZXIiLCJhZG1pbiJdfQ.9e5hDi2uxmIXNwHkJoScBZsHBk0jQ8CcZ7YIcZhDtuI