@@ -12,6 +12,7 @@ import { CacheService } from '~/processors/redis/cache.service'
12
12
import { InjectModel } from '~/transformers/model.transformer'
13
13
import { getRedisKey } from '~/utils'
14
14
15
+ import { RequestContext } from '~/common/contexts/request.context'
15
16
import { ConfigsService } from '../configs/configs.service'
16
17
import { AuthnModel } from './authn.model'
17
18
import type { UserDocument } from '../user/user.model'
@@ -36,20 +37,29 @@ export class AuthnService {
36
37
) { }
37
38
38
39
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
+ } ) ( )
39
49
if ( isDev ) {
40
50
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' ,
44
54
}
45
55
}
46
56
const { adminUrl } = await this . configService . get ( 'url' )
47
57
48
58
const parsedUrl = new URL ( adminUrl )
49
59
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 ,
53
63
}
54
64
}
55
65
0 commit comments