Cov txheej txheem:

Yuav ua li cas JWT tokens tas sijhawm?
Yuav ua li cas JWT tokens tas sijhawm?

Video: Yuav ua li cas JWT tokens tas sijhawm?

Video: Yuav ua li cas JWT tokens tas sijhawm?
Video: Role Based Login Authentication Angular 15 | Angular Tutorials | Angular 15 2024, Kaum ib hlis
Anonim

A JWT token uas tsis tau tas sij hawm yog txaus ntshai yog hais tias tus token raug nyiag ces leej twg ua tau ib txwm nkag mus rau tus neeg siv cov ntaub ntawv. Muab los ntawm JWT RFC: Yog li cov lus teb yog pom tseeb, teeb tsa tas sij hawm hnub nyob rau hauv daim ntawv thov exp thiab tsis lees paub qhov token nyob rau sab server yog hnub tim hauv exp thov ua ntej hnub tam sim no.

Raws li txoj cai, JWT token yuav kav ntev npaum li cas?

15 feeb

Ib sab saum toj no, koj khaws JWT tokens li cas? A JWT yuav tsum tau muab khaws cia rau hauv qhov chaw nyab xeeb hauv tus neeg siv lub browser. Yog koj khw nws hauv localStorage, nws nkag tau los ntawm ib tsab ntawv hauv koj nplooj ntawv (uas yog phem li nws suab, raws li XSS nres tuaj yeem cia tus neeg tawm tsam sab nraud nkag mus rau hauv token ). Tsis txhob khw nws hauv zos khaws cia (los yog kev sib tham khaws cia ).

Ib sab saum toj no, kuv yuav ua li cas yuam JWT token kom tas sijhawm?

Teem caij nyoog ntawm JWTs nrog Refresh Token

  1. Txheeb xyuas qhov muaj tus token nyob rau hauv qhov kev thov headers.
  2. Xyuas tias token yog JWT siv tau, kos npe kom raug thiab tsis tas sijhawm.
  3. Xyuas cov neeg siv muaj los ntawm cov cuab yeej uid ntawm lub payload.
  4. Txheeb xyuas qhov kev tso tawm tshiab token tseem muaj nyob ntawm cov khoom tshem tawm.

Dab tsi yog qhov txawv ntawm kev nkag token thiab refresh?

Cov qhov sib txawv ntawm a refresh token thiab ib nkag mus token yog cov neeg tuaj saib: lub refresh token tsuas yog rov qab mus rau qhov kev tso cai server, lub nkag mus token mus rau (RS) cov neeg rau zaub mov. refreshing tus nkag mus token yuav muab rau koj nkag mus rau tus API ntawm tus neeg siv, nws yuav tsis qhia koj yog tias tus neeg siv nyob ntawd.

Pom zoo: