Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit 68fa540

Browse files
authored
[ACA-4317][JS-API] CS silent refresh is not working for content service (#1024)
* fix viewer * * fix cs silent refresh * * revert old fix * * removded duplicate call * * remove imports * * added test case * * test
1 parent c9498e9 commit 68fa540

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/authentication/oauth2Auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ export class Oauth2Auth extends AlfrescoApiClient {
714714
}
715715

716716
exchangeTicketListener(alfrescoApi: AlfrescoApi) {
717-
this.once('token_issued', async () => {
717+
this.on('token_issued', async () => {
718718
const authContentApi: AuthenticationApi = new AuthenticationApi(alfrescoApi);
719719
authContentApi.apiClient.authentications = this.authentications;
720720
try {

test/oauth2Auth.spec.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ describe('Oauth2 test', () => {
301301
authType: 'OAUTH'
302302
});
303303

304-
alfrescoApi.oauth2Auth.once('ticket_exchanged', () => {
304+
alfrescoApi.oauth2Auth.on('ticket_exchanged', () => {
305305
expect(alfrescoApi.config.ticketEcm).to.be.equal('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
306306
expect(alfrescoApi.contentClient.config.ticketEcm).to.be.equal('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
307307

@@ -335,7 +335,7 @@ describe('Oauth2 test', () => {
335335

336336
const contentApi = new ContentApi(alfrescoApi);
337337

338-
alfrescoApi.oauth2Auth.once('ticket_exchanged', () => {
338+
alfrescoApi.oauth2Auth.on('ticket_exchanged', () => {
339339
expect(alfrescoApi.config.ticketEcm).to.be.equal('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
340340
expect(alfrescoApi.contentClient.config.ticketEcm).to.be.equal('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
341341

@@ -349,6 +349,44 @@ describe('Oauth2 test', () => {
349349
alfrescoApi.login('admin', 'admin');
350350
});
351351

352+
it('should extend content session after oauth token refresh', function (done) {
353+
oauth2Mock.get200Response();
354+
authResponseMock.get200ValidTicket();
355+
356+
const alfrescoApi = new AlfrescoApi(<AlfrescoApiConfig> {
357+
hostEcm: 'http://myOauthUrl:30081',
358+
oauth2: {
359+
'host': 'http://myOauthUrl:30081/auth/realms/springboot',
360+
'clientId': 'activiti',
361+
'scope': 'openid',
362+
'secret': '',
363+
'redirectUri': '/',
364+
'redirectUriLogout': '/logout'
365+
},
366+
authType: 'OAUTH'
367+
});
368+
369+
let counterCallEvent = 0;
370+
alfrescoApi.oauth2Auth.on('ticket_exchanged', () => {
371+
expect(alfrescoApi.config.ticketEcm).to.be.equal('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
372+
expect(alfrescoApi.contentClient.config.ticketEcm).to.be.equal('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
373+
374+
let content = new ContentApi(alfrescoApi);
375+
let URL = content.getContentUrl('FAKE-NODE-ID');
376+
expect(URL).to.be.equal('http://myOauthUrl:30081/alfresco/api/-default-/public/alfresco/versions/1/nodes/FAKE-NODE-ID/content?attachment=false&alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
377+
378+
counterCallEvent++;
379+
380+
if (counterCallEvent === 2) {
381+
done();
382+
}
383+
});
384+
385+
alfrescoApi.login('admin', 'admin');
386+
this.timeout(3000);
387+
alfrescoApi.refreshToken();
388+
});
389+
352390
it('isLoggedIn should return true if the api is logged in', (done) => {
353391
oauth2Mock.get200Response();
354392

0 commit comments

Comments
 (0)