Cross-domain Cookie carrying method and device, related equipment and computer program product
By intercepting client requests, obtaining domain name mapping relationships and writing cookie information under different domain names, the problem of cross-domain cookie sharing is solved, simple and convenient cross-domain access is achieved, and development efficiency and maintenance are improved.
Patent Information
- Application Number
- CN202411248543.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-05
- Publication Date
- 2024-11-26
AI Technical Summary
The existing technology cannot realize the sharing of cross-domain cookies, resulting in the separation of front-end and back-end, making it difficult for the front-end to carry back-end cookies under different domain names, which are complex in configuration and difficult to maintain.
By intercepting the client's interface request, obtaining the domain name mapping relationship, determining the different domain names corresponding to the current domain name, and writing the cookie information under it into the request, re-selling the request, realizing the carrying of cross-domain cookies.
Simplifies the configuration of cross-domain cookies, reduces development and maintenance costs, improves development efficiency, and avoids the complexity of configuring Host and Nginx and the hassle of applying for https certificates.
Smart Images

Figure CN119030954A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer and Internet technology, and in particular to a method, device, electronic device, computer-readable storage medium, and computer program product for carrying cookies across domains. Background Art
[0002] This section is intended to provide a background or context to the embodiments of the disclosure that are recited in the claims. No description herein is admitted to be prior art by inclusion in this section.
[0003] Cookie is a small text file stored on your machine's hard disk by the Web (word wide web) server when you browse a website. It records your user name, password, web pages you browsed, length of stay, and other information. When you visit this website again, the Web server will first check if there is a cookie left by it last time. If there is, it will read the content in the cookie to determine the user, allowing you to log in directly without entering an ID (Identity Document) or password, etc.
[0004] However, after the cookie is generated by the server, it has domain name restrictions, that is, the cookie generated under one domain name cannot be accessed by devices under another domain name. Under the conditions of two completely different domain names, the existing method cannot achieve cookie sharing. Summary of the invention
[0005] The purpose of the present disclosure is to provide a method, device, electronic device, computer-readable storage medium and computer program product for carrying cookies across domains, which can allow cross-domain requests to carry cookies of other domains for normal access.
[0006] Other features and advantages of the present disclosure will become apparent from the following detailed description, or may be learned in part by the practice of the present disclosure.
[0007] An embodiment of the present disclosure provides a method for carrying cookies across domains, including: intercepting an interface request issued by a client, and using the domain name carried in the interface request as a first domain name; obtaining a domain name mapping relationship; determining a second domain name corresponding to the first domain name according to the domain name mapping relationship, wherein the first domain name is different from the second domain name; obtaining cookie information under the second domain name as first cookie information; writing the first cookie information under the second domain name into the interface request; and re-initiating the interface request.
[0008] In some embodiments, determining a second domain name corresponding to the first domain name according to the domain name mapping relationship includes: determining whether the first domain name is configured with a mapped domain name according to the domain name mapping relationship; if it is determined that the first domain name is configured with a mapped domain name according to the domain name mapping relationship, determining the mapped domain name corresponding to the first domain name according to the domain name mapping relationship, and using the mapped domain name corresponding to the first domain name as the second domain name.
[0009] In some embodiments, the method also includes: determining a third domain name corresponding to the first domain name based on the domain name mapping relationship, the third domain name is different from the first domain name, and the third domain name is also different from the second domain name; obtaining the cookie under the third domain name as the second cookie information; wherein, writing the first cookie information under the second domain name into the interface request includes: writing the first cookie information under the second domain name and the second cookie information under the third domain name into the interface request.
[0010] In some embodiments, the client is a browser, and the method further includes: the browser receiving the first Cookie information returned by the first server; determining that the domain name of the first server is the second domain name; and planting the first Cookie information under the second domain name.
[0011] In some embodiments, the method further includes: the browser receives second Cookie information returned by the second server; determines that the domain name of the second server is a third domain name; and plants the second Cookie information under the third domain name.
[0012] In some embodiments, before obtaining the domain name mapping relationship, the method includes: displaying a plug-in configuration page; receiving the domain name mapping relationship through the plug-in configuration page, and the domain name mapping relationship is used to associate the first domain name with the second domain name, and to associate the first domain name with a third domain name, so that the client can carry the cookie information under the second domain name and the third domain name when initiating a request under the first domain name.
[0013] The embodiment of the present disclosure provides a cross-domain Cookie carrying device, including: a request interception module, a mapping relationship acquisition module, a mapping domain name determination module, an information determination module, an information writing module and a re-initiating request module.
[0014] Among them, the request interception module is used to intercept the interface request issued by the client, and use the domain name carried in the interface request as the first domain name; the mapping relationship acquisition module can be used to obtain the domain name mapping relationship; the mapping domain name determination module can be used to determine the second domain name corresponding to the first domain name according to the domain name mapping relationship, and the first domain name is different from the second domain name; the information determination module can be used to obtain the Cookie information under the second domain name as the first Cookie information; the information writing module can be used to write the first Cookie information under the second domain name into the interface request; the re-initiate request module can be used to re-initiate the interface request.
[0015] An embodiment of the present disclosure proposes an electronic device, which includes: a memory and a processor; the memory is used to store computer program instructions; the processor calls the computer program instructions stored in the memory to implement any of the above-mentioned cross-domain cookie carrying methods.
[0016] The embodiment of the present disclosure proposes a computer-readable storage medium on which computer program instructions are stored to implement the cross-domain Cookie carrying method as described in any one of the above items.
[0017] The embodiment of the present disclosure provides a computer program product or a computer program, which includes computer program instructions, and the computer program instructions are stored in a computer-readable storage medium. The computer program instructions are read from the computer-readable storage medium, and the processor executes the computer program instructions to implement the above-mentioned cross-domain cookie carrying method.
[0018] The cross-domain cookie carrying method, device, electronic device, computer-readable storage medium and computer program product provided by the embodiments of the present disclosure only need to determine other domain names related to the domain name in the current interface request through the domain name mapping relationship, so that the current interface request can carry all cookie information under the relevant domain name, so that the cross-domain request can carry the required cookies for normal access, and has strong reuse and maintainability, thereby improving development efficiency.
[0019] It is to be understood that the foregoing general description and the following detailed description are exemplary only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. Obviously, the accompanying drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without creative work.
[0021] Figure 1 A schematic diagram of a scenario in which a method or device for carrying cookies across domains that can be applied to an embodiment of the present disclosure is shown.
[0022] Figure 2 The figure is a flowchart of a method for carrying Cookies across domains according to an exemplary embodiment.
[0023] Figure 3 The diagram is a schematic diagram of a domain name mapping relationship configuration page according to an exemplary embodiment.
[0024] Figure 4 The figure is a flowchart of a method for carrying Cookies across domains according to an exemplary embodiment.
[0025] Figure 5 The figure is a flowchart of a method for carrying Cookies across domains according to an exemplary embodiment.
[0026] Figure 6 The figure is a flow chart of a Cookie planting method according to an exemplary embodiment.
[0027] Figure 7 The present invention is a flowchart of a method for configuring a domain name mapping relationship according to an exemplary embodiment.
[0028] Figure 8 This is a structural framework diagram corresponding to a method of carrying cookies across domains.
[0029] Fig. 9 The figure is a flowchart of a method for carrying Cookies across domains according to an exemplary embodiment.
[0030] Fig.10 It is a block diagram of a device for carrying Cookies across domains according to an exemplary embodiment.
[0031] Fig.11 A schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present disclosure is shown. DETAILED DESCRIPTION
[0032] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this disclosure will be comprehensive and complete and will fully convey the concepts of the example embodiments to those skilled in the art. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted.
[0033] Those skilled in the art will appreciate that the embodiments of the present disclosure may be a system, device, apparatus, method or computer program product. Therefore, the present disclosure may be specifically implemented in the following forms, namely: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.
[0034] The features, structures or characteristics described in the present disclosure may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known methods, devices, implementations or operations are not shown or described in detail to avoid blurring the various aspects of the present disclosure.
[0035] In the embodiments of the present disclosure, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0036] The accompanying drawings are only schematic diagrams of the present disclosure, and the same reference numerals in the drawings represent the same or similar parts, so their repeated description will be omitted. Some block diagrams shown in the accompanying drawings do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0037] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and steps, nor must they be executed in the order described. For example, some steps can be decomposed, and some steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0038] In the description of the present disclosure, unless otherwise specified, " / " means "or", for example, A / B can mean A or B. "And / or" in this article is only a kind of association relationship describing the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, "at least one" means one or more, and "plurality" means two or more. The words "first", "second", etc. do not limit the quantity and execution order, and the words "first", "second", etc. do not limit them to be different; the terms "comprising", "including" and "having" are used to express the meaning of open inclusion and mean that in addition to the listed elements / components / etc., there may be other elements / components / etc.
[0039] In order to more clearly understand the above-mentioned objects, features and advantages of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods. It should be noted that the embodiments of the present invention and the features in the embodiments can be combined with each other without conflict.
[0040] It should be noted that the collection, collection, updating, analysis, processing, use, transmission, storage and other aspects of user personal information involved in the technical solution of this disclosure are in compliance with the provisions of relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken for user personal information to prevent illegal access to user personal information data and maintain the security of user personal information and network security.
[0041] First, some terms involved in the embodiments of the present disclosure are explained below to facilitate understanding by those skilled in the art.
[0042] A domain name, also known as a network domain, is composed of a string of names separated by dots.
[0043] Cross-domain: if two protocols, ports (if any), and domain names are the same, they are of the same origin. As long as one of them is different, it is cross-domain.
[0044] Joint debugging: After the division of labor, a process of docking and joint debugging is required to ensure that the front-end and back-end codes can accurately collaborate. This is called joint debugging. For example, when a user adds an item to the shopping cart on a page, the front-end needs to send a request to the back-end, and the back-end returns the new shopping cart information to the front-end for display after processing. This requires "joint debugging".
[0045] Front-end local startup: In a local development environment, front-end resources are usually provided by a local server. This server is usually a lightweight server running on a local computer. After these servers are started locally, a local IP address and port number will be provided as an access point instead of a domain name.
[0046] Cookies are planted under a domain name, which means setting or storing cookies under a specific domain name. Generally speaking, cookies are planted when you log in for the first time.
[0047] The front-end application and the back-end service are not under the same domain name, which can include the front-end application and the back-end service being deployed on different network addresses. In WEB development, the front-end application is usually deployed on the client (such as the user's browser), while the back-end service runs on the server. When it is said "not under the same domain name", it means that the front-end application and the back-end service have their own domain names. For example, the front-end application may be deployed on app.example.com, and the back-end service may be deployed on api.example.com. These two domain names point to different servers, which may be located in different physical locations and may even be managed by different teams.
[0048] A popup in a plug-in refers to a small window that is temporarily displayed on the screen in a computer interface. This concept is mainly used in the development of browser extensions (plug-ins), and popup usually refers to the main interface window of a browser plug-in. When you click the plug-in icon, the window will temporarily pop up and display the functions, setting options or other interactive elements provided by the plug-in.
[0049] The foregoing introduces some terms and concepts involved in the embodiments of the present disclosure. The following introduces the technical features involved in the embodiments of the present disclosure.
[0050] In related technologies, when a local application is started, the environment deployed on the server will be called. After the user successfully logs in, the server will store the login information in the form of a cookie in the front-end application. The front-end application can carry the relevant cookies for interface calls.
[0051] In the front-end and back-end separation development mode, the domain names of the front-end and back-end may be different. When the front-end is jointly debugged or online problems are troubleshooted, the front-end will inevitably encounter the following situations because cookies cannot be accessed across domains:
[0052] 1. The server usually instructs to plant cookies under the domain name (such as .com for commercial site services, gov for countries or administrative units, edu for educational organizations, etc.). When the front-end is started locally, there is no relevant domain name and cookies cannot be carried;
[0053] 2. The server supports https (hypertext transfer protocol secure), but the local front-end environment does not support it, resulting in the problem of being unable to carry cookies across domains.
[0054] 3. The server sets special attributes when planting cookies, which does not allow cross-site transmission, making it impossible to carry third-party cookies.
[0055] Common solutions to the above problems are as follows:
[0056] 1. Configure the local Host or configure Nginx proxy for forwarding;
[0057] 2. Apply for https security certificate on the front end and configure relevant Nginx to solve the problem;
[0058] 3. The front-end configuration is accessed with the same domain name as the one that stores the cookies.
[0059] The above technology has the following disadvantages:
[0060] 1. The configuration is complicated. Whether configuring Host or Nginx, it is time-consuming, especially Nginx configuration requires certain basic knowledge;
[0061] 2. You need to apply for an https security certificate, which is troublesome;
[0062] 3. When configuring the domain name on the front end, you need to always pay attention to whether to configure the SameSite attribute to decide how to configure the domain name;
[0063] 4. The above solutions are difficult to reuse. After too many configurations, maintenance is more troublesome and development efficiency is relatively low.
[0064] The present application provides a method for carrying cookies across domains in a simple, convenient and efficient manner through an embodiment.
[0065] The exemplary embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
[0066] Figure 1 A schematic diagram of a scenario in which a method or device for carrying cookies across domains that can be applied to an embodiment of the present disclosure is shown.
[0067] Please refer to Figure 1 , which shows a schematic diagram of an implementation environment provided by an exemplary embodiment of the present disclosure.
[0068] like Figure 1As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0069] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Terminal devices 101, 102, 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, wearable devices, virtual reality devices, smart homes, etc.
[0070] The server 105 may be a server that provides various services, such as a background management server that provides support for devices operated by users using the terminal devices 101, 102, and 103. The background management server may analyze and process the received request data, and feed back the processing results to the terminal device.
[0071] The server can be an independent physical server or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), as well as basic cloud computing services such as big data and artificial intelligence platforms, etc. The present disclosure does not impose any restrictions on this.
[0072] The server 105 may, for example, intercept an interface request issued by the client, and use the domain name carried in the interface request as the first domain name; the server 105 may, for example, determine a second domain name corresponding to the first domain name based on a domain name mapping relationship, where the first domain name is different from the second domain name; the server 105 may, for example, obtain Cookie information under the second domain name as the first Cookie information; the server 105 may, for example, write the first Cookie information under the second domain name into the interface request; the server 105 may, for example, re-initiate the interface request.
[0073] It should be understood that Figure 1 The number of terminal devices, networks and servers in the figure is only for illustration. The server 105 may be a physical server or may be composed of multiple servers. According to actual needs, it may have any number of terminal devices, networks and servers.
[0074] Under the above system architecture, a method for carrying cookies across domains is provided in an embodiment of the present disclosure, and the method can be executed by any electronic device with computing and processing capabilities.
[0075] Figure 2 The method provided by the embodiment of the present disclosure can be implemented by a plug-in, and the plug-in can be run on any electronic device with computing and processing capabilities to execute.
[0076] Reference Figure 2 The cross-domain Cookie carrying method provided by the embodiment of the present disclosure may include the following steps.
[0077] Step S202: intercepting an interface request sent by the client, and using the domain name carried in the interface request as the first domain name.
[0078] In some embodiments, the client (Client) or user end refers to a program corresponding to the server that provides local services to customers. Except for some applications that only run locally, it is generally installed on a common client and needs to cooperate with the server to run.
[0079] Clients generally include: desktop app, which refers to the client application running on the desktop operating system; desktop web, which refers to the hypertext content (web pages) running in the desktop browser; mobile app, which refers to the client application running on the mobile device operating system; mobile web, which refers to the hypertext content (mobile web pages) running on the mobile device browser.
[0080] In some embodiments, the domain name carried in the interface request may include the domain name of the domain where the client is located, or may include the domain name of the domain where the server to which the request points is located, but this application does not impose any restrictions on this.
[0081] The domain where the client is located may refer to the network domain (Domain) that the client computer joins. The domain where the server is located may refer to the network domain that the server joins.
[0082] In computer networks, a domain is a way to centrally manage network resources and user accounts, allowing network administrators to uniformly manage and control access to computers and users within the domain.
[0083] Below, this application will be described using the client as a browser or a web page in the browser as an example, but this application is not limited to this.
[0084] In some embodiments, each interface request sent by the client can be intercepted, and the interface request can include the domain name of the domain where the client is located or the domain where the server pointed to by the interface request is located, and the domain name carried in the interface request can be called the first domain name. For example, assuming that the client is in the A network domain (Domain), then the interface request sent by the client can carry the domain name of the A domain, and can also carry Cookie information stored under the domain name of the A domain; for another example, assuming that the server to be accessed by the interface request is in the B network domain, then the interface request can carry the domain name of the B domain, and can also carry Cookie information stored under the domain name of the B domain.
[0085] Step S204, obtaining the domain name mapping relationship.
[0086] In some embodiments, the above domain name mapping relationship can associate two unrelated domain names. Figure 3 As shown, domain name a and domain name b can be associated through the domain name mapping relationship, domain name abc can be associated with domain name b, and domain name d can be associated with domain name b. This application does not impose any restrictions on this. Technical personnel in this field can associate two unrelated and / or related domain names according to actual needs.
[0087] Step S206: determining a second domain name corresponding to the first domain name according to the domain name mapping relationship, where the first domain name is different from the second domain name.
[0088] In some embodiments, it may be determined whether there is a domain name associated with the first domain name based on the domain name mapping relationship. If so, the domain name related to the first domain name may be called the second domain name, wherein the first domain name and the second domain name may be different.
[0089] In some embodiments, if it is determined according to the domain name mapping relationship that there is no domain name associated with the first domain name, or it is determined that the first domain name does not exist in the domain name mapping relationship; the interface request is not modified and the interface request continues to be issued.
[0090] Step S208, obtaining Cookie information under the second domain name as the first Cookie information.
[0091] In some embodiments, the Cookie stored under the second domain name can be obtained, and the Cookie stored under the second domain name can be used as the first Cookie information.
[0092] Step S210, write the first Cookie information under the second domain name into the interface request.
[0093] In some embodiments, the first Cookie information may be written into the above interface request so that the interface request carries the first Cookie information.
[0094] In some embodiments, after writing the first Cookie information, the interface request may carry both Cookie information under the first domain name and Cookie information under the second domain name.
[0095] Step S212, re-initiate the interface request.
[0096] In some embodiments, after the first Cookie information is written into the interface request, the interface request may be re-initiated so that the interface request carries the Cookie information under the first domain name and the second domain name for access.
[0097] In some embodiments, if the first domain name is the domain name of the domain where the client is located, then the second domain name may include the domain name of the domain where the server to be accessed by the interface request is located.
[0098] For example, if the client and the server to be accessed by the interface request are not in the same domain, and the interface request carries the domain name of the domain where the client is located, then the first domain name may include the domain name of the domain where the client is located, and the second domain name may include the domain name of the domain where the server is located.
[0099] In some embodiments, if the first domain name is the domain name of the domain where the client is located or the domain name of the domain where the server to which the interface request points is located, then the second domain name may include the domain name of the third-party server to which the interface request will call.
[0100] For example, assuming that the interface request needs to continue to call the second service after accessing the first server, and the first server and the second server are in different domains, if the interface request carries the domain name of the first server, then the first domain name can include the domain name of the domain where the first server is located, and the second domain name can include the domain name of the domain where the second server is located; for another example, assuming that the interface request needs to continue to call the second service after accessing the first server, and the client and the first server are in the same domain, but the client and the second server are in different domains, if the interface request carries the domain name of the domain where the client is located (it can also be said to be the domain name of the domain where the first server is located), then the first domain name can be the domain name of the domain where the client (or the first server) is located, and the second domain name can include the domain name of the domain where the second server is located; for another example, assuming that the interface request needs to continue to call the second service after accessing the first server, and the client and the first server, the second server, etc. are all in different domains, if the interface request carries the domain name of the domain where the client is located, then the first domain name can be the domain name of the domain where the client is located, and the second domain name can include the domain name of the domain where the first server is located and the domain name of the domain where the second server is located.
[0101] Through the above method, the cross-domain cookie information can be carried in the interface request, so as to simply and conveniently implement the cross-domain carrying of cookies. Moreover, the above method only needs to configure a domain name mapping relationship, the configuration method is convenient, the maintenance is simple, and the maintenance cost is reduced.
[0102] Through the above method, developers do not need to configure Host, Nginx, do not need to pay attention to whether the interface domain name supports https, and do not need to pay attention to whether the Cookie is set with the SameSite attribute. The front end only needs to configure a simple domain name mapping relationship to carry the required Cookie for normal access. It is highly reusable and maintainable, which improves development efficiency.
[0103] Figure 4 The figure is a flowchart of a method for carrying Cookies across domains according to an exemplary embodiment.
[0104] refer to Figure 4 The above-mentioned cross-domain Cookie carrying method may include the following steps.
[0105] Step S402: intercepting an interface request sent by the client, and using the domain name carried in the interface request as the first domain name.
[0106] Step S404, obtaining domain name mapping relationship.
[0107] Step S406: Determine whether the first domain name is configured with a mapped domain name according to the domain name mapping relationship.
[0108] Step S408: If it is determined according to the domain name mapping relationship that the first domain name is configured with a mapped domain name, a mapped domain name corresponding to the first domain name is determined according to the domain name mapping relationship, and the mapped domain name corresponding to the first domain name is used as the second domain name;
[0109] Step S410, obtaining Cookie information under the second domain name as the first Cookie information.
[0110] Step S412, write the first Cookie information under the second domain name into the interface request.
[0111] Step S414, re-initiate the interface request.
[0112] In some embodiments, the cookie information of all domain names related to the first domain name can be written into the interface request through the domain name mapping relationship, so that the interface request carries the cookie information of all domain names related to the first domain name.
[0113] The following will be Figure 5 The illustrated embodiment illustrates this.
[0114] Figure 5 The figure is a flowchart of a method for carrying Cookies across domains according to an exemplary embodiment.
[0115] refer to Figure 5 The above-mentioned cross-domain Cookie carrying method may include the following steps.
[0116] Step S502: intercepting an interface request sent by the client, and using the domain name carried in the interface request as the first domain name.
[0117] Step S504, obtaining domain name mapping relationship.
[0118] Step S506: determining a second domain name corresponding to the first domain name according to the domain name mapping relationship, where the first domain name is different from the second domain name.
[0119] Step S508, obtaining Cookie information under the second domain name as the first Cookie information.
[0120] Step S510: determining a third domain name corresponding to the first domain name according to the domain name mapping relationship, where the third domain name is different from the first domain name and also different from the second domain name.
[0121] In some embodiments, it is determined through a domain name mapping relationship that the first domain name can correspond to the second domain name and the third domain name at the same time, wherein the first domain name, the second domain name and the third domain name are directly different from each other.
[0122] Step S512, obtaining the Cookie under the third domain name as the second Cookie information.
[0123] Step S514, write the first Cookie information under the second domain name and the second Cookie information under the third domain name into the interface request.
[0124] The cookie information under the second domain name and the third domain name related to the first domain name may be written into the interface request, so that the interface request carries the cookie information under all domain names related to the first domain name.
[0125] In some embodiments, the Cookie returned by the server can be planted under the domain name corresponding to the server itself. Figure 6 The illustrated embodiment describes the growing process of Cookie.
[0126] Figure 6 The figure is a flow chart of a Cookie planting method according to an exemplary embodiment.
[0127] In the following embodiments, the client is a browser as an example for description, but the client can also be other, and this application does not limit this.
[0128] refer to Figure 6 , the above-mentioned Coolie planting method may include the following steps.
[0129] Step S602: The browser receives the first Cookie information returned by the first server.
[0130] In some embodiments, when a user initiates a request to the first server through a browser, the first server may return a cookie information to the browser. It can be assumed here that the cookie information returned by the server to the browser is the first cookie information.
[0131] In some embodiments, when a user initiates a login request to the first server through a browser, the first server may return Cookie information to the browser.
[0132] Step S604: determine that the domain name of the first server is the second domain name.
[0133] Step S606, planting the first Cookie information under the second domain name.
[0134] In some embodiments, the Cookie information returned by the first server may be planted under the domain name where the first server is located (ie, the second domain name).
[0135] Step S608: The browser receives the second Cookie information returned by the second server.
[0136] Step S610: determine that the domain name of the second server is a third domain name.
[0137] Step S612, planting the second Cookie information under the third domain name.
[0138] In some embodiments, the Cookie information returned by the second server can be planted under the domain name where the second server is located (ie, the third domain name).
[0139] In other words, the cookie information can be planted under the domain name of the server that returns the cookie.
[0140] In some embodiments, the above-mentioned domain name mapping relationship can be configured through a configuration page provided by a plug-in, or through a configuration file. The present application does not limit the configuration method of the above-mentioned domain name mapping relationship.
[0141] Figure 7 The present invention is a flowchart of a method for configuring a domain name mapping relationship according to an exemplary embodiment.
[0142] refer to Figure 7 The above domain name mapping relationship configuration method may include the following steps.
[0143] Step S702: display the plug-in configuration page.
[0144] In some embodiments, a plug-in configuration page may be displayed to configure the plug-in.
[0145] Step S704, receiving a domain name mapping relationship through the plug-in configuration page, the domain name mapping relationship is used to associate the first domain name with the second domain name, and to associate the first domain name with the third domain name, so that the client can carry the cookie information under the second domain name and the third domain name when initiating a request under the first domain name.
[0146] like Figure 3 As shown, the plug-in configuration page may include multiple mapping relationships, each of which may include a target domain name and a cookie storage domain name. The target domain name may be the domain name carried in the request, and the cookie storage domain name may be a domain name that may store cookies associated with the target domain name.
[0147] In some embodiments, those skilled in the art can configure the above domain name mapping relationship according to actual needs.
[0148] like Figure 3As shown, there may also be a delete control in the plug-in configuration page to control whether to delete the domain name mapping relationship.
[0149] like Figure 3 As shown, the plug-in configuration page may also have a "whether to open" control, which can control whether the corresponding domain name mapping relationship is valid. In some embodiments, when the "whether to open" control is selected, it may represent that the corresponding domain name mapping relationship is valid; when the "whether to open" control is not selected, it may represent that the corresponding domain name mapping relationship is invalid.
[0150] The embodiment of the present application also provides a method for carrying Cookies across domains.
[0151] Figure 8 This is a structural framework diagram corresponding to a method of carrying cookies across domains.
[0152] like Figure 8 As shown, the browser page can initiate an interface request, and the interface request can carry the domain name of the domain where the browser is located.
[0153] like Figure 8 As shown, the browser plug-in can intercept the above interface request, and then obtain the cookies under other domain names related to the domain name carried in the interface request based on the domain name mapping relationship in the plug-in, write them into the interface request, and then re-initiate the interface request.
[0154] like Figure 8 As shown, the server interface can accept requests to normally obtain data and all cookie information in the interface.
[0155] This application also provides Fig. 9 The method shown is to carry cookies across domains.
[0156] Fig. 9 The figure is a flowchart of a method for carrying Cookies across domains according to an exemplary embodiment.
[0157] Specifically, the above-mentioned cross-domain Cookie carrying method may include the following steps.
[0158] 1. Develop a browser plug-in. The background of the plug-in (a background script file) has high permissions and can call almost all browser interface APIs without cross-domain restrictions. Therefore, the plug-in can obtain cookie information under different domains, etc.;
[0159] 2. Domain name mapping management: Configure a set of domain name mapping relationships through the pop-up of the plug-in, that is, configure the target domain name and the domain name stored in Cookie. The general interface is as follows Figure 3 shown.
[0160] From the above plug-in page, this embodiment can dynamically manage the mapping management of domain names. In the above example, the cookie information is stored in the b domain name, so when an access request is initiated in the a domain name, abc domain name, d domain name and e domain name, the access request can normally carry the cookie information in the b domain name.
[0161] The above content is the process of plug-in development and use. The following will describe how to implement the above cross-domain cookie carrying method through the developed plug-in. Fig. 9 As described in the illustrated embodiment.
[0162] 3. When the page makes an interface request (such as Fig. 9 Step 901), first, it will be intercepted by the plug-in to determine whether the target domain name in the request has a corresponding mapping relationship (such as Fig. 9 Step S902), if there is a mapping relationship and the switch is turned on (such as Fig. 9 Step S903), the plug-in obtains the Cookie storage domain name corresponding to the target domain name (such as Fig. 9 Step S904), the plug-in provides an interface to obtain all Cookie information under the domain name. After obtaining the Cookie information, the plug-in will rewrite the Cookie in the current request interface request (such as Fig. 9 Step S905 shown), re-initiate the request (such as Fig. 9 Step S906 shown in the figure) is performed, thereby allowing normal access.
[0163] In some embodiments, when the plug-in is developed, it can be published to the application store. When the developer needs it, he can download and install it and configure the corresponding domain name mapping relationship to solve the problem of carrying cookies across domains. The configuration is simple and easy to use.
[0164] In the above embodiment, the browser plug-in can call all interfaces without limiting cross-domain. A browser plug-in is developed on the front end, domain name mapping management rules are configured, interface requests are intercepted, and cookie information in the request is rewritten according to the domain name mapping relationship, thereby solving the problem that cookies cannot be carried normally across domains during the development process. The operation is simple and the efficiency of development joint debugging and troubleshooting is improved.
[0165] It should be particularly pointed out that the various steps in the various embodiments of the above-mentioned cross-domain cookie carrying method can be mutually crossed, replaced, added, and deleted. Therefore, these reasonable permutations, combinations, and transformations of the cross-domain cookie carrying method should also belong to the protection scope of this disclosure, and the protection scope of this disclosure should not be limited to the embodiments.
[0166] Based on the same inventive concept, the present disclosure also provides a cross-domain Cookie carrying device, such as the following embodiment. Since the principle of solving the problem in the device embodiment is similar to that in the above method embodiment, the implementation of the device embodiment can refer to the implementation of the above method embodiment, and the repeated parts will not be repeated.
[0167] Fig.10 is a block diagram of a device for carrying cookies across domains according to an exemplary embodiment. Fig.10 The cross-domain Cookie carrying device 1000 provided in the embodiment of the present disclosure may include: a request interception module 1001, a mapping relationship acquisition module 1002, a mapping domain name determination module 1003, an information determination module 1004, an information writing module 1005 and a re-initiating request module 1006.
[0168] Among them, the request interception module 1001 can be used to intercept the interface request issued by the client, and use the domain name carried in the interface request as the first domain name; the mapping relationship acquisition module 1002 can be used to obtain the domain name mapping relationship; the mapping domain name determination module 1003 can be used to determine the second domain name corresponding to the first domain name according to the domain name mapping relationship, and the first domain name is different from the second domain name; the information determination module 1004 can be used to obtain the Cookie information under the second domain name as the first Cookie information; the information writing module 1005 can be used to write the first Cookie information under the second domain name into the interface request; the re-initiate request module 1006 can be used to re-initiate the interface request.
[0169] It should be noted that the request interception module 1001, mapping relationship acquisition module 1002, mapping domain name determination module 1003, information determination module 1004, information writing module 1005, and re-initiating request module 1006 correspond to S202 to S212 in the method embodiment, and the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above method embodiment. It should be noted that the above modules as part of the device can be executed in a computer system such as a set of computer executable instructions.
[0170] In some embodiments, the mapped domain name determination module 1003 may include: a mapping relationship determination submodule and a second domain name determination submodule.
[0171] Among them, the mapping relationship determination submodule can be used to determine whether the first domain name is configured with a mapped domain name according to the domain name mapping relationship; the second domain name determination submodule can be used to determine the mapped domain name corresponding to the first domain name according to the domain name mapping relationship if it is determined according to the domain name mapping relationship that the first domain name is configured with a mapped domain name, and use the mapped domain name corresponding to the first domain name as the second domain name.
[0172] In some embodiments, the cross-domain Cookie carrying device 1000 may include: a third domain name determination module and a second information acquisition module.
[0173] Among them, the third domain name determination module can be used to determine the third domain name corresponding to the first domain name according to the domain name mapping relationship. The third domain name is different from the first domain name, and the third domain name is also different from the second domain name; the second information acquisition module can be used to obtain the Cookie under the third domain name as the second Cookie information.
[0174] The information writing module 1005 may include: an information writing submodule.
[0175] Among them, the information writing submodule can be used to write the first cookie information under the second domain name and the second cookie information under the third domain name into the interface request.
[0176] In some embodiments, the client is a browser, and the information writing module 1005 may further include: a first information receiving submodule, a domain name determining submodule, and a first information seeding submodule.
[0177] Among them, the first information receiving submodule can be used by the browser to receive the first Cookie information returned by the first server; the domain name determination submodule can be used to determine that the domain name of the first server is the second domain name; the first information planting submodule can be used to plant the first Cookie information under the second domain name.
[0178] In some embodiments, the cross-domain Cookie carrying device 1000 may also include: a second information receiving module, a third domain name determination submodule and a second information seeding submodule.
[0179] Among them, the second information receiving module can be used by the browser to receive the second Cookie information returned by the second server; the third domain name determination submodule can be used to determine that the domain name of the second server is the third domain name; the second information planting submodule can be used to plant the second Cookie information under the third domain name.
[0180] In some embodiments, the cross-domain Cookie carrying device 1000 may also include: a page display module and a mapping relationship configuration module.
[0181] Among them, the page display module can be used to display the plug-in configuration page before obtaining the domain name mapping relationship; the mapping relationship configuration module can be used to receive the domain name mapping relationship through the plug-in configuration page, and the domain name mapping relationship is used to associate the first domain name with the second domain name, and to associate the first domain name with the third domain name, so that the client can carry the cookie information under the second domain name and the third domain name when initiating a request under the first domain name.
[0182] Since the functions of the device 1000 have been described in detail in the corresponding method embodiments, the present disclosure will not elaborate on them here.
[0183] The modules and / or submodules involved in the embodiments described in the present disclosure may be implemented by software or hardware. The modules and / or submodules described may also be arranged in a processor. The names of these modules and / or submodules do not, in certain cases, constitute limitations on the modules and / or submodules themselves.
[0184] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a part of a module or program segment, and a part of the above-mentioned module or program segment 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 an order different from that 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 flowchart, and the combination of boxes in the block diagram or flowchart, 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 program instructions.
[0185] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present disclosure, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0186] Fig.11 FIG. 1 shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiment of the present disclosure. It should be noted that: Fig.11 The electronic device 1100 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0187] like Fig.11As shown, the electronic device 1100 includes a central processing unit (CPU) 1101, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1102 or a program loaded from a storage part 1108 into a random access memory (RAM) 1103. In the RAM 1103, various programs and data required for the operation of the electronic device 1100 are also stored. The CPU 1101, the ROM 1102, and the RAM 1103 are connected to each other via a bus 1104. An input / output (I / O) interface 1105 is also connected to the bus 1104.
[0188] The following components are connected to the I / O interface 1105: an input section 1106 including a keyboard, a mouse, etc.; an output section 1107 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1108 including a hard disk, etc.; and a communication section 1109 including a network interface card such as a LAN card, a modem, etc. The communication section 1109 performs communication processing via a network such as the Internet. A drive 1110 is also connected to the I / O interface 1105 as needed. A removable medium 1111, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1110 as needed, so that a computer program read therefrom is installed into the storage section 1108 as needed.
[0189] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable storage medium, and the computer program contains computer program instructions for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication part 1109, and / or installed from a removable medium 1111. When the computer program is executed by a central processing unit (CPU) 1101, the above-mentioned functions defined in the system of the present disclosure are executed.
[0190] It should be noted that the computer-readable storage medium shown in the present disclosure 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 disclosure, 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 disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable computer program instructions. 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. The computer-readable signal medium may also be any computer-readable storage medium other than a computer-readable storage medium that can send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The computer program instructions contained on the computer-readable storage 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.
[0191] As another aspect, the present disclosure also provides a computer-readable storage 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 storage medium carries one or more programs, and when the above one or more programs are executed by a device, the device can implement functions including: intercepting an interface request sent by a client, and using the domain name carried in the interface request as the first domain name; obtaining a domain name mapping relationship; determining a second domain name corresponding to the first domain name according to the domain name mapping relationship, the first domain name is different from the second domain name; obtaining Cookie information under the second domain name as the first Cookie information; writing the first Cookie information under the second domain name into the interface request; and re-initiating the interface request.
[0192] According to one aspect of the present disclosure, a computer program product or a computer program is provided, the computer program product or the computer program comprising computer program instructions, the computer program instructions being stored in a computer-readable storage medium. The computer program instructions are read from the computer-readable storage medium, and a processor executes the computer program instructions to implement the methods provided in various optional implementations of the above embodiments.
[0193] Through the description of the above implementation methods, it is easy for those skilled in the art to understand that the example implementation methods described here can be implemented by software, or by combining software with necessary hardware. Therefore, the technical solution of the embodiment of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), including a number of computer program instructions for enabling an electronic device (which can be a server or a terminal device, etc.) to execute the method according to the embodiment of the present disclosure.
[0194] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the disclosure disclosed herein. The present disclosure is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and embodiments are to be regarded as exemplary only, and the true scope and spirit of the present disclosure are indicated by the claims.
[0195] It should be understood that the present disclosure is not limited to the detailed structures, drawings or implementations shown herein, but rather the present disclosure is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims.
Claims
1. A method for carrying cookies across domains. It is characterized in that include: Intercepting an interface request sent by a client, and using the domain name carried in the interface request as the first domain name; Get domain name mapping relationship; Determine a second domain name corresponding to the first domain name according to the domain name mapping relationship, where the first domain name is different from the second domain name; Obtain the Cookie information under the second domain name as the first Cookie information; Writing the first cookie information under the second domain name into the interface request; Re-initiate the interface request.
2. The method according to claim 1, It is characterized in that Determining a second domain name corresponding to the first domain name according to the domain name mapping relationship includes: Determine whether the first domain name is configured with a mapped domain name according to the domain name mapping relationship; If it is determined according to the domain name mapping relationship that the first domain name is configured with a mapped domain name, the mapped domain name corresponding to the first domain name is determined according to the domain name mapping relationship, and the mapped domain name corresponding to the first domain name is used as the second domain name.
3. The method according to claim 1, It is characterized in that The method further comprises: Determine a third domain name corresponding to the first domain name according to the domain name mapping relationship, wherein the third domain name is different from the first domain name, and the third domain name is also different from the second domain name; Obtain the Cookie under the third domain name as the second Cookie information; Wherein, writing the first cookie information under the second domain name into the interface request includes: The first cookie information under the second domain name and the second cookie information under the third domain name are written into the interface request.
4. The method according to claim 1, It is characterized in that The client is a browser, and the method further comprises: The browser receives the first Cookie information returned by the first server; Determining that the domain name of the first server is the second domain name; Plant the first Cookie information under the second domain name.
5. The method according to claim 4, It is characterized in that The method further comprises: The browser receives the second Cookie information returned by the second server; Determining that the domain name of the second server is a third domain name; Plant the second Cookie information under the third domain name.
6. The method according to claim 1, It is characterized in that Before obtaining the domain name mapping relationship, the method includes: Display the plugin configuration page; The domain name mapping relationship is received through the plug-in configuration page, and the domain name mapping relationship is used to associate the first domain name with the second domain name and to associate the first domain name with a third domain name, so that the client can carry the cookie information under the second domain name and the third domain name when initiating a request under the first domain name.
7. The method according to claim 1, It is characterized in that The method further comprises: Determining, according to the domain name mapping relationship, that there is no domain name associated with the first domain name, or determining that the first domain name does not exist in the domain name mapping relationship; Continue to issue the interface request.
8. A device for carrying cookies across domains, It is characterized in that include: A request interception module, used to intercept an interface request sent by a client, and use the domain name carried in the interface request as the first domain name; A mapping relationship acquisition module is used to obtain domain name mapping relationships; a mapping domain name determination module, configured to determine a second domain name corresponding to the first domain name according to the domain name mapping relationship, wherein the first domain name is different from the second domain name; An information determination module, used to obtain Cookie information under the second domain name as first Cookie information; An information writing module, used for writing the first Cookie information under the second domain name into the interface request; The re-initiating request module is used to re-initiate the interface request.
9. An electronic device, It is characterized in that include: Memory; as well as A processor coupled to the memory, the processor being used to execute the cross-domain cookie carrying method as described in any one of claims 1-7 based on computer program instructions stored in the memory.
10. A computer-readable storage medium having computer program instructions stored thereon, It is characterized in that When the computer program instructions are executed by a processor, the cross-domain cookie carrying method as described in any one of claims 1-7 is implemented.
11. A computer program product comprising computer program instructions stored in a computer readable storage medium, It is characterized in that When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 7 is implemented.
