From 74851ac651686106d1cda4f1a0b6ce74bcef540c Mon Sep 17 00:00:00 2001 From: Deepak Paul Date: Fri, 23 Nov 2018 15:01:55 +0530 Subject: [PATCH] [ADF-3540] Start Task Cloud by cli - Core module changes (#4006) * [ADF-3540] Added username and id to the usermodel * [ADF-3540] Added tests --- lib/core/mock/jwt-helper.service.spec.ts | 11 ++++++----- lib/core/userinfo/models/identity-user.model.ts | 4 ++++ .../userinfo/services/identity-user.service.spec.ts | 1 + lib/core/userinfo/services/identity-user.service.ts | 4 +++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/core/mock/jwt-helper.service.spec.ts b/lib/core/mock/jwt-helper.service.spec.ts index 9329ed525e..bf0ef3bf26 100644 --- a/lib/core/mock/jwt-helper.service.spec.ts +++ b/lib/core/mock/jwt-helper.service.spec.ts @@ -15,8 +15,9 @@ * limitations under the License. */ -export let mockToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.' - + 'eyJzdWIiOiIxMjM0NTY3ODkwIiwiZW1haWwiOiJqb2huRG9lQGdtYWlsLmNvbSI' - + 'sImdpdmVuX25hbWUiOiJKb2huIERvZSIsImp0aSI6IjY1ZGMzZTEyLWJhNGUtNDQ' - + '2Mi1iZjAyLTBlZGQ2MTYwM2M2NCIsImlhdCI6MTU0MjcyMTYxMywiZXhwIjoxNTQyNzI3NzY5fQ' - + '.cUxMzfiJeLwh9Er2CBn_y8ehQgSm_s2-NHehx-SRZKg'; +export let mockToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIx' + + 'MjM0NTY3ODkwIiwiZW1haWwiOiJqb2huRG9lQGdtYWlsLmNvbSIsImdpdmVuX25h' + + 'bWUiOiJKb2huIERvZSIsInByZWZlcnJlZF91c2VybmFtZSI6ImpvaG5Eb2UxIiwi' + + 'anRpIjoiNjVkYzNlMTItYmE0ZS00NDYyLWJmMDItMGVkZDYxNjAzYzY0IiwiaWF0' + + 'IjoxNTQyNzIxNjEzLCJleHAiOjE1NDI3Mjc3Njl9.W-KUqsy5IBVgG0RhZTvTUXY' + + '1no5wE9lghKXGFNgFbuA'; diff --git a/lib/core/userinfo/models/identity-user.model.ts b/lib/core/userinfo/models/identity-user.model.ts index 75a707a471..f10e50773a 100644 --- a/lib/core/userinfo/models/identity-user.model.ts +++ b/lib/core/userinfo/models/identity-user.model.ts @@ -17,15 +17,19 @@ export class IdentityUserModel { + id: string; firstName: string; lastName: string; email: string; + username: string; constructor(obj?: any) { if (obj) { + this.id = obj.id || null; this.firstName = obj.firstName || null; this.lastName = obj.lastName || null; this.email = obj.email || null; + this.username = obj.username || null; } } } diff --git a/lib/core/userinfo/services/identity-user.service.spec.ts b/lib/core/userinfo/services/identity-user.service.spec.ts index ba943fcdaa..2c699cf547 100644 --- a/lib/core/userinfo/services/identity-user.service.spec.ts +++ b/lib/core/userinfo/services/identity-user.service.spec.ts @@ -54,6 +54,7 @@ describe('IdentityUserService', () => { expect(user.firstName).toEqual('John'); expect(user.lastName).toEqual('Doe'); expect(user.email).toEqual('johnDoe@gmail.com'); + expect(user.username).toEqual('johnDoe1'); done(); }); }); diff --git a/lib/core/userinfo/services/identity-user.service.ts b/lib/core/userinfo/services/identity-user.service.ts index 4f4db75e97..26eaf79e38 100644 --- a/lib/core/userinfo/services/identity-user.service.ts +++ b/lib/core/userinfo/services/identity-user.service.ts @@ -28,14 +28,16 @@ export class IdentityUserService { static USER_NAME = 'given_name'; static USER_EMAIL = 'email'; static USER_ACCESS_TOKEN = 'access_token'; + static USER_PREFERRED_USERNAME = 'preferred_username'; constructor(private helper: JwtHelperService) {} getCurrentUserInfo(): Observable { const fullName = this.getValueFromToken(IdentityUserService.USER_NAME); const email = this.getValueFromToken(IdentityUserService.USER_EMAIL); + const username = this.getValueFromToken(IdentityUserService.USER_PREFERRED_USERNAME); const nameParts = fullName.split(' '); - const user = { firstName: nameParts[0], lastName: nameParts[1], email: email }; + const user = { firstName: nameParts[0], lastName: nameParts[1], email: email, username: username }; return of(new IdentityUserModel(user)); }