javascript get access_token almost got it need support

Viewed 40

i want to get the access_token value but instead it gets id_token which i do not want. here is the code i have and i kindly will appreciate it if you can share a fix to what i want.

alert(localStorage.getItem('oidc.user:https://accounts.zerotier.com/auth/realms/zerotier:zt-central'));

kindly look at this attachment below picture so you know what am trying to get.

enter image description here

Update code

alert(Object.keys(JSON.parse(localStorage.getItem('oidc.user:https://accounts.zerotier.com/auth/realms/zerotier:zt-central')))[2]);

brings Access_Token Name only no value? enter image description here

1 Answers

You should use

ak=JSON.parse(localStorage.getItem('oidc.user:https://accounts.zerotier.com/auth/realms/zerotier:zt-central'));

alert(JSON.stringify(ak['access_token']));

this turns the JSON into a Js array so you can get the parameter you want

Related