Identity Authentication in nancy and nancy Authentication

Source: Internet
Author: User

Identity Authentication in nancy and nancy Authentication

In nancy, identity authentication can be divided into basic, form, token, and stateless. basic and form are not mentioned here. If the identity is saved using cookies, note the following: cookies are limited in size, so they cannot be used to store information larger than 4 K, and some js plug-ins also use cookies, although html5 seems to be more. But pay attention to it. Some people may log on to the website in the previous article because the user information is too large.

Here we are talking about token verification.

ITokenizer

This is an interface that defines token. Tokenizer is an implementation of token. You can implement it by yourself, such as expiration and encryption.

ITokenKeyStore

This is the database for storing Login User identity information on the server. Private ITokenKeyStore keyStore = new FileSystemTokenKeyStore (); this line of code stores user information using files. InMemoryTokenKeyStore stores user information in the memory. You can save your login information in your own way, as long as you implement ITokenKeyStore.

Expiration time

Private Func tokenExpiration = () => TimeSpan. FromDays (1); private Func keyExpiration = () => TimeSpan. FromDays (7); this is the default expiration time

Identity Information

After logging on to the console, A json-formatted message containing the token key value is usually returned.

Token Transfer

After obtaining the token, if you save it to the cookie and then send it out, it is similar to stateless. How to transfer it? Nancy is used to add information headers, that is, adding the field named Authorization to the Header. This is the code in the test instance. header ("Authorization", "Token" + token); you can use jquery's ajax call or add it. Please search by yourself. When you see the code above, note that you need to add the string "token" before passing the token value. I just passed the token value directly.

Var authorization = request. Headers. Authorization in the TokenAuthentication. cs file is used by the server to read authorization information.

Var apiKey = (string) nancyContext. Request. Query. ApiKey. Value; while stateless is transmitted using Request. Query, apikey is generated based on guid, which does not seem to be complicated

The above are the methods and methods in the Code on the official website.

Related Article

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.