C # Gets the token value in the header

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.