mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ADF-3666] User Profile - Provide a way to show SSO Logged-In User (#3976)
* * Created IdentityUserService * Created IdentityUserModel * Added JWT lib into package.json * * Provided a way to show SSO user info * * Added condition to check sso login * * Refactored userInfo component* Updated unit tests to the recent changes * * Created IdenityUser model * Refactored userInfoComponent * * Modified userInfoComponent * Modified unit tests * * Used Fullname pipe* Removed the logic that we had to display fullname in the ecm/bpm/identity model* Created JwtHelperService* Modified ecm/bpm services * added test cases to the identity service * * Moved jwt service to core/service * * Updated userInfo doc * * Added missing return types * * Created a mockToken* Added unit tests to the JwtHelperService* Updated identityUserService unit test * Update jwt-helper.service.spec.ts * * Updated bpm/ecm/identity services
This commit is contained in:
committed by
Maurizio Vitale
parent
a39e44e4a9
commit
974929e76d
@@ -0,0 +1,45 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { JwtHelperService } from './jwt-helper.service';
|
||||
import { mockToken } from './../mock/jwt-helper.service.spec';
|
||||
|
||||
describe('JwtHelperService', () => {
|
||||
|
||||
let jwtHelperService: JwtHelperService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [JwtHelperService]
|
||||
});
|
||||
jwtHelperService = TestBed.get(JwtHelperService);
|
||||
});
|
||||
|
||||
it('should be able to create the service', () => {
|
||||
expect(jwtHelperService).not.toBeNull();
|
||||
expect(jwtHelperService).toBeDefined();
|
||||
});
|
||||
|
||||
it('Should decode the Jwt token', () => {
|
||||
const result = jwtHelperService.decodeToken(mockToken);
|
||||
expect(result).toBeDefined();
|
||||
expect(result).not.toBeNull('');
|
||||
expect(result['given_name']).toBe('John Doe');
|
||||
expect(result['email']).toBe('johnDoe@gmail.com');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class JwtHelperService {
|
||||
|
||||
constructor() {}
|
||||
|
||||
decodeToken(token): Object {
|
||||
let parts = token.split('.');
|
||||
|
||||
if (parts.length !== 3) {
|
||||
throw new Error('JWT must have 3 parts');
|
||||
}
|
||||
|
||||
let decoded = this.urlBase64Decode(parts[1]);
|
||||
if (!decoded) {
|
||||
throw new Error('Cannot decode the token');
|
||||
}
|
||||
|
||||
return JSON.parse(decoded);
|
||||
}
|
||||
|
||||
private urlBase64Decode(token): string {
|
||||
let output = token.replace(/-/g, '+').replace(/_/g, '/');
|
||||
switch (output.length % 4) {
|
||||
case 0: {
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
output += '==';
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
output += '=';
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error('Illegal base64url string!');
|
||||
}
|
||||
}
|
||||
return decodeURIComponent(escape(window.atob(output)));
|
||||
}
|
||||
}
|
||||
@@ -50,3 +50,4 @@ export * from './search-configuration.service';
|
||||
export * from './comment-content.service';
|
||||
export * from './login-dialog.service';
|
||||
export * from './external-alfresco-api.service';
|
||||
export * from './jwt-helper.service';
|
||||
|
||||
Reference in New Issue
Block a user