2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
19 export type AuthToken = {
24 * datetime the token should expire in unix timestamp
30 * time the token was issued in unix timestamp
38 export type AuthPolicy = {
51 constructor (private _bearerToken: AuthToken) {
55 public get user(): string | null {
56 return this._bearerToken && this._bearerToken.username;
59 public get token(): string | null {
60 return this._bearerToken && this._bearerToken.access_token;
63 public get tokenType(): string | null {
64 return this._bearerToken && this._bearerToken.token_type;
68 * Time the user should be logged out, in unix timestamp in seconds
70 public get logoutAt(): number{
71 return this._bearerToken && this._bearerToken.expires;
75 * Time the user logged in, in unix timestamp in seconds
77 public get loginAt(): number{
78 return this._bearerToken && this._bearerToken.issued;
81 public get isValid(): boolean {
82 return (this._bearerToken && (new Date().valueOf()) < this._bearerToken.expires*1000) || false;
86 return JSON.stringify(this._bearerToken);
89 public static fromString(data: string) {
90 return new User(JSON.parse(data));