Skip to content

Commit

Permalink
Merge pull request #70 from wwWallet/openid4vci/refresh-token
Browse files Browse the repository at this point in the history
Additions required for the refresh token grant type implementation
  • Loading branch information
kkmanos authored Oct 25, 2024
2 parents dd53c46 + 8c3082c commit 86b0737
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/entities/VerifiableCredential.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export class VerifiableCredentialEntity {

@Column({ type: "varchar", nullable: false })
format: string;

@Column({ type: "varchar", nullable: false, default: "" })
credentialConfigurationId: string = "";

@Column({ type: "varchar", nullable: false, default: "" })
credentialIssuerIdentifier: string = "";
}


Expand Down
3 changes: 3 additions & 0 deletions src/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class UserEntity {

@OneToMany(() => FcmTokenEntity, (fcmToken) => fcmToken.user, { eager: true })
fcmTokenList: FcmTokenEntity[];

@Column({ nullable: false, default: 3600 })
openidRefreshTokenMaxAgeInSeconds: number;
}

@Entity({ name: "webauthn_credential" })
Expand Down
27 changes: 27 additions & 0 deletions src/routers/user.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ userController.get('/account-info', async (req: Request, res: Response) => {
username: user.username,
displayName: user.displayName,
hasPassword: user.passwordHash !== null,
settings: {
openidRefreshTokenMaxAgeInSeconds: user.openidRefreshTokenMaxAgeInSeconds,
},
webauthnCredentials: (user.webauthnCredentials || []).map(cred => ({
createTime: cred.createTime,
credentialId: cred.credentialId,
Expand Down Expand Up @@ -597,4 +600,28 @@ userController.delete('/', async (req: Request, res: Response) => {
}
});


userController.post('/settings', async (req: Request, res: Response) => {
try {
const {
openidRefreshTokenMaxAgeInSeconds
} = req.body;
const userRes = await getUser(req.user.id);

if (userRes.ok) {
const user = userRes.unwrap();
await updateUser(user.uuid, (userEntity, manager) => {
userEntity.openidRefreshTokenMaxAgeInSeconds = openidRefreshTokenMaxAgeInSeconds;
manager.save(userEntity);
return userEntity;
})
return res.send({ openidRefreshTokenMaxAgeInSeconds: user.openidRefreshTokenMaxAgeInSeconds })
}
return res.status(400).send({ error: userRes.err });
}
catch (err) {
return res.status(500).send({ error: err });
}
});

export default noAuthUserController;

0 comments on commit 86b0737

Please sign in to comment.