Skip to content

Commit b2fc18d

Browse files
committed
fix: passkey origin
Signed-off-by: Innei <i@innei.in>
1 parent 0858ba1 commit b2fc18d

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

apps/core/src/modules/authn/authn.service.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { CacheService } from '~/processors/redis/cache.service'
1212
import { InjectModel } from '~/transformers/model.transformer'
1313
import { getRedisKey } from '~/utils'
1414

15+
import { RequestContext } from '~/common/contexts/request.context'
1516
import { ConfigsService } from '../configs/configs.service'
1617
import { AuthnModel } from './authn.model'
1718
import type { UserDocument } from '../user/user.model'
@@ -36,20 +37,29 @@ export class AuthnService {
3637
) {}
3738

3839
private async getConfig() {
40+
const headers = RequestContext.currentRequest()?.headers
41+
const origin = headers?.origin
42+
const host = (() => {
43+
try {
44+
return new URL(origin ?? '').hostname
45+
} catch {
46+
return null
47+
}
48+
})()
3949
if (isDev) {
4050
return {
41-
rpID: 'localhost',
42-
expectedOrigin: ['http://localhost:9528'],
43-
expectedRPID: 'localhost',
51+
rpID: host ?? 'localhost',
52+
expectedOrigin: origin ?? ['http://localhost:9528'],
53+
expectedRPID: host ?? 'localhost',
4454
}
4555
}
4656
const { adminUrl } = await this.configService.get('url')
4757

4858
const parsedUrl = new URL(adminUrl)
4959
return {
50-
rpID: parsedUrl.hostname,
51-
expectedOrigin: [parsedUrl.origin],
52-
expectedRPID: parsedUrl.hostname,
60+
rpID: host ?? parsedUrl.hostname,
61+
expectedOrigin: origin ?? [parsedUrl.origin],
62+
expectedRPID: host ?? parsedUrl.hostname,
5363
}
5464
}
5565

0 commit comments

Comments
 (0)