Skip to content

Commit 20cfbaa

Browse files
committed
feat(api): save last logged at and identity provider in #reconcileOidcUserForAdmin
1 parent d58903f commit 20cfbaa

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

api/src/identity-access-management/domain/usecases/reconcile-oidc-user-for-admin.usecase.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,37 @@ export const reconcileOidcUserForAdmin = async function ({
6666

6767
const accessToken = await oidcAuthenticationService.createAccessToken({ userId, audience });
6868

69+
await _updateUserLastConnection({
70+
userLoginRepository,
71+
userId,
72+
lastUserApplicationConnectionsRepository,
73+
requestedApplication,
74+
authenticationMethodRepository,
75+
oidcAuthenticationService,
76+
});
77+
78+
return accessToken;
79+
};
80+
81+
async function _updateUserLastConnection({
82+
userLoginRepository,
83+
userId,
84+
lastUserApplicationConnectionsRepository,
85+
requestedApplication,
86+
authenticationMethodRepository,
87+
oidcAuthenticationService,
88+
}) {
6989
await userLoginRepository.updateLastLoggedAt({ userId });
7090
await lastUserApplicationConnectionsRepository.upsert({
7191
userId,
7292
application: requestedApplication.applicationName,
7393
lastLoggedAt: new Date(),
7494
});
75-
76-
return accessToken;
77-
};
95+
return await authenticationMethodRepository.updateLastLoggedAtByIdentityProvider({
96+
userId,
97+
identityProvider: oidcAuthenticationService.identityProvider,
98+
});
99+
}
78100

79101
async function _assertExternalIdentifier({
80102
sessionContentAndUserInfo,

api/tests/identity-access-management/unit/domain/usecases/reconcile-oidc-user-for-admin.usecase.test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ describe('Unit | Identity Access Management | Domain | UseCase | reconcile-oidc-
1919
const requestedApplication = new RequestedApplication('admin');
2020

2121
beforeEach(function () {
22-
authenticationMethodRepository = { create: sinon.stub(), findOneByUserIdAndIdentityProvider: sinon.stub() };
22+
authenticationMethodRepository = {
23+
create: sinon.stub(),
24+
findOneByUserIdAndIdentityProvider: sinon.stub(),
25+
updateLastLoggedAtByIdentityProvider: sinon.stub(),
26+
};
2327
userRepository = { getByEmail: sinon.stub() };
2428
userLoginRepository = { updateLastLoggedAt: sinon.stub() };
2529
authenticationSessionService = { getByKey: sinon.stub() };
@@ -144,7 +148,7 @@ describe('Unit | Identity Access Management | Domain | UseCase | reconcile-oidc-
144148
expect(result).to.equal('accessToken');
145149
});
146150

147-
it('saves the last user application connection', async function () {
151+
it('saves the last user connection', async function () {
148152
// given
149153
const email = 'anne@example.net';
150154
const externalIdentifier = 'external_id';
@@ -182,6 +186,10 @@ describe('Unit | Identity Access Management | Domain | UseCase | reconcile-oidc-
182186
application: 'admin',
183187
lastLoggedAt: sinon.match.instanceOf(Date),
184188
});
189+
expect(authenticationMethodRepository.updateLastLoggedAtByIdentityProvider).to.be.calledWithMatch({
190+
userId,
191+
identityProvider: oidcAuthenticationService.identityProvider,
192+
});
185193
});
186194

187195
context('when authentication key is expired', function () {

0 commit comments

Comments
 (0)