vix-ui
Version:
A set of essential UI modules for your Angular application in ViSenze
1,162 lines (1,151 loc) • 209 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common/http'), require('angular-oauth2-oidc'), require('@okta/okta-auth-js'), require('@angular/router'), require('@angular/common'), require('@angular/forms'), require('@angular/material'), require('@angular/platform-browser/animations')) :
typeof define === 'function' && define.amd ? define('vix-ui', ['exports', '@angular/core', '@angular/common/http', 'angular-oauth2-oidc', '@okta/okta-auth-js', '@angular/router', '@angular/common', '@angular/forms', '@angular/material', '@angular/platform-browser/animations'], factory) :
(factory((global['vix-ui'] = {}),global.ng.core,global.ng.common.http,null,null,global.ng.router,global.ng.common,global.ng.forms,global.ng.material,global.ng.platformBrowser.animations));
}(this, (function (exports,core,http,angularOauth2Oidc,OktaAuth,router,common,forms,material,animations) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* VixAuthConfig holds the necessary config required by other services
*/
var /**
* VixAuthConfig holds the necessary config required by other services
*/ VixAuthConfig = (function () {
function VixAuthConfig() {
}
return VixAuthConfig;
}());
/**
* AuthConfigService provides get method for all parameters
*
* \@var {string} _url: url for okta account like: 'https://dev-913444.oktapreview.com'
* \@
*/
var AuthConfigService = (function () {
function AuthConfigService(authConfig) {
this.authConfig = authConfig;
this._url = authConfig.url;
this._issuer = authConfig.issuer;
this._clientId = authConfig.clientId;
this._redirectUrl = authConfig.redirectUrl;
this._apiKey = authConfig.apiKey;
this._loginUrl = authConfig.loginUrl;
}
/**
* @return {?}
*/
AuthConfigService.prototype.getLoginUrl = /**
* @return {?}
*/
function () {
return this._loginUrl;
};
/**
* @returns url
*/
/**
* @return {?} url
*/
AuthConfigService.prototype.getUrl = /**
* @return {?} url
*/
function () {
return this._url;
};
/**
* @returns issuer
*/
/**
* @return {?} issuer
*/
AuthConfigService.prototype.getIssuer = /**
* @return {?} issuer
*/
function () {
return this._issuer;
};
/**
* @returns clientId
*/
/**
* @return {?} clientId
*/
AuthConfigService.prototype.getClientId = /**
* @return {?} clientId
*/
function () {
return this._clientId;
};
/**
*
* @returns redirectUrl
*/
/**
*
* @return {?} redirectUrl
*/
AuthConfigService.prototype.getRedirectUrl = /**
*
* @return {?} redirectUrl
*/
function () {
return this._redirectUrl;
};
/**
*
* @returns remove the domain from url.
* example: return '/foo/bar' if redirectUrl is 'http://foobar.com/foo/bar'
*/
/**
*
* @return {?} remove the domain from url.
* example: return '/foo/bar' if redirectUrl is 'http://foobar.com/foo/bar'
*/
AuthConfigService.prototype.getRoute = /**
*
* @return {?} remove the domain from url.
* example: return '/foo/bar' if redirectUrl is 'http://foobar.com/foo/bar'
*/
function () {
var /** @type {?} */ s = this._redirectUrl.split('/');
return '/' + s.slice(3, s.length).join('/');
};
/**
* @returns okta API key
*/
/**
* @return {?} okta API key
*/
AuthConfigService.prototype.getApiKey = /**
* @return {?} okta API key
*/
function () {
return this._apiKey;
};
AuthConfigService.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
AuthConfigService.ctorParameters = function () {
return [
{ type: VixAuthConfig, },
];
};
return AuthConfigService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* Wrapper for Okta API
*/
var OktaService = (function () {
/**
* @param httpClient
* @param authConfig
*/
function OktaService(httpClient, authConfig) {
this.httpClient = httpClient;
this.authConfig = authConfig;
this.httpOptions = {
headers: new http.HttpHeaders({
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'SSWS ' + this.authConfig.getApiKey()
})
};
}
/**
* Build Full API URl by given endpoint
* @param endpoint
* @returns
*/
/**
* Build Full API URl by given endpoint
* @param {?} endpoint
* @return {?}
*/
OktaService.prototype.getFullUrl = /**
* Build Full API URl by given endpoint
* @param {?} endpoint
* @return {?}
*/
function (endpoint) {
return this.authConfig.getUrl() + "/api/v1" + endpoint;
};
/**
* Get user info by email.
* doc: https://developer.okta.com/docs/api/resources/users#get-current-user
* @returns
*/
/**
* Get user info by email.
* doc: https://developer.okta.com/docs/api/resources/users#get-current-user
* @param {?} userId
* @return {?}
*/
OktaService.prototype.getUserInfo = /**
* Get user info by email.
* doc: https://developer.okta.com/docs/api/resources/users#get-current-user
* @param {?} userId
* @return {?}
*/
function (userId) {
return this.httpClient.get(this.getFullUrl("/users/" + userId), this.httpOptions).toPromise();
};
/**
* Get user groups information by given userId
* doc: https://developer.okta.com/docs/api/resources/users#get-member-groups
* @param userId
* @returns
*/
/**
* Get user groups information by given userId
* doc: https://developer.okta.com/docs/api/resources/users#get-member-groups
* @param {?} userId
* @return {?}
*/
OktaService.prototype.getUserGroups = /**
* Get user groups information by given userId
* doc: https://developer.okta.com/docs/api/resources/users#get-member-groups
* @param {?} userId
* @return {?}
*/
function (userId) {
return this.httpClient.get(this.getFullUrl("/users/" + userId + "/groups"), this.httpOptions).toPromise();
};
/**
* List all groups
*/
/**
* List all groups
* @return {?}
*/
OktaService.prototype.listGroups = /**
* List all groups
* @return {?}
*/
function () {
return this.httpClient.get(this.getFullUrl('/groups'), this.httpOptions).toPromise();
};
OktaService.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
OktaService.ctorParameters = function () {
return [
{ type: http.HttpClient, },
{ type: AuthConfigService, },
];
};
return OktaService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* UserInfo holds the user information
*/
var /**
* UserInfo holds the user information
*/ UserInfo = (function () {
/**
* Extract necessary information oktaUserInfo
* @param oktaUserInfo
* oktaUserInfo example:
* {
* "id": "foobar",
* ...
* "profile": {
* "firstName": "foobar",
* "lastName": "foobar",
* "mobilePhone": null,
* "secondEmail": null,
* "login": "foo@bar.com",
* "email": "foo@bar.com"
* },
* ...
* }
*/
function UserInfo(oktaUserInfo) {
this.userId = oktaUserInfo.id;
this.email = oktaUserInfo.profile.email;
this.firstName = oktaUserInfo.profile.firstName;
this.lastName = oktaUserInfo.profile.lastName;
}
return UserInfo;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* UserGroups holds the groups information of a user. It is mainly used to check permissions.
*/
var /**
* UserGroups holds the groups information of a user. It is mainly used to check permissions.
*/ UserGroups = (function () {
/**
* construct UserGroups from OktaUserGroups
*
* @param oktaUserGroups Array of oktaGroups
* oktaGroup example:
* { ...
* "profile": {
* "name": "Everyone",
* "description": "All users in your organization"
* },
* ...
* }
*/
function UserGroups(oktaUserGroups) {
var _this = this;
this.groups = [];
if (oktaUserGroups) {
oktaUserGroups.forEach(function (oktaGroup) {
_this.groups.push(oktaGroup.profile.name);
});
}
}
/**
* Check if instance has enough permission for requireGroups.
*
* @param requireGroups
* @returns true if this.groups contains all group of requireGroups, else then false
*/
/**
* Check if instance has enough permission for requireGroups.
*
* @param {?} requireGroups
* @return {?} true if this.groups contains all group of requireGroups, else then false
*/
UserGroups.prototype.hasPermission = /**
* Check if instance has enough permission for requireGroups.
*
* @param {?} requireGroups
* @return {?} true if this.groups contains all group of requireGroups, else then false
*/
function (requireGroups) {
for (var /** @type {?} */ i = 0; i < requireGroups.length; i++) {
if (this.groups.indexOf(requireGroups[i]) > 0) {
return true;
}
}
return false;
};
return UserGroups;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* VixAuthService is the interface exported to users. It wraps all API and methods.
*/
var VixAuthService = (function () {
function VixAuthService(oauth, authConfig, okta) {
this.oauth = oauth;
this.authConfig = authConfig;
this.okta = okta;
this.oktaAuth = new OktaAuth({
url: this.authConfig.getUrl(),
issuer: this.authConfig.getIssuer()
});
}
/**
* Check permissions by userGroups and requireGroups
*
* @param userGroups groups users are in
* @param requireGroups groups application requires user to have
* @returns true/false
*/
/**
* Check permissions by userGroups and requireGroups
*
* @param {?} userGroups groups users are in
* @param {?} requireGroups groups application requires user to have
* @return {?} true/false
*/
VixAuthService.hasPermission = /**
* Check permissions by userGroups and requireGroups
*
* @param {?} userGroups groups users are in
* @param {?} requireGroups groups application requires user to have
* @return {?} true/false
*/
function (userGroups, requireGroups) {
return userGroups.hasPermission(requireGroups);
};
/**
* Use tokenManager to store userId
* TODO: actually I have problems in create a cache object to hold all these cache variables, so I use tokenManager to do these works.
* TODO: need to create a share service to provide cache service
*
* @param userId
*/
/**
* Use tokenManager to store userId
* TODO: actually I have problems in create a cache object to hold all these cache variables, so I use tokenManager to do these works.
* TODO: need to create a share service to provide cache service
*
* @param {?} userId
* @return {?}
*/
VixAuthService.prototype.setUserId = /**
* Use tokenManager to store userId
* TODO: actually I have problems in create a cache object to hold all these cache variables, so I use tokenManager to do these works.
* TODO: need to create a share service to provide cache service
*
* @param {?} userId
* @return {?}
*/
function (userId) {
var /** @type {?} */ obj = {
accessToken: 'userId',
expiresAt: Math.round((new Date()).getTime() / 1000 + 3600),
scopes: [userId]
};
this.oktaAuth.tokenManager.add('userId', obj);
};
/**
* Get userId from tokenManager
* @returns
*/
/**
* Get userId from tokenManager
* @return {?}
*/
VixAuthService.prototype.getUserId = /**
* Get userId from tokenManager
* @return {?}
*/
function () {
var /** @type {?} */ userIdObj = this.oktaAuth.tokenManager.get('userId');
if (userIdObj) {
return this.oktaAuth.tokenManager.get('userId').scopes[0];
}
else {
return null;
}
};
/**
* Store userGroup and shared among browsers by TokenManager with key 'userGroup'
*
* @param userGroups
*/
/**
* Store userGroup and shared among browsers by TokenManager with key 'userGroup'
*
* @param {?} userGroups
* @return {?}
*/
VixAuthService.prototype.setCurrentUserGroups = /**
* Store userGroup and shared among browsers by TokenManager with key 'userGroup'
*
* @param {?} userGroups
* @return {?}
*/
function (userGroups) {
var /** @type {?} */ obj = {
accessToken: 'userGroups',
expiresAt: Math.round((new Date()).getTime() / 1000 + 3600),
scopes: userGroups.groups
};
this.oktaAuth.tokenManager.add('userGroups', obj);
};
/**
* Get stored userGroups and refresh if expires
*
* @returns
*/
/**
* Get stored userGroups and refresh if expires
*
* @return {?}
*/
VixAuthService.prototype.getLoginUserGroups = /**
* Get stored userGroups and refresh if expires
*
* @return {?}
*/
function () {
return __awaiter(this, void 0, void 0, function () {
var userGroupsTokenObj, nowSecond, tmpUserGroups, userGroups;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
userGroupsTokenObj = this.oktaAuth.tokenManager.get('userGroups');
nowSecond = (new Date()).getTime() / 1000;
if (!(!userGroupsTokenObj || nowSecond > userGroupsTokenObj.expireAt))
return [3 /*break*/, 2];
return [4 /*yield*/, this.getUserGroups(this.getUserId())];
case 1:
tmpUserGroups = _a.sent();
this.setCurrentUserGroups(tmpUserGroups);
_a.label = 2;
case 2:
userGroups = new UserGroups(null);
userGroups.groups = this.oktaAuth.tokenManager.get('userGroups').scopes;
return [2 /*return*/, userGroups];
}
});
});
};
/**
* Get current login userInfo
* TODO: we can cache user info includes groups information when finished login
*
* @returns
*/
/**
* Get current login userInfo
* TODO: we can cache user info includes groups information when finished login
*
* @return {?}
*/
VixAuthService.prototype.getUserInfo = /**
* Get current login userInfo
* TODO: we can cache user info includes groups information when finished login
*
* @return {?}
*/
function () {
return __awaiter(this, void 0, void 0, function () {
var oktaUserInfo;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.isLogin())
return [3 /*break*/, 3];
return [4 /*yield*/, this.okta.getUserInfo(this.getUserId())];
case 1:
oktaUserInfo = _a.sent();
return [4 /*yield*/, new UserInfo(oktaUserInfo)];
case 2: return [2 /*return*/, _a.sent()];
case 3: return [2 /*return*/, Promise.reject('not login')];
}
});
});
};
/**
* get userGroup by given userId
*
* @param userId
* @returns
*/
/**
* get userGroup by given userId
*
* @param {?} userId
* @return {?}
*/
VixAuthService.prototype.getUserGroups = /**
* get userGroup by given userId
*
* @param {?} userId
* @return {?}
*/
function (userId) {
return __awaiter(this, void 0, void 0, function () {
var oktaUserGroups, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.isLogin())
return [3 /*break*/, 6];
_a.label = 1;
case 1:
_a.trys.push([1, 4, , 5]);
return [4 /*yield*/, this.okta.getUserGroups(userId)];
case 2:
oktaUserGroups = _a.sent();
return [4 /*yield*/, new UserGroups(oktaUserGroups)];
case 3: return [2 /*return*/, _a.sent()];
case 4:
err_1 = _a.sent();
console.log('getUserGroups err', err_1);
// return new UserGroups(null);
return [3 /*break*/, 5];
case 5: return [3 /*break*/, 7];
case 6: return [2 /*return*/, null];
case 7: return [2 /*return*/];
}
});
});
};
/**
* Return if already login by check the existence of accessToken
*
* @returns
*/
/**
* Return if already login by check the existence of accessToken
*
* @return {?}
*/
VixAuthService.prototype.isLogin = /**
* Return if already login by check the existence of accessToken
*
* @return {?}
*/
function () {
return !!this.getUserId();
};
/**
* Redirect to url for Google login
*/
/**
* Redirect to url for Google login
* @param {?} redirectUrl
* @return {?}
*/
VixAuthService.prototype.loginWithGoogle = /**
* Redirect to url for Google login
* @param {?} redirectUrl
* @return {?}
*/
function (redirectUrl) {
window.location.href = this.authConfig.getUrl() + "/oauth2/v1/authorize?" +
("idp=0oadulhuz78SMW8cD0h7&client_id=" + this.authConfig.getClientId() + "&response_type=id_token&") +
"response_mode=fragment&scope=openid&scope=email&scope=picture&scope=name&" +
("state=WM6D&nonce=YsG76jo&redirect_uri=" + redirectUrl);
};
/**
* Login by username and password
*
* @param username
* @param password
* @returns
*/
/**
* Login by username and password
*
* @param {?} username
* @param {?} password
* @return {?}
*/
VixAuthService.prototype.loginWithPassword = /**
* Login by username and password
*
* @param {?} username
* @param {?} password
* @return {?}
*/
function (username, password) {
return __awaiter(this, void 0, void 0, function () {
var nonce, signInResponse, session;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.oauth.createAndSaveNonce()];
case 1:
nonce = _a.sent();
return [4 /*yield*/, this.oktaAuth.signIn({ username: username, password: password })];
case 2:
signInResponse = _a.sent();
if (!(signInResponse.status === 'SUCCESS'))
return [3 /*break*/, 5];
return [4 /*yield*/, this.oktaAuth.token.getWithoutPrompt({
clientId: this.authConfig.getClientId(),
responseType: ['id_token', 'token'],
scopes: ['openid', 'profile', 'email'],
sessionToken: signInResponse.sessionToken,
nonce: nonce,
redirectUri: window.location.origin
})];
case 3:
_a.sent();
return [4 /*yield*/, this.getSession()];
case 4:
session = _a.sent();
if (session.status === 'ACTIVE') {
console.log('session ACTIVE');
this.setUserId(session.userId);
}
return [2 /*return*/, Promise.resolve('login successfully')];
case 5: return [2 /*return*/, Promise.reject('username or password error')];
}
});
});
};
/**
* List all groups
*
* @return {?}
*/
VixAuthService.prototype.listGroups = /**
* List all groups
*
* @return {?}
*/
function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.okta.listGroups()];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**
* Get session
*
* @return {?}
*/
VixAuthService.prototype.getSession = /**
* Get session
*
* @return {?}
*/
function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.oktaAuth.session.get()];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/**
* Navigate browser to login page
* @return {?}
*/
VixAuthService.prototype.navigateToLoginPage = /**
* Navigate browser to login page
* @return {?}
*/
function () {
console.log('navigateToLoginPage:', this.authConfig.getLoginUrl());
document.location.href = this.authConfig.getLoginUrl();
};
/**
* Navigate browser to redirect page
*/
/**
* Navigate browser to redirect page
* @return {?}
*/
VixAuthService.prototype.navigateToRedirectPage = /**
* Navigate browser to redirect page
* @return {?}
*/
function () {
console.log('navigateToRedirectPage:', this.authConfig.getRedirectUrl());
document.location.href = this.authConfig.getRedirectUrl();
};
/**
* Logout current user and clear token
*
* @returns
*/
/**
* Logout current user and clear token
*
* @return {?}
*/
VixAuthService.prototype.logout = /**
* Logout current user and clear token
*
* @return {?}
*/
function () {
var _this = this;
if (this.isLogin()) {
this.oktaAuth.tokenManager.clear();
console.log('start to logout');
this.oktaAuth.signOut().then(function () {
console.log('logout done, to navigate', _this.authConfig.getLoginUrl());
_this.navigateToLoginPage();
});
}
};
VixAuthService.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
VixAuthService.ctorParameters = function () {
return [
{ type: angularOauth2Oidc.OAuthService, },
{ type: AuthConfigService, },
{ type: OktaService, },
];
};
return VixAuthService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* Auth guard will check user groups and app required groups and
* judge user can view the route or not
*/
var VixAuthGuard = (function () {
/**
* @param auth
* @param authConfig
* @param router
*/
function VixAuthGuard(auth, authConfig, router$$1) {
this.auth = auth;
this.authConfig = authConfig;
this.router = router$$1;
}
/**
* compare user groups and app required groups by UserGroups.hasPermission()
* canActive will cache the user groups information by 1 hour.
*
* @param route
* @param state
* @returns
*/
/**
* compare user groups and app required groups by UserGroups.hasPermission()
* canActive will cache the user groups information by 1 hour.
*
* @param {?} route
* @param {?} state
* @return {?}
*/
VixAuthGuard.prototype.canActivate = /**
* compare user groups and app required groups by UserGroups.hasPermission()
* canActive will cache the user groups information by 1 hour.
*
* @param {?} route
* @param {?} state
* @return {?}
*/
function (route, state) {
return __awaiter(this, void 0, void 0, function () {
var currentUserGroups, requireGroups;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
console.log('in authguard');
if (!this.auth.isLogin()) {
alert('Please login first.');
this.auth.navigateToLoginPage();
return [2 /*return*/, false];
}
return [4 /*yield*/, this.auth.getLoginUserGroups()];
case 1:
currentUserGroups = _a.sent();
requireGroups = /** @type {?} */ (route.data['groups']);
if (VixAuthService.hasPermission(currentUserGroups, requireGroups)) {
return [2 /*return*/, true];
}
alert('Insufficient permissions. Please contact renjie@visenze.com');
// this.auth.navigateToLoginPage();
this.auth.navigateToRedirectPage();
return [2 /*return*/, false];
}
});
});
};
VixAuthGuard.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
VixAuthGuard.ctorParameters = function () {
return [
{ type: VixAuthService, },
{ type: AuthConfigService, },
{ type: router.Router, },
];
};
return VixAuthGuard;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var VixAuthModule = (function () {
function VixAuthModule() {
}
/**
* @param {?} config
* @return {?}
*/
VixAuthModule.forRoot = /**
* @param {?} config
* @return {?}
*/
function (config) {
return {
ngModule: VixAuthModule,
providers: [
{ provide: VixAuthConfig, useValue: config }
]
};
};
VixAuthModule.decorators = [
{ type: core.NgModule, args: [{
imports: [
common.CommonModule,
http.HttpClientModule,
],
providers: [
OktaService,
VixAuthService,
AuthConfigService,
],
declarations: [],
exports: []
},] },
];
return VixAuthModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var VixLoginComponent = (function () {
function VixLoginComponent(oauth, auth, router$$1, authConfig, cdRef, ngZone) {
var _this = this;
this.oauth = oauth;
this.auth = auth;
this.router = router$$1;
this.authConfig = authConfig;
this.cdRef = cdRef;
this.ngZone = ngZone;
this.loginFormControl = new forms.FormControl('', [forms.Validators.required, forms.Validators.email]);
this.isShowProgressBar = false;
this.isShowProgressBar = false;
if (this.auth.isLogin()) {
console.log('already login in login page');
this.ngZone.run(function () {
_this.auth.navigateToRedirectPage();
});
}
}
/**
* @param {?} status
* @return {?}
*/
VixLoginComponent.prototype.toggleProgressBar = /**
* @param {?} status
* @return {?}
*/
function (status) {
this.isShowProgressBar = status;
};
/**
* Form control to validate email
*
* @returns
*/
/**
* Form control to validate email
*
* @return {?}
*/
VixLoginComponent.prototype.getErrorMessage = /**
* Form control to validate email
*
* @return {?}
*/
function () {
return this.loginFormControl.hasError('required') ? 'You must enter a value' :
this.loginFormControl.hasError('email') ? 'Not a valid email' :
'';
};
/**
* Login with Google
*/
/**
* Login with Google
* @return {?}
*/
VixLoginComponent.prototype.loginWithGoogle = /**
* Login with Google
* @return {?}
*/
function () {
this.auth.loginWithGoogle(this.authConfig.getLoginUrl());
};
/**
* Login with username and password. Redirect to url after login successfully
*/
/**
* Login with username and password. Redirect to url after login successfully
* @return {?}
*/
VixLoginComponent.prototype.loginWithPassword = /**
* Login with username and password. Redirect to url after login successfully
* @return {?}
*/
function () {
var _this = this;
if (this.loginFormControl.invalid) {
alert('Email is not valid!');
return;
}
this.toggleProgressBar(true);
this.auth.loginWithPassword(this.email, this.password)
.then(function () {
// this.router.navigate([this.authConfig.getRoute()]);
// this.router.navigate([this.authConfig.getRoute()]);
_this.auth.navigateToRedirectPage();
})
.catch(function (err) {
_this.toggleProgressBar(false);
console.log('login with username and password failed', err);
alert('Username or Password error, cannot login');
});
};
/**
* @return {?}
*/
VixLoginComponent.prototype.ngAfterViewChecked = /**
* @return {?}
*/
function () {
this.cdRef.detectChanges();
};
/**
* This is used for Google Login. Browser will redirect to the login url after login successfully.
* ngAfterViewInit will get the access_token from url and redirect to the url set as redirect url.
*/
/**
* This is used for Google Login. Browser will redirect to the login url after login successfully.
* ngAfterViewInit will get the access_token from url and redirect to the url set as redirect url.
* @return {?}
*/
VixLoginComponent.prototype.ngAfterViewInit = /**
* This is used for Google Login. Browser will redirect to the login url after login successfully.
* ngAfterViewInit will get the access_token from url and redirect to the url set as redirect url.
* @return {?}
*/
function () {
var _this = this;
var /** @type {?} */ regexp = new RegExp('[#|\?]id_token=([^&]*)[&]{0,1}');
var /** @type {?} */ idTokenRegex = regexp.exec(this.router.url);
if (idTokenRegex) {
console.log('has idToken', idTokenRegex);
this.toggleProgressBar(true);
// has idToken in url
this.auth.getSession().then(function (session) {
if (session.status === 'ACTIVE') {
console.log('session ACTIVE');
_this.auth.setUserId(session.userId);
_this.ngZone.run(function () {
_this.auth.navigateToRedirectPage();
});
}
else {
console.log('session INACTIVE');
_this.ngZone.run(function () {
_this.auth.navigateToLoginPage();
});
}
});
}
};
VixLoginComponent.decorators = [
{ type: core.Component, args: [{
selector: 'vix-log-in',
template: "<title>ViSenze Sign In</title>\n<div class=\"background\">\n <img class=\"logo\" src=\"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAAAAAAAD/7QFkUGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAUgcAgUADFZJU0VOWkUgTE9HTxwCDwADQSBGHAIZAApURUNITk9MT0dZHAIeAAgyMDE0MDIxORwCIwAEMDAwMBwCKABaU0VFIFNUT1JZIDIwMTQwMjE5L0hLNjY4MDRMT0dPLCBNTSAoOTg1NjU0KSBNZWRpYSBjb250YWN0OiBPbGl2ZXIgVGFuLCBvbGl2ZXJAdmlzZW56ZS5jb20uHAI3ABcyMDE0MDIxOFQwMDowMDowMC0wNTowMBwCWgAJU0lOR0FQT1JFHAJkAANTR1AcAmUACVNJTkdBUE9SRRwCaQAMVklTRU5aRSBMT0dPHAJuAAtQUiBORVdTV0lSRRwCcwAHVklTRU5aRRwCeAAjVmlTZW56ZSBMb2dvLiAgKFBSTmV3c0ZvdG8vVmlTZW56ZSkcAnoAAlJEHAL6AAoxNDAwIHggMzY3/+EOPUV4aWYAAE1NACoAAAAIAAcBEgADAAAAAQAAAAABGgAFAAAAAQAAAGIBGwAFAAAAAQAAAGoBKAADAAAAAQACAAABMQACAAAAHAAAAHIBMgACAAAAFAAAAI6HaQAEAAAAAQAAAKQAAADQAAAAAAAAAAEAAAAAAAAAAUFkb2JlIFBob3Rvc2hvcCBDUzMgV2luZG93cwAyMDE0OjAyOjE4IDA5OjI3OjA3AAAAAAOgAQADAAAAAQABAACgAgAEAAAAAQAABXigAwAEAAAAAQAAAW8AAAAAAAAABgEDAAMAAAABAAYAAAEaAAUAAAABAAABHgEbAAUAAAABAAABJgEoAAMAAAABAAIAAAIBAAQAAAABAAABLgICAAQAAA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