@@ -15,22 +15,33 @@ export class AllureServiceClient {
1515 throw new Error ( "Allure service access token is required" ) ;
1616 }
1717
18- const [ prefix , body ] = atob ( config . accessToken ) . split ( ":" ) ;
18+ const { iss , projectId , url : baseUrl } = this . decodeToken ( config . accessToken ) ?? { } ;
1919
20- if ( prefix !== "allure-service" ) {
21- throw new Error ( "Invalid access token" ) ;
22- }
23-
24- const { projectId, url : baseUrl } = JSON . parse ( atob ( body ) ) ;
25-
26- if ( ! baseUrl || ! projectId ) {
20+ if ( iss !== "allure-service" || ! baseUrl || ! projectId ) {
2721 throw new Error ( "Invalid access token" ) ;
2822 }
2923
3024 this . #url = baseUrl ;
3125 this . #client = createServiceHttpClient ( this . #url, config . accessToken ) ;
3226 }
3327
28+ decodeToken ( token : string ) {
29+ try {
30+ const base64Url = token . split ( "." ) [ 1 ] ;
31+ const base64 = base64Url . replace ( / - / g, "+" ) . replace ( / _ / g, "/" ) ;
32+ const jsonPayload = decodeURIComponent (
33+ atob ( base64 )
34+ . split ( "" )
35+ . map ( ( c ) => `%${ `00${ c . charCodeAt ( 0 ) . toString ( 16 ) } ` . slice ( - 2 ) } ` )
36+ . join ( "" ) ,
37+ ) ;
38+
39+ return JSON . parse ( jsonPayload ) ;
40+ } catch {
41+ return undefined ;
42+ }
43+ }
44+
3445 /**
3546 * Returns user profile and current project
3647 */
@@ -98,7 +109,9 @@ export class AllureServiceClient {
98109 async downloadHistory ( payload : { branch : string ; limit ?: number } ) {
99110 const { branch, limit } = payload ;
100111 const { history } = await this . #client. get < { history : HistoryDataPoint [ ] } > (
101- limit ? `/projects/history/${ encodeURIComponent ( branch ) } ?limit=${ limit } ` : `/projects/history/${ encodeURIComponent ( branch ) } ` ,
112+ limit
113+ ? `/projects/history/${ encodeURIComponent ( branch ) } ?limit=${ limit } `
114+ : `/projects/history/${ encodeURIComponent ( branch ) } ` ,
102115 ) ;
103116
104117 return history ;
0 commit comments