mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
chore: rename linkToken to oauthLinkToken
This commit is contained in:
@@ -23,7 +23,7 @@ const LoginCredentialSchema = z
|
||||
.object({
|
||||
email: toEmail.describe('User email').meta({ example: 'testuser@email.com' }),
|
||||
password: z.string().describe('User password').meta({ example: 'password' }),
|
||||
linkToken: z.string().optional().describe('OAuth link token to consume on successful login'),
|
||||
oauthLinkToken: z.string().optional().describe('OAuth link token to consume on successful login'),
|
||||
})
|
||||
.meta({ id: 'LoginCredentialDto' });
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ describe(AuthService.name, () => {
|
||||
expect(mocks.user.getByEmail).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should link an OAuth account when linkToken is provided', async () => {
|
||||
it('should link an OAuth account when oauthLinkToken is provided', async () => {
|
||||
const user = UserFactory.create({ password: 'immich_password' });
|
||||
const session = SessionFactory.create();
|
||||
mocks.user.getByEmail.mockResolvedValue(user);
|
||||
@@ -104,20 +104,20 @@ describe(AuthService.name, () => {
|
||||
});
|
||||
mocks.user.update.mockResolvedValue(user);
|
||||
|
||||
await sut.login({ email, password: 'password', linkToken: 'plain-token' }, loginDetails);
|
||||
await sut.login({ email, password: 'password', oauthLinkToken: 'plain-token' }, loginDetails);
|
||||
|
||||
expect(mocks.oauthLinkToken.consumeToken).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.user.update).toHaveBeenCalledWith(user.id, { oauthId: 'oauth-sub-123' });
|
||||
});
|
||||
|
||||
it('should reject login with invalid linkToken', async () => {
|
||||
it('should reject login with invalid oauthLinkToken', async () => {
|
||||
const user = UserFactory.create({ password: 'immich_password' });
|
||||
mocks.user.getByEmail.mockResolvedValue(user);
|
||||
mocks.oauthLinkToken.consumeToken.mockResolvedValue(null as any);
|
||||
|
||||
await expect(sut.login({ email, password: 'password', linkToken: 'bad-token' }, loginDetails)).rejects.toThrow(
|
||||
'Invalid or expired link token',
|
||||
);
|
||||
await expect(
|
||||
sut.login({ email, password: 'password', oauthLinkToken: 'bad-token' }, loginDetails),
|
||||
).rejects.toThrow('Invalid or expired link token');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -75,8 +75,8 @@ export class AuthService extends BaseService {
|
||||
throw new UnauthorizedException('Incorrect email or password');
|
||||
}
|
||||
|
||||
if (dto.linkToken) {
|
||||
const hashedToken = this.cryptoRepository.hashSha256(dto.linkToken);
|
||||
if (dto.oauthLinkToken) {
|
||||
const hashedToken = this.cryptoRepository.hashSha256(dto.oauthLinkToken);
|
||||
const record = await this.oauthLinkTokenRepository.consumeToken(hashedToken);
|
||||
if (!record) {
|
||||
throw new BadRequestException('Invalid or expired link token');
|
||||
@@ -350,7 +350,7 @@ export class AuthService extends BaseService {
|
||||
throw new ForbiddenException({
|
||||
message: 'oauth_account_link_required',
|
||||
userEmail: emailUser.email,
|
||||
linkToken: plainToken,
|
||||
oauthLinkToken: plainToken,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user