The token and androidtoken in the interaction between the Android client and the server

Source: Internet
Author: User

The token and androidtoken in the interaction between the Android client and the server
What is TokenToken?

Token is a string generated by the server. It is used as a Token for requests from the client. After the first login, the server generates a Token and returns the Token to the client, in the future, the client only needs to bring this Token to request data, and the user name and password are not required again.

Token introduction --

Token requests data frequently from the client to the server. The server frequently queries the user name and password from the database and compares them to determine whether the user name and password are correct or not. Then, a prompt is prompted, in this context, Token came into being.

Purpose of using Token --

The purpose of Token is to reduce the pressure on the server, reduce frequent database queries, and make the server more robust.

How to Use Token?

Two usage methods:

Use of sessions and tokens in git-osc:

Not long ago, I first came into contact with the Token when I learned to log on, but I was not quite clear about the situation at that time. Now I understand:

When a user logs on, the server returns a Session with a Token in the Session. After the Token is obtained, we need to save the token.
The user does not need to carry the user name and password when sending the request next time. This reduces the burden on the server by carrying the Token and parameters required for the request.

So far, I have understood several questions:

/*** User logon, save the private token ** @ param appContext * @ param username * @ param password * @ return GitlabUser User information * @ throws IOException */public static User login (AppContext appContext, String userEmail, string password) throws AppException {String urlString = URLs. LOGIN_HTTPS; Session session = getHttpRequestor (). init (appContext, HTTPRequestor. POST_METHOD, urlString ). with ("email", userEmail ). with ("pas Sword ", password). to (Session. class); // save your private token if (session! = Null & session. get_privateToken ()! = Null) {String token = polictoutils. encode (GITOSC_PRIVATE_TOKEN, session. get_privateToken (); appContext. setProperty (PRIVATE_TOKEN, token);} return session ;}
References

How to use tokens and sessions on the Android client and server

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.