1 PublicCurrentUser CurrentUser2 {3 Get4 {5CurrentUser result =NewCurrentUser ();6 //JWT Decryption Token7Ijsonserializer serializer =NewJsonnetserializer ();8Idatetimeprovider Provider =NewUtcdatetimeprovider ();9Ijwtvalidator Validator =NewJwtvalidator (serializer, provider);TenIbase64urlencoder Urlencoder =NewJwtbase64urlencoder (); OneIjwtdecoder decoder =NewJwtdecoder (Serializer, validator, urlencoder); A stringAuthheader = This. request.headers["Authorization"];//tokens in the header - //Add JWT Protection - if(Authheader! =NULL&& Authheader.startswith ("Bearer")) the { - stringtoken = authheader.substring ("Bearer". Length). Trim (); - varRequestService =httpcontext.requestservices; - varconf = Requestservice.getservice (typeof(iconfiguration)) asiconfiguration; + varSecretkey = conf["aaa:bbb"];//Key Information - stringResultStr = decoder. Decode (token, Secretkey, verify:true);//token for the previously generated string + Aresult = Jsonconvert.deserializeobject<currentuser> (RESULTSTR);//deserialization extracts the information from the JWT at } - Else - { - //Handle What happens if that isn ' t the case - Throw NewException ("The authorization header is either empty or isn ' t Basic."); - } in returnresult; - } to}
C # Gets the token value in the header