Skip to content

The getFromToken method has compatibility problem. #23796

@maliming

Description

@maliming

We found that in the getFromToken function, the access token payload is decoded using atob. When the payload length is not a multiple of 4 (due to missing Base64 padding =), atob throws this error. This happens especially when the preferred_username claim contains an email (e.g., [email protected]).

https://github.com/abpframework/abp/blob/dev/npm/ng-packs/packages/oauth/src/lib/services/remember-me.service.ts#L40-L49

Current Code:(in remember-me.service.ts)

const tokenBody = accessToken.split('.')[1].replace(/-/g, '+').replace(/_/g, '/');
const parsedToken = JSON.parse(atob(tokenBody));

Suggested Fix:
Add missing padding before calling atob:

while (tokenBody.length % 4 !== 0) {
  tokenBody += '=';
}

Alternatively, using the jwt-decode library in Angular would be a more reliable approach.

https://abp.io/support/questions/9936/Angular-UI---atob-error-while-decoding-access-token-The-string-to-be-decoded-is-not-correctly-encoded

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions