Skip to content

Commit

Permalink
Merge pull request #47 from NonozgYtb/master
Browse files Browse the repository at this point in the history
fix: add refreshToken function and fix JWT parser
  • Loading branch information
maelgangloff authored Aug 26, 2024
2 parents e7886a7 + 86d0cb6 commit 483d005
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class Skolengo {
this.config = {
httpClient: config?.httpClient ?? axios.create({ baseURL: BASE_URL }),
onTokenRefresh: config?.onTokenRefresh ?? (() => {}),
refreshToken: config?.refreshToken,
handlePronoteError: config?.handlePronoteError ?? false
}
}
Expand Down Expand Up @@ -1056,7 +1057,9 @@ export class Skolengo {
*/
public getTokenClaims (): IdTokenClaims {
if (this.tokenSet.id_token === undefined) throw new TypeError('id_token not present in TokenSet')
return JSON.parse(atob((this.tokenSet.id_token).split('.')[1]))
const dataPart = this.tokenSet.id_token.split('.')?.at(1)?.replace(/-/g, '+').replace(/_/g, '/')
if (dataPart === undefined || dataPart.trim().length === 0) throw new TypeError('Invalid id_token')
return JSON.parse(atob(dataPart))
}

/**
Expand Down

0 comments on commit 483d005

Please sign in to comment.