[英]How to get token_id and access_token values from Angular Session object
I am very new to angular js and i am trying to fetch the session_token from browser login and pass it to the backend,i have below code:我对 angular js 非常陌生,我正在尝试从浏览器登录中获取 session_token 并将其传递给后端,我有以下代码:
console.log(this.sso.getLoginid(localStorage.getItem("at")))
let loginid=this.sso.getNtid(localStorage.getItem("at"));
this.loginid=loginid.loginid
let username=loginid.name
this.username=username
var sessionControl = localStorage.getItem("at")
console.log(sessionControl)
and sessionControl value is below when i found using debugging in console:当我在控制台中使用调试时发现 sessionControl 值低于:
{"token_type":"bearer","access_token":"eyJhbGciOiJSUzI1NiIsImprdSI6Imh0dHBzOi8vYXBwc3NvLnVhYS5zYXVzdmRjMDIucGNmLmRlbGwuY29tL3Rva2VuX2tleXMiLCJr","id_token":"eyJhbGciOiJSUzI1NiIsImprdSI6Imh0dHBzOi8vYXBwc3NvLnVhYS5zYXVzdmRjMDIucGNm"}
Please help me in storing access_token and id_token in a variable using sessionControl object.请帮助我使用 sessionControl object 将 access_token 和 id_token 存储在变量中。
You can use JSON.parse to convert sessionControl in a object and than get sessionControl.acces_token content.您可以使用 JSON.parse 转换 object 中的 sessionControl 并获取 sessionControl.acces_token 内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.