Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

javascript - 如何在不使用库的情况下在javascript中解码jwt令牌?(How to decode jwt token in javascript without using a library?)

How can I decode the payload of JWT using JavaScript?(如何使用JavaScript解码JWT的有效负载?)

Without a library.(没有图书馆。) So the token just returns a payload object that can consumed by my front-end app.(因此,令牌仅返回可由我的前端应用程序使用的有效负载对象。) Example token: xxxxxxxxx.XXXXXXXX.xxxxxxxx(令牌示例: xxxxxxxxx.XXXXXXXX.xxxxxxxx) And the result is the payload:(结果是有效负载:) {exp: 10012016 name: john doe, scope:['admin']}   ask by Chrisk8er translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Working unicode text JWT parser function:(起作用的Unicode文本JWT解析器功能:)

function parseJwt (token) { var base64Url = token.split('.')[1]; var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); var jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); return JSON.parse(jsonPayload); };

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...