1+ import { stringify } from 'qs' ;
2+ import { generateConfigs } from '../helper' ;
13import { MY_ACCOUNT_DOMAINS } from '../server-paths' ;
24import { StoredOptions , TokenInfo } from '../typings' ;
35
@@ -11,12 +13,17 @@ export default async function tokenInfo(
1113 throw new Error ( '[mt-link-sdk] Missing parameter `token` in `tokenInfo`.' ) ;
1214 }
1315
16+ const queryString = stringify ( {
17+ client_id : clientId ,
18+ configs : generateConfigs ( )
19+ } )
20+
1421 try {
15- const response = await fetch ( `${ MY_ACCOUNT_DOMAINS [ mode ] } /oauth/token/info.json` , {
22+ const response = await fetch ( `${ MY_ACCOUNT_DOMAINS [ mode ] } /oauth/token/info.json? ${ queryString } ` , {
1623 method : 'GET' ,
1724 headers : {
1825 Authorization : `Bearer ${ token } ` ,
19- 'x-api-key ' : clientId as string ,
26+ 'API-Version ' : '1604911588' ,
2027 } ,
2128 } ) ;
2229
@@ -26,18 +33,7 @@ export default async function tokenInfo(
2633 throw new Error ( result . error_description ) ;
2734 }
2835
29- return {
30- guestUid : result . uid ,
31- resourceServer : result . resource_server ,
32- country : result . country ,
33- currency : result . currency ,
34- language : result . locale ,
35- clientId : result . aud . uid ,
36- clientName : result . aud . name ,
37- expTimestamp : result . exp ,
38- scopes : result . scopes ,
39- isMtClient : result . is_mt_client ,
40- } ;
36+ return result ;
4137 } catch ( error ) {
4238 throw new Error ( `[mt-link-sdk] \`tokenInfo\` execution failed. ${ error } ` ) ;
4339 }
0 commit comments