@@ -38,35 +38,58 @@ export function defineOAuthSteamEventHandler({ config, onSuccess, onError }: OAu
38
38
return handleMissingConfiguration ( event , 'steam' , [ 'apiKey' ] , onError )
39
39
}
40
40
41
+ const url = getRequestURL ( event )
42
+
41
43
if ( ! query [ 'openid.claimed_id' ] ) {
42
44
const redirectURL = config . redirectURL || getRequestURL ( event ) . href
43
45
const steamOpenIdParams = {
44
46
'openid.ns' : 'http://specs.openid.net/auth/2.0' ,
45
47
'openid.mode' : 'checkid_setup' ,
46
48
'openid.return_to' : redirectURL ,
49
+ 'openid.realm' : `${ url . protocol } //${ url . hostname } ` ,
47
50
'openid.identity' : 'http://specs.openid.net/auth/2.0/identifier_select' ,
48
51
'openid.claimed_id' : 'http://specs.openid.net/auth/2.0/identifier_select' ,
49
52
}
50
53
// Redirect to Steam Oauth page
51
54
return sendRedirect ( event , withQuery ( config . authorizationURL as string , steamOpenIdParams ) )
52
55
}
53
56
54
- const openIdCheck = {
55
- ns : 'http://specs.openid.net/auth/2.0' ,
56
- claimed_id : 'https://steamcommunity.com/openid/id/' ,
57
- identity : 'https://steamcommunity.com/openid/id/' ,
57
+ if ( ! query [ 'openid.signed' ]
58
+ || ! query [ 'openid.sig' ]
59
+ ) {
60
+ const error = createError ( {
61
+ statusCode : 400 ,
62
+ message : 'Steam login failed: Incomplete query.' ,
63
+ } )
64
+ if ( ! onError ) throw error
65
+ return onError ( event , error )
58
66
}
59
67
60
- const idRegex = / ^ h t t p s ? : \/ \/ s t e a m c o m m u n i t y \. c o m \/ o p e n i d \/ i d \/ ( \d + ) $ /
61
- const steamIdCheck = idRegex . exec ( query [ 'openid.claimed_id' ] )
68
+ const openIdCheck : Record < string , string > = {
69
+ 'openid.ns' : 'http://specs.openid.net/auth/2.0' ,
70
+ 'openid.mode' : 'check_authentication' ,
71
+ 'openid.signed' : query [ 'openid.signed' ] ,
72
+ 'openid.sig' : query [ 'openid.sig' ] ,
73
+ }
62
74
63
- if (
64
- query [ 'openid.op_endpoint' ] !== config . authorizationURL
65
- || ! steamIdCheck
66
- || query [ 'openid.ns' ] !== openIdCheck . ns
67
- || ! query [ 'openid.claimed_id' ] ?. startsWith ( openIdCheck . claimed_id )
68
- || ! query [ 'openid.identity' ] ?. startsWith ( openIdCheck . identity )
69
- ) {
75
+ for ( const signed of query [ 'openid.signed' ] . split ( ',' ) ) {
76
+ if ( ! query [ `openid.${ signed } ` ] ) {
77
+ const error = createError ( {
78
+ statusCode : 400 ,
79
+ message : 'Steam login failed: Incomplete query.' ,
80
+ } )
81
+ if ( ! onError ) throw error
82
+ return onError ( event , error )
83
+ }
84
+ openIdCheck [ `openid.${ signed } ` ] = query [ `openid.${ signed } ` ]
85
+ }
86
+
87
+ const auth_validation : string = await $fetch ( withQuery ( config ?. authorizationURL as string , openIdCheck ) )
88
+
89
+ const validRegex = / i s _ v a l i d : t r u e /
90
+ const valid = validRegex . test ( auth_validation )
91
+
92
+ if ( ! valid ) {
70
93
const error = createError ( {
71
94
statusCode : 401 ,
72
95
message : 'Steam login failed: Claimed identity is invalid.' ,
@@ -75,6 +98,9 @@ export function defineOAuthSteamEventHandler({ config, onSuccess, onError }: OAu
75
98
return onError ( event , error )
76
99
}
77
100
101
+ const idRegex = / ^ h t t p s ? : \/ \/ s t e a m c o m m u n i t y \. c o m \/ o p e n i d \/ i d \/ ( \d + ) $ /
102
+ const steamIdCheck = idRegex . exec ( query [ 'openid.claimed_id' ] )
103
+
78
104
const steamId = steamIdCheck [ 1 ]
79
105
80
106
// TODO: improve typing
0 commit comments