JWT hauv Nodejs yog dab tsi?
JWT hauv Nodejs yog dab tsi?

Video: JWT hauv Nodejs yog dab tsi?

Video: JWT hauv Nodejs yog dab tsi?
Video: neej neeg niam ua dab 2024, Plaub Hlis Ntuj
Anonim

Kev lees paub thiab kev tso cai siv JWT nrog Node. JSON Web Token ( JWT ). Cov ntaub ntawv no tuaj yeem txheeb xyuas thiab ntseeg tau vim nws tau kos npe digitally.

Raws li txoj cai, JWT ua haujlwm hauv node JS li cas?

Cov lus thov hauv a JWT tau encoded raws li JSON cov khoom uas siv los ua tus them nyiaj ntawm JSON Web Kos Npe (JWS) qauv lossis raws li cov ntsiab lus ntawm JSON Web Encryption (JWE) qauv, ua rau cov neeg thov kom kos npe digitally lossis kev ncaj ncees tiv thaiv nrog Message Authentication Code (MAC) thiab/los yog encrypted.

Tom qab ntawd, lo lus nug yog, JWT yuav tsum muaj dab tsi? Unserialized JWTs muaj ob lub ntsiab JSON cov khoom hauv lawv: header thiab payload. Cov khoom header muaj cov ntaub ntawv hais txog lub JWT nws tus kheej: hom token, kos npe lossis encryption algorithm siv, tus yuam sij id, thiab lwm yam. muaj tag nrho cov ntaub ntawv ntsig txog nqa los ntawm lub token.

Tom qab ntawd, JWT secret key yog dab tsi?

Lub algorithm (HS256) siv los kos npe rau JWT txhais tau tias cov zais cia yog symmetrical tus yuam sij uas paub los ntawm ob tus xa thiab tus txais. Nws yog sib tham thiab faib tawm ntawm pawg. Li no, yog tias koj yog tus neeg tau txais lub token, tus neeg xa khoom yuav tsum tau muab rau koj zais cia tawm ntawm band.

JWT lees paub ua dab tsi?

Ua yog li tso cai rau koj lees paub tias lub token tau muab los ntawm koj tus neeg rau zaub mov thiab tsis raug hloov kho. Thaum lub cim kos npe, nws yog "tsis muaj neeg nyob": qhov no txhais tau tias koj tsis xav tau cov ntaub ntawv ntxiv, tsis yog tus yuam sij zais cia, txheeb xyuas tias cov ntaub ntawv hauv lub token yog "muaj tseeb".

Pom zoo: