A login method and device
By intercepting request and response messages on the client side, determining the user's login status based on the status code, and obtaining the login address, the login problem in a client-server separated environment is solved, achieving secure and efficient login processing.
Patent Information
- Application Number
- CN201910452009.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-05-28
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2039-05-28
AI Technical Summary
In existing technologies, login processing methods in client-server separated environments have problems such as the inability to redirect to the login page, low security when processing login from the client, easy cookie forgery, and poor configuration flexibility.
The client intercepts request and response messages, determines the user's login status based on predefined login rules and status codes, obtains the login address information from the response message to log in, and encapsulates the request message into a common request class to uniformly handle the server interface.
It enables flexible login methods, avoids cookie forgery, improves client security and configuration flexibility, and reduces repetitive code work.
Smart Images

Figure CN112015383B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and in particular to a login method and device. Background Art
[0002] At present, most applications are developed in a way that the client and the server are separated. The client uses technologies such as Vue and React, and the server provides an interface. In the application, user login is the most basic function. The existing technology generally only processes login from the server (also called the backend) or the client. The implementation principle of login processing from the server is: the server configures an interceptor to intercept all page requests and determine whether there is a login mark in the page request. If not, it automatically jumps to the login page; if so, continue to complete the page request. The implementation principle of login processing from the client is: the client determines whether there is a cookie in the page opened for the first time. If it exists, it will not be processed; if it does not exist, it will jump to the login page.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] (1) The method of processing login from the server is only applicable to server-side rendering or when the client and server are not separated. In an environment where the client and server are separated, this method will fail to jump to the login page due to the obstruction of the client service or the client ajax.
[0005] (2) The client-side login processing method requires determining whether a cookie exists on the page before making the next request. This can easily lead to cookie forgery and expose cookie parsing rules, resulting in low security. In addition, this method has poor login configuration flexibility and requires frequent modification of login configuration in test and offline environments. If the modification is incorrect, the online launch will fail. Summary of the invention
[0006] In view of this, the embodiment of the present invention provides a login method and device. After the client intercepts the request message and the corresponding response message, based on the set login judgment rule and the response message, when it is determined that the user is not logged in, the login address information is obtained from the response message, and then the login is completed. The embodiment of the present invention realizes a flexible login method. The client only needs to intercept the login and does not need to care about which address to use for login.
[0007] To achieve the above objective, according to one aspect of an embodiment of the present invention, a login method is provided.
[0008] A login method according to an embodiment of the present invention includes: intercepting a request message and a response message corresponding to the request message; judging whether a user is logged in according to a predefined login judgment rule and a status code in the response message; wherein the login judgment rule is provided with a status code and a meaning represented by the status code; and when the user is not logged in, obtaining login address information from the response message to log in based on the login address information.
[0009] Optionally, the method also includes: encapsulating the request message into a common request class; respectively defining methods corresponding to the server interface, and encapsulating the address information of the server interface into the method according to the request type of the server interface; passing the encapsulation result to the common request class, and outputting the method name of the method.
[0010] Optionally, encapsulating the request message into a common request class includes: creating an instance object and outputting the instance object; using a request interceptor to intercept the request message and adding common header information to the request message; using a response interceptor to intercept a response message corresponding to the request message and processing the response message.
[0011] Optionally, the logging in based on the login address information includes: concatenating the login address information with current address information corresponding to the request information, and jumping to login according to the concatenated address information.
[0012] Optionally, obtaining the login address information from the response message includes: obtaining the login address information from header information of the response message; wherein the header information includes the login address information provided by the server.
[0013] To achieve the above objective, according to another aspect of an embodiment of the present invention, a login device is provided.
[0014] A login device according to an embodiment of the present invention includes: an interception module, which is used to intercept a request message and a response message corresponding to the request message; a judgment module, which is used to judge whether a user is logged in based on a predefined login judgment rule and a status code in the response message; wherein the login judgment rule is provided with a status code and a meaning represented by the status code; and a login module, which is used to obtain login address information from the response message when the user is not logged in, so as to log in based on the login address information.
[0015] Optionally, the device also includes: an encapsulation module, used to encapsulate the request message into a common request class; respectively define methods corresponding to the server interface, and encapsulate the address information of the server interface into the method according to the request type of the server interface; and pass the encapsulation result to the common request class and output the method name of the method.
[0016] Optionally, the encapsulation module is also used to: create an instance object and output the instance object; use a request interceptor to intercept the request message and add common header information to the request message; use a response interceptor to intercept a response message corresponding to the request message and process the response message.
[0017] Optionally, the login module is further used to: concatenate the login address information with current address information corresponding to the request information, and jump to login according to the concatenated address information.
[0018] Optionally, the judgment module is further used to: obtain login address information from the header information of the response message; wherein the header information includes the login address information provided by the server.
[0019] To achieve the above objective, according to another aspect of an embodiment of the present invention, an electronic device is provided.
[0020] An electronic device according to an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement a login method according to an embodiment of the present invention.
[0021] To achieve the above objective, according to another aspect of the embodiments of the present invention, a computer readable medium is provided.
[0022] A computer-readable medium according to an embodiment of the present invention stores a computer program, and when the program is executed by a processor, a login method according to an embodiment of the present invention is implemented.
[0023] An embodiment of the above invention has the following advantages or beneficial effects: after the client intercepts the request message and the corresponding response message, when it determines that the user is not logged in based on the set login judgment rule and the response message, it obtains the login address information from the response message and completes the login, realizing a flexible login method. The client only needs to intercept the login and does not need to worry about which address to use to log in; through unified login judgment rules, login judgment is made in combination with the status code, and there is no need to judge whether the cookie exists, which prevents problems such as cookie forgery and further improves the flexibility of the client; through secondary encapsulation, the request message is uniformly encapsulated into a public request class, and the server interface is uniformly encapsulated into a client API, realizing unified processing of request messages and response messages, reducing the workload of repeated code, and easily realizing login interception.
[0024] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0026] Figure 1 is a schematic diagram of the main steps of the login method according to an embodiment of the present invention;
[0027] Figure 2 is a schematic diagram of the main principles of a login method according to an embodiment of the present invention;
[0028] Figure 3 is a schematic diagram of the main flow of the login method according to an embodiment of the present invention;
[0029] Figure 4 is a schematic diagram of main modules of a login device according to an embodiment of the present invention;
[0030] Figure 5 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0031] Figure 6 It is a schematic diagram of the structure of a computer device suitable for implementing the electronic device of the embodiment of the present invention. DETAILED DESCRIPTION
[0032] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0033] The following is an explanation of the terms involved in the embodiments of the present invention.
[0034] Front-end: A web page or interface that interacts directly with users, which is a type of client.
[0035] Client: The party that can initiate requests to the server, such as an APP (Application).
[0036] Backend or server: The party that can respond to client requests, such as a cloud server.
[0037] Vue: is a progressive framework for building user interfaces. Unlike other large frameworks, Vue is designed to be applied layer by layer from the bottom up.
[0038] React: It is a JavaScript library launched by Facebook for building user interfaces.
[0039] JavaScript: It is a directly interpreted scripting language, abbreviated as JS. It is a dynamically typed, weakly typed, prototype-based language with built-in support types.
[0040] Cookie: refers to data stored on the user's local terminal by certain websites in order to identify the user and track the session.
[0041] Ajax: Asynchronous Javascript And XML, refers to a web development technology for creating interactive web applications.
[0042] XML: Extensible Markup Language, is a markup language used to mark electronic files to make them structured.
[0043] axios: is a promise-based http client that can be used in browsers and node.js (a Javascript runtime environment) to complete ajax asynchronous requests.
[0044] url: Uniform Resource Locator, which is the address of standard resources on the Internet.
[0045] Figure 1 FIG. 1 is a schematic diagram of the main steps of the login method according to an embodiment of the present invention. Figure 1 As shown, the login method of the embodiment of the present invention mainly includes the following steps:
[0046] Step S101: intercepting a request message and a response message corresponding to the request message. Encapsulate the request message into a common request class in advance, specifically: create an instance object in the common request class; use a request interceptor to intercept at least one request message sent by the client, and process the request messages in a unified manner; use a response interceptor to intercept a response message corresponding to the request message returned by the server, and process the response messages in a unified manner. Subsequently, the client can intercept the request message by calling the request interceptor, and intercept the response message by calling the response interceptor.
[0047] Step S102: Determine whether the user is logged in according to the predefined login judgment rule and the status code in the response message. The client and the server have unified login judgment rules, which are set with status codes and the corresponding meanings of each status code. For example, the status code 401 is defined to represent that the user is not logged in. If the user is not logged in, the server adds the login address information to the header information of the response message; after intercepting the response message, the client can determine whether the user is logged in according to the login judgment rule and the status code in the response message.
[0048] Step S103: When the user is not logged in, the login address information is obtained from the response message to log in based on the login address information. The interface requested by the server is encapsulated in advance, specifically: methods corresponding to the server interface are defined respectively, and the address information of the server interface is encapsulated into the method according to the request type of the server interface; the encapsulation result is passed to the public request class, and the method name of the method is output. If the client subsequently determines that the user is not logged in and has obtained the login address information, the client can call the corresponding method through the method name to splice the login address information with the address information of the address bar currently visited by the user, and then jump to login according to the spliced address information.
[0049] Figure 2 FIG. 1 is a schematic diagram of the main principles of the login method according to an embodiment of the present invention. Figure 2 As shown, in order to achieve the purpose of the present invention, the client (the front end in the embodiment) performs multi-layer processing, including a page view layer, a public processing layer, and an application program interface layer.
[0050] The page view layer contains all request messages. This layer is used to send page request messages and perform page rendering.
[0051] The public processing layer includes a custom request, which is requestJS in the embodiment. This layer is used to intercept request messages using a request interceptor, aggregate and uniformly process all request messages of the page, and then output them to the application interface layer; the response interceptor is used to intercept response messages from the application interface layer, aggregate and uniformly process all response messages. In the embodiment, a secondary encapsulation method is used to achieve unified processing of all messages.
[0052] The application interface layer is used to encapsulate all server interfaces and expose a method name to the page view layer. The advantage of this is that all server interfaces can be managed in a unified manner. If the URL of the server interface changes, you only need to change the file attributes corresponding to this layer, without having to change the page request message on a large scale, reducing client duplicate requests and duplicate code. The application interface layer is also used to send the request message to the server that currently has an http connection with the client through the corresponding interface after receiving the request message; after receiving the response message from the server for the request message, the interface sends it to the response interceptor.
[0053] Figure 3 FIG. 1 is a schematic diagram of the main flow of the login method according to an embodiment of the present invention. Figure 3 As shown, the login method of the embodiment of the present invention mainly includes the following steps:
[0054] Step S301: The public processing layer encapsulates all request messages for server data from the target page into a public request class. In the embodiment, taking a single page of a Vue project as an example, all information interactions between the client and the server are axios request messages. The specific implementation of encapsulating the axios request message into a public request class (requestJS) is as follows: (1) creating an axios instance object, the instance object name is axiosService, and then exporting the instance object; (2) using the interceptors.request.use method (i.e., request interceptor) to intercept all axios request messages, and process the intercepted axios request messages; the processing here can be to add public header information, such as token, timestamp, etc.; (3) using the interceptors.response.use method (i.e., response interceptor) to intercept the response message corresponding to the axios request message returned by the server, and uniformly process the response message.
[0055] In the embodiment, the unified processing of the response message mainly includes:
[0056] (1) The value corresponding to the applicationprofile attribute data in the header information (headers) of the response message is stored in the client cache.
[0057] (2) Special processing is performed on the data whose content-type value is application / properties in the headers of the response message, that is, it is directly returned to the page calling program, and a promise object is returned here.
[0058] (3) For other data: determine whether the status code is equal to 200. If it is equal to 200, return the data value in the data to the page calling program; if it is not equal to 200, return the message in the data to the page calling program. Here, a promise object is returned.
[0059] (4) Processing of error data: If the code is equal to 401, try to obtain the jump path in the location field in the header (the path is the login address information, which can be the URL of the login page or login window) for jump; if the code is equal to 404, jump to the error page.
[0060] Step S302: The application program interface layer defines methods corresponding to at least one server interface respectively, and encapsulates the address information of the server interface into the method according to the request type of the server interface. Here, only a standard for interface input and output is defined. In an embodiment, the standard for interface input can only care about the method name of the call, and does not need to care about what the requested url is specifically. If the url of the server interface is changed, it is only necessary to change the url inside the method, and it is not necessary to change the axios request message of each page, which greatly reduces the code duplication. The standard for interface input can be to uniformly output a promise object.
[0061] The following example illustrates how to define the method corresponding to the server interface:
[0062] For example, the server interface is: v1 / application / appId
[0063] The client encapsulated interface is:
[0064] export function getApp(appId){
[0065] return request({
[0066] url:baseUrl+'v1 / application / '+appId,
[0067] method:'get'
[0068] })
[0069] }
[0070] For example, the server interface is: v1 / applications / search
[0071] The client encapsulated interface is:
[0072] export function searchApps(params){
[0073] let url=baseUrl+'v1 / applications / search? '
[0074] for(let key in params){
[0075] url+=key+"="+params[key]+"&"
[0076] }
[0077] url=url.substring(0,url.length-1);
[0078] return request({
[0079] url:url,
[0080] method:'get'
[0081] })
[0082] }
[0083] The following example illustrates how to encapsulate the address information of the server interface into a method according to the request type of the server interface:
[0084] For example, for a get type request, the corresponding URL is concatenated, and the incoming parameters are concatenated after the URL. Assuming that the incoming parameters are an object {a:1, b:2}, the incoming parameters will be combined with the server URL during encapsulation and processed into the following format: http: / / xxx.jd.com / v1 / xx / get?a=1&b=2.
[0085] For another example, for post, delete, and put type requests, the parameters passed in are placed in the data, so you only need to concatenate the corresponding URLs without doing any special processing on the passed in parameters. For example, delete: http: / / xxx.jd.com / v1 / xx / delete / :id, id is the passed in parameter.
[0086] Step S303: The application program interface layer passes the encapsulation result to the public request class and outputs the method name of the method. The application program interface layer only exposes one method name for the Vue page, such as getApp, searchApps. When the Vue page is called, it only needs to pass in the parameters as required to output the promise object. In the embodiment, the application program interface layer passes the processed url, parameters, and other header information that needs to be processed to requestJS, and outputs (exports) these method names to provide these method names to the page view layer so that the page view layer can directly call these methods.
[0087] Step S304: The page view layer calls the method name of the application interface layer to intercept all request messages from the target page through the public processing layer, as well as the response message corresponding to the request message returned by the server. After receiving the request message sent by the client, the server will return the corresponding response message. The public processing layer intercepts all request messages from the target page through the request interceptor, and intercepts the response message corresponding to the request message returned by the server through the response interceptor. In the embodiment, after intercepting the request message, the public processing layer obtains the response message matching the request message based on the pre-established http connection.
[0088] Step S305: The public processing layer determines whether the user has logged in to the target page according to the predefined login judgment rules and the status code in the response message. If the user has logged in to the target page, step S306 is executed; if the user has not logged in to the target page, step S307 is executed. Since the page is rendered by Vue instead of server-side rendering, when judging whether the user has logged in to the target page, the cookie method is used in the prior art, but this method is prone to malicious cookie forgery attacks. In this embodiment, the client and the server cooperate to determine whether the user has logged in to the target page, that is, through a unified login judgment rule. The rule specifies the corresponding status code when the user has not logged in to the target page. If the user has not logged in to the target page, the server will return the specific status code and the URL of the corresponding login page or login window, and the client does not need to worry about which page the user goes to log in. For example, the client and the server predetermine that when the status code is 401, it means that the user is not logged in. At this time, the header information of the response message must contain a location field, which is used to store the URL of the login page or login window (defined and stored by the server so that different environments and systems can be changed at any time); when the status code is other values, it represents other meanings accordingly.
[0089] Step S306: the page view layer renders the target page to display the page content.
[0090] Step S307: The public processing layer obtains the login address information from the response message, and splices the login address information with the address information of the target page to jump to the login page or login window according to the spliced address information. If the status code is 401, it means that the user has not logged in to the target page, and the client needs to jump to the login page or login window. Since the server has three systems: testing, development, and online, the URLs of the login pages or login windows of each system are different, so the client needs to obtain it from the header provided by the server, which can greatly improve the flexibility of the client. In an embodiment, the public processing layer obtains the URL of the login page or login window from the location field contained in the header of the response message. The address information of the target page is the URL of the address bar of the page currently visited by the user. In the embodiment, the process of splicing the two address information can be: const returnUrl = errorresponse.headers.location + "? ReturnUrl = " + nowUrl; wherein the information in the location field is the URL of the login page, such as: http: / / xxx.jd.com; nowUrl is the URL of the address bar of the page currently visited by the user obtained through JS, such as: http: / / abc.jd.com; then the URL obtained after the splicing is: http: / / xxx.jd.com? ReturnUrl = http: / / abc.jd.com. Afterwards, according to the spliced address, the location.href method of the client can be used to complete the jump from the target page currently visited by the user to the login page or login window.
[0091] It can be seen from the login method of the embodiment of the present invention that after the client intercepts the request message and the corresponding response message, when it determines that the user is not logged in based on the set login judgment rule and the response message, it obtains the login address information from the response message to complete the login, thereby realizing a flexible login method. The client only needs to intercept the login and does not need to worry about which address to use to log in; through a unified login judgment rule, the login judgment is made in combination with the status code, and there is no need to judge whether the cookie exists, thereby preventing problems such as cookie forgery, and further improving the flexibility of the client; through the secondary encapsulation method, the request message is uniformly encapsulated into a public request class, and the server interface is uniformly encapsulated into a client API, thereby realizing unified processing of request messages and response messages, reducing the workload of repeated code, and easily realizing login interception.
[0092] Figure 4 Schematic diagram of the main modules of the login device according to an embodiment of the present invention. Figure 4 As shown, the login device 400 of the embodiment of the present invention mainly includes:
[0093] The interception module 401 is used to intercept the request message and the response message corresponding to the request message. The request message is pre-encapsulated as a common request class, specifically: an instance object is created in the common request class; a request interceptor is used to intercept at least one request message sent by the client, and the request message is processed uniformly; a response interceptor is used to intercept the response message corresponding to the request message returned by the server, and the response message is processed uniformly. Subsequently, the client can intercept the request message by calling the request interceptor, and intercept the response message by calling the response interceptor.
[0094] The judgment module 402 is used to judge whether the user is logged in according to the predefined login judgment rules and the status code in the response message. The client and the server have unified login judgment rules, which are set with status codes and the corresponding meanings of each status code. For example, the status code 401 is defined to represent that the user is not logged in. If the user is not logged in, the server adds the login address information to the header information of the response message; after intercepting the response message, the client can judge whether the user is logged in according to the login judgment rules and the status code in the response message.
[0095] The login module 403 is used to obtain the login address information from the response message when the user is not logged in, so as to log in based on the login address information. The interface requested by the server is encapsulated in advance, specifically: methods corresponding to the server interface are defined respectively, and the address information of the server interface is encapsulated into the method according to the request type of the server interface; the encapsulation result is passed to the public request class, and the method name of the method is output. If the client determines that the user is not logged in later and has obtained the login address information, the client can call the corresponding method through the method name to splice the login address information with the address information of the address bar currently visited by the user, and then jump to login according to the spliced address information.
[0096] In addition, the login device 400 of the embodiment of the present invention may further include: a packaging module ( Figure 4 (not shown in the figure), the module is used to encapsulate the request message into a common request class; respectively define methods corresponding to the server interface, and encapsulate the address information of the server interface into the method according to the request type of the server interface; and pass the encapsulation result to the common request class and output the method name of the method.
[0097] From the above description, it can be seen that after the client intercepts the request message and the corresponding response message, when it determines that the user is not logged in based on the set login judgment rules and the response message, it obtains the login address information from the response message and completes the login, realizing a flexible login method. The client only needs to intercept the login and does not need to worry about which address to use to log in; through unified login judgment rules, combined with the status code, login judgment is made, and there is no need to judge whether the cookie exists, which prevents problems such as cookie forgery and further improves the flexibility of the client; through secondary encapsulation, the request message is uniformly encapsulated into a public request class, and the server interface is uniformly encapsulated into a client API, realizing unified processing of request messages and response messages, reducing the workload of repeated code, and easily realizing login interception.
[0098] Figure 5 An exemplary system architecture 500 to which the login method or login device according to the embodiment of the present invention can be applied is shown.
[0099] like Figure 5 As shown, system architecture 500 may include terminal devices 501, 502, 503, a network 504 and a server 505. Network 504 is used to provide a medium for communication links between terminal devices 501, 502, 503 and server 505. Network 504 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0100] Users can use terminal devices 501, 502, 503 to interact with server 505 through network 504 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 501, 502, 503, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0101] The terminal devices 501 , 502 , and 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0102] The server 505 may be a server that provides various services, such as a background management server that responds to request messages sent by users using terminal devices 501, 502, and 503. The background management server may analyze and process the received request information, and feed back the processing result (such as response information) to the terminal device.
[0103] It should be noted that the login method provided in the embodiment of the present application is generally executed by the front end on the terminal devices 501 , 502 , 503 , and accordingly, the login device is generally arranged in the front end on the terminal devices 501 , 502 , 503 .
[0104] It should be understood that Figure 5 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0105] According to an embodiment of the present invention, the present invention also provides an electronic device and a computer-readable medium.
[0106] The electronic device of the present invention comprises: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement a login method of an embodiment of the present invention.
[0107] The computer-readable medium of the present invention stores a computer program, and when the program is executed by a processor, a login method of an embodiment of the present invention is implemented.
[0108] Reference below Figure 6 , which shows a schematic diagram of the structure of a computer system 600 suitable for implementing an electronic device of an embodiment of the present invention. Figure 6 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0109] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the computer system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0110] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.
[0111] In particular, according to the embodiments disclosed in the present invention, the process described in the main step diagram above can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the main step diagram. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present invention are executed.
[0112] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0113] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0114] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes an interception module, a judgment module and a login module. The names of these modules do not constitute a limitation on the modules themselves in some cases, for example, the interception module may also be described as a "module for intercepting request messages and response messages corresponding to the request messages".
[0115] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: intercepting a request message and a response message corresponding to the request message; judging whether the user is logged in according to a predefined login judgment rule and a status code in the response message; wherein the login judgment rule is provided with a status code and the meaning represented by the status code; and when the user is not logged in, obtaining the login address information from the response message to log in based on the login address information.
[0116] From the above description, it can be seen that after the client intercepts the request message and the corresponding response message, when it determines that the user is not logged in based on the set login judgment rules and the response message, it obtains the login address information from the response message and then completes the login, realizing a flexible login method. The client only needs to intercept the login and does not need to worry about which address to use to log in. Through unified login judgment rules, combined with the status code for login judgment, there is no need to judge whether the cookie exists, which prevents problems such as cookie forgery and further improves the flexibility of the client.
[0117] The above product can execute the method provided by the embodiment of the present invention, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not described in detail in this embodiment, please refer to the method provided by the embodiment of the present invention.
[0118] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A login method, characterized in that: include: Intercepting a request message and a response message corresponding to the request message; Determine whether the user is logged in according to a predefined login judgment rule and a status code in the response message; wherein the login judgment rule is provided with a status code and a meaning represented by the status code; When the user is not logged in, acquiring login address information from the response message to log in based on the login address information; further comprising: Encapsulating the request message into a common request class; respectively defining methods corresponding to the server interfaces, and encapsulating the address information of the server interfaces into the methods according to the request type of the server interfaces; The encapsulation result is passed to the public request class, and the method name of the method is output.
2. The method according to claim 1, characterized in that The step of encapsulating the request message into a common request class comprises: Create an instance object, and output the instance object; Using a request interceptor to intercept the request message, and adding common header information to the request message; A response interceptor is used to intercept a response message corresponding to the request message, and the response message is processed.
3. The method according to claim 1, characterized in that The logging in based on the login address information includes: The login address information and the current address information corresponding to the request message are spliced together, and the login is jumped according to the spliced address information.
4. The method according to claim 1, characterized in that: The acquiring the login address information from the response message includes: acquiring the login address information from the header information of the response message; wherein the header information includes the login address information provided by the server.
5. A login device, characterized in that: include: An interception module, used to intercept a request message and a response message corresponding to the request message; A judgment module, used to judge whether the user is logged in according to a predefined login judgment rule and a status code in the response message; wherein the login judgment rule is provided with a status code and a meaning represented by the status code; A login module, used for obtaining login address information from the response message when the user is not logged in, so as to log in based on the login address information; An encapsulation module is used to encapsulate the request message into a common request class; define methods corresponding to the server interface respectively, and encapsulate the address information of the server interface into the method according to the request type of the server interface; and pass the encapsulation result to the common request class and output the method name of the method.
6. The device according to claim 5, characterized in that The encapsulation module is further used for: Create an instance object, and output the instance object; Using a request interceptor to intercept the request message, and adding common header information to the request message; A response interceptor is used to intercept a response message corresponding to the request message, and the response message is processed.
7. The device according to claim 5, characterized in that The login module is further used to: splice the login address information and the current address information corresponding to the request message, and jump to login according to the spliced address information.
8. The device according to claim 5, characterized in that The determination module is further used to: obtain the login address information from the header information of the response message; wherein the header information includes the login address information provided by the server.
9. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 4.
10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.