You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by an...@apache.org on 2019/10/16 10:16:58 UTC

[incubator-dlab] 02/06: [DLAB-1157]: added refresh token store

This is an automated email from the ASF dual-hosted git repository.

ankovalyshyn pushed a commit to branch DLAB-1157
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git

commit 6501649437885d0f9ea12e135db716629acddde8
Author: Andriana Kovalyshyn <An...@epam.com>
AuthorDate: Tue Oct 15 12:23:52 2019 +0300

    [DLAB-1157]: added refresh token store
---
 .../core/services/applicationSecurity.service.ts   | 28 ++++++++++++----------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/services/self-service/src/main/resources/webapp/src/app/core/services/applicationSecurity.service.ts b/services/self-service/src/main/resources/webapp/src/app/core/services/applicationSecurity.service.ts
index c6b161c..8b4f021 100644
--- a/services/self-service/src/main/resources/webapp/src/app/core/services/applicationSecurity.service.ts
+++ b/services/self-service/src/main/resources/webapp/src/app/core/services/applicationSecurity.service.ts
@@ -19,7 +19,7 @@
 
 import { Injectable } from '@angular/core';
 import { of as observableOf, Observable, BehaviorSubject } from 'rxjs';
-import { catchError, map } from 'rxjs/operators';
+import { catchError, map, tap } from 'rxjs/operators';
 
 import { ApplicationServiceFacade } from './applicationServiceFacade.service';
 import { AppRoutingService } from './appRouting.service';
@@ -59,13 +59,8 @@ export class ApplicationSecurityService {
       .pipe(
         map(response => {
           if (response.status === HTTP_STATUS_CODES.OK) {
-            if (!DICTIONARY.use_ldap) {
-              this.storage.setAuthToken(response.body.access_token);
-              this.storage.setUserName(response.body.username);
-            } else {
-              this.storage.setAuthToken(response.body);
-              this.storage.setUserName(loginModel.username);
-            }
+            this.storage.storeTokens(response.body);
+            this.storage.setUserName(response.body.username);
             this._loggedInStatus.next(true);
             return true;
           }
@@ -75,7 +70,14 @@ export class ApplicationSecurityService {
         catchError(ErrorUtils.handleServiceError));
   }
 
-  public logout(): Observable<boolean> {
+  public refreshToken() {
+    const refreshTocken = `/${this.storage.getRefreshToken()}`;
+    return this.serviceFacade.buildRefreshToken(refreshTocken)
+      .pipe(
+        tap((tokens) => this.storage.storeTokens(tokens)))
+  }
+
+  public logout(): Observable<any> {
     const authToken = this.storage.getToken();
 
     if (!!authToken) {
@@ -83,7 +85,7 @@ export class ApplicationSecurityService {
         .buildLogoutRequest()
         .pipe(
           map(response => {
-            this.storage.destroyToken();
+            this.storage.destroyTokens();
             this.storage.setBillingQuoteUsed('');
             this._loggedInStatus.next(false);
             return response;
@@ -106,12 +108,12 @@ export class ApplicationSecurityService {
               return true;
             }
 
-            this.storage.destroyToken();
+            this.storage.destroyTokens();
             return false;
           }),
           catchError(error => {
             this.emmitMessage(error.message);
-            this.storage.destroyToken();
+            this.storage.destroyTokens();
 
             return observableOf(false);
           }));
@@ -129,7 +131,7 @@ export class ApplicationSecurityService {
         map((response: any) => {
           const data = response.body;
           if (response.status === HTTP_STATUS_CODES.OK && data.access_token) {
-            this.storage.setAuthToken(data.access_token);
+            this.storage.storeTokens(data);
             this.storage.setUserName(data.username);
 
             this.appRoutingService.redirectToHomePage();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org