WO2018228036A1 - 校验方法、装置、服务端及可读存储介质 - Google Patents

校验方法、装置、服务端及可读存储介质 Download PDF

Info

Publication number
WO2018228036A1
WO2018228036A1 PCT/CN2018/082350 CN2018082350W WO2018228036A1 WO 2018228036 A1 WO2018228036 A1 WO 2018228036A1 CN 2018082350 W CN2018082350 W CN 2018082350W WO 2018228036 A1 WO2018228036 A1 WO 2018228036A1
Authority
WO
WIPO (PCT)
Prior art keywords
verification
information
session
network request
carried
Prior art date
Application number
PCT/CN2018/082350
Other languages
English (en)
French (fr)
Inventor
熊长江
张文明
陈少杰
Original Assignee
武汉斗鱼网络科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 武汉斗鱼网络科技有限公司 filed Critical 武汉斗鱼网络科技有限公司
Publication of WO2018228036A1 publication Critical patent/WO2018228036A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/08Network architectures or network communication protocols for network security for authentication of entities
    • H04L63/0815Network architectures or network communication protocols for network security for authentication of entities providing single-sign-on or federations
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/08Network architectures or network communication protocols for network security for authentication of entities
    • H04L63/0807Network architectures or network communication protocols for network security for authentication of entities using tickets, e.g. Kerberos

Definitions

  • the present disclosure relates to the field of identity verification technologies, and in particular, to a verification method, apparatus, server, and readable storage medium.
  • the server After the user logs in successfully, in order to avoid maliciously requesting unauthorized request access, the server also needs to verify the network request sent by the client.
  • Most of the existing verification methods are implemented from the perspective of server development, which brings a lot of inconvenience to front-end development.
  • the verification method used As the type of service interface changes, the verification method used needs to be changed accordingly. Therefore, the business architecture of the front-end project needs to be adjusted to adapt to the new verification method, resulting in huge workload and low development efficiency.
  • an object of the present disclosure includes providing a verification method, apparatus, server, and readable storage medium to improve the above problems.
  • an embodiment of the present disclosure provides a verification method, which is applied to a server that communicates with a client, and the method includes:
  • the verification information is generated according to the login request
  • the network request is verified according to the verification information carried in the received network request, and the interface requesting the call is invoked when the verification is passed.
  • the verification information is generated according to the login request, including:
  • the non-relational database is stored in the server; the user information carried in the login request is associated with the session ID of the session, and the associated user information and the session ID are stored.
  • the user information carried in the login request is associated with the session ID of the session, and the associated user information and the session ID are stored.
  • the key-value pairs are stored in the non-relational database.
  • generating a token according to the session ID and the first parameter information carried in the login request including:
  • the first parameter information is used as a parameter of the createtoken method, and the token is generated by using a JWT temporary token generation algorithm.
  • the network request is verified according to the verification information carried in the received network request, including:
  • the verification information further includes the session ID, and sending the verification information to the client, including:
  • the network request is verified according to the verification information carried in the received network request, including:
  • the session ID is carried in the network request, the user information associated with the session ID is found, and when the user information is not expired, the network request verification is determined to pass.
  • the network ID is carried in the network request, the user information associated with the session ID is found, and the network request verification is determined when the user information is not expired, including:
  • the session ID is carried in the network request
  • the user information used by the user to log in is read in the non-relational database by using the session ID, and if the read user information is not expired, The network request verification is passed.
  • the network request is verified according to the verification information carried in the received network request, including:
  • session ID is not carried in the network request, parsing the token carried in the network request, and obtaining the session ID and the first parameter information;
  • the embodiment of the present disclosure further provides a verification apparatus, which is applied to a server that communicates with a client, and the apparatus includes:
  • a verification information generating module configured to generate verification information according to the login request after the login request verification sent by the client is passed;
  • a verification information sending module configured to send the verification information to the client
  • a receiving module configured to receive a network request that is sent by the client and that carries the verification information
  • the verification module is configured to check the network request according to the verification information carried in the received network request, and invoke the network request to declare the invoked interface when the verification is passed.
  • the verification information includes a token
  • the manner in which the verification information generating module generates the verification information according to the login request after the verification of the login request sent by the client includes:
  • the server stores a non-relational database
  • the verification information generating module associates the user information carried in the login request with the session ID of the session, and associates the associated user.
  • the way information and session IDs are stored includes:
  • the key-value pairs are stored in the non-relational database.
  • the manner in which the verification information generating module generates the token according to the session ID and the first parameter information carried in the login request includes:
  • the first parameter information is used as a parameter of the createtoken method, and the token is generated by using a JWT temporary token generation algorithm.
  • the manner in which the verification module checks the network request according to the verification information carried in the received network request includes:
  • the verification information further includes the session ID
  • the manner in which the verification information sending module sends the verification information to the client includes:
  • the manner in which the verification module checks the network request according to the verification information carried in the received network request includes:
  • the session ID is carried in the network request, the user information associated with the session ID is found, and when the user information is not expired, the network request verification is determined to pass.
  • the check module detects that the session ID is carried in the network request, the user information associated with the session ID is found, and the network request is determined when the user information is not expired.
  • the way to pass the verification includes:
  • the session ID is carried in the network request
  • the user information used by the user to log in is read in the non-relational database by using the session ID, and if the read user information is not expired, The network request verification is passed.
  • the manner in which the verification module checks the network request according to the verification information carried in the received network request includes:
  • session ID is not carried in the network request, parsing the token carried in the network request, and obtaining the session ID and the first parameter information;
  • the embodiment of the present disclosure further provides a server, including a processor and a non-volatile memory storing a plurality of computer instructions.
  • the server executes the verification method.
  • the embodiment of the present disclosure further provides a readable storage medium, where the readable storage medium includes a computer program, and the computer program controls the server where the readable storage medium is located to execute the verification method described above.
  • the verification method, the device, the server, and the readable storage medium provided by the embodiment of the present disclosure are used to verify a network request initiated by the client after the user successfully logs in, thereby implementing identity verification of the user.
  • the server After the server authenticates the login request sent by the client, the server generates verification information according to the login request and sends it to the client.
  • the server receives the network request that carries the verification information sent by the client after the login request is verified, checks the received network request according to the verification information, and invokes the network request to declare the call when the verification is passed. interface.
  • the verification method and apparatus provided by the present disclosure are applied only to the request interface that needs to be verified, and the front end does not need to be adjusted according to the type of the interface, thereby greatly reducing the workload of the developer and improving the development efficiency.
  • FIG. 1 is a schematic diagram of interaction between a server and a client according to an embodiment of the present disclosure.
  • FIG. 2 is a schematic block diagram of a server provided by an embodiment of the present disclosure.
  • FIG. 3 is a schematic flowchart diagram of a verification method according to an embodiment of the present disclosure.
  • FIG. 4 is a schematic diagram of the sub-steps of step S101 shown in FIG. 3.
  • FIG. 5 is a functional block diagram of a verification apparatus according to an embodiment of the present disclosure.
  • Icon 100-server; 110-checking device; 111-check information generating module; 112-checking information transmitting module; 113-receiving module; 114-checking module; 120-memory; 130-processor; - communication unit; 200-client; 300-network.
  • FIG. 1 is a schematic diagram of interaction between a server 100 and a client 200 according to a preferred embodiment of the present disclosure.
  • the client 200 may be plural (one shown in FIG. 1).
  • the server 100 can communicate with the client 200 over the network 300 for data communication or interaction.
  • the network 300 can be a wired or wireless network.
  • the client 200 and the server 100 can be directly connected through a communication network.
  • the client 200 and the server 100 can establish a communication connection in a Wi-Fi (Wireless Fidelity) network, a 2G/3G/4G/5G network, or a local area network.
  • Wi-Fi Wireless Fidelity
  • the client 200 may be a mobile terminal device, for example, a smart phone, a tablet computer, a wearable mobile terminal, a personal digital assistant (PDA), a PC (personal computer) computer, a smart TV, Set-top box, vehicle terminal, mobile Internet device (MID), etc.
  • PDA personal digital assistant
  • PC personal computer
  • MID mobile Internet device
  • an application is installed in the client 200, and corresponds to the server 100 to provide services for the user. The user can access the server 100 through an application installed in the client 200.
  • the application may be a browser
  • the server 100 may be a web server.
  • FIG. 2 it is a block diagram of a server 100 provided by a preferred embodiment of the present disclosure.
  • the server 100 includes a verification device 110, a memory 120, one or more processors 130 (only one is shown in FIG. 2), and a communication unit 140.
  • the components of the memory 120, the processor 130, and the communication unit 140 are electrically connected to each other or indirectly to implement data transmission or interaction.
  • the components can be electrically connected to one another via one or more communication buses or signal lines.
  • the verification device 110 includes at least one software function module that can be stored in the memory 120 or in an operating system (OS) of the client 200 in the form of software or firmware.
  • OS operating system
  • the memory 120 may be, but not limited to, a random access memory (RAM), a read only memory (ROM), and a programmable read only memory (Programmable Read-Only). Memory, PROM, Erasable Programmable Read-Only Memory (EPROM), Electric Erasable Programmable Read-Only Memory (EEPROM), and the like.
  • RAM random access memory
  • ROM read only memory
  • PROM Erasable Programmable Read-Only Memory
  • EEPROM Electric Erasable Programmable Read-Only Memory
  • the processor 130 can be an integrated circuit chip with signal processing capabilities.
  • the above processor may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; or may be a digital signal processor (DSP), an application specific integrated circuit (ASIC) ), Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components.
  • the methods, steps, and logical block diagrams disclosed in the embodiments of the present disclosure may be implemented or carried out.
  • the general purpose processor may be a microprocessor or the processor or any conventional processor or the like.
  • the communication unit 140 is configured to establish a communication connection between the server 100 and the client 200 via the network 300.
  • the server 100 may also include more or less components than those shown in FIG. 2, or have a different configuration than that shown in FIG. 2.
  • the components shown in FIG. 2 can be implemented in software, hardware, or a combination thereof.
  • FIG. 3 it is a schematic flowchart of a verification method applied to the server 100 shown in FIG. 2 according to an embodiment of the present disclosure.
  • the flow and specific steps shown in FIG. 3 will be described in detail below.
  • the method may include step S101, step S102, step S103, and step S104.
  • Step S101 After the login request verification sent by the client 200 is passed, the verification information is generated according to the login request.
  • the verification method provided by the present disclosure is used for verifying the network request initiated after the login request verification sent by the client 200 is passed.
  • the user can input user information (eg, user name and user password) on the client 200 and confirm the login, the client 200 sends a login request including the user information to the server 100.
  • the server 100 receives the login request and verifies the user information carried in the login request, and confirms that the user login is successful when the verification succeeds.
  • the server 100 records the user information carried in the login request, generates a verification information, and returns the verification information to the client 200, so that the client 200 can carry the verification next time.
  • a network request for information to access the server 100 In this way, the server 100 can verify the received network request by using the verification information.
  • the login request may be a login request that is sent when the user logs in through the client 200 for the first time, or may be that the user first passes the client 200 after the user information recorded in the server 100 expires. Login request issued when logging in.
  • the server 100 includes a login interface that can be logged in by the client 200.
  • the login interface is configured to receive a login request sent by the client 200 for verification, and when the verification is passed, generate the verification information and send the verification information to the client 200.
  • the verification information may be multiple.
  • the verification information may include a token.
  • step S101 may include three sub-steps of step S201, step S202, and step S203.
  • step S201 after the login request sent by the client 200 is verified, a session is generated.
  • the session is generated by an express-session having a session ID (sessionid).
  • step S202 the user information carried in the login request is associated with the session ID of the session, and the associated user information and the session ID are stored.
  • the server 100 can be configured by using the nodejs technology and the non-relational database Redis.
  • the server 100 can cache and query data through the non-relational database redis.
  • step S202 can be implemented by the following steps.
  • a key-value pair is formed by using the session ID as a key and the user information carried in the login request as a value, and the key-value pair is stored in the non-relational database redis.
  • Step S203 Generate the token according to the session ID and the first parameter information carried in the login request.
  • the first parameter information may include, but is not limited to, a user access IP, application information, and the like.
  • the user access IP may be an IP address of the client.
  • the application information may be browser information.
  • the server 100 may generate the token by using a JWT (Json Web Tokens) manner.
  • the server 100 may use the first parameter information as a parameter of the createtoken method to generate the token by using a JWT temporary token generation algorithm.
  • the verification method provided by the present disclosure is more secure and has fewer additional operations.
  • the session ID may also be directly used as the verification information.
  • the verification information includes the token and the session ID.
  • Step S102 sending the verification information to the client 200.
  • the manner of sending the server 100 is different for different verification information.
  • the server 100 can directly return the token to the client 200.
  • the server 100 may generate a cookie information after the login request is verified, and store the session ID to the cookie information.
  • the server 100 sends the cookie information to the client 200, causing the client 200 to store the session ID in the cookie information into a network request.
  • the cookie information includes an expiration date of the cookie information.
  • the validity period of the cookie information is an expiration date of user information associated with the session ID.
  • the cookie information also expires, and the client 200 cannot extract the session ID and store it in the network request.
  • the server 100 will not be able to receive the received network.
  • the session ID was detected in the request.
  • Step S103 receiving a network request that is sent by the client 200 and carrying the verification information.
  • the verification method is used to verify all network requests sent by the client 200 after the login request is verified. Therefore, the network request received by the server 100 refers to all network requests sent by the client 200 after the login request is verified. And, the verification information is carried in each of the network requests.
  • the network request may be an HTTP request
  • the information in the HTTP request header is automatically sent to the server 100 in each HTTP request.
  • the client 200 inserts the token into the request header of the HTTP request after receiving the token.
  • the token is carried in each HTTP request sent by the client 200, and the token is not required to be submitted as a request parameter each time an HTTP request is sent.
  • the client 200 sends the session ID stored in the cookie information as a parameter of the HTTP request to the node after receiving the cookie information.
  • the server 100 As such, when the cookie information expires, the session ID does not exist in the HTTP request.
  • Step S104 The network request is verified according to the verification information carried in the received network request, and the interface requesting the call is invoked when the verification is passed.
  • the server 100 further includes a plurality of request interfaces that are accessible by the client 200.
  • the network request sent by the client 200 to the server 100 generally indicates that there is a request interface to be accessed. If the request interface is an interface that needs to verify the identity of the user who has successfully logged in, the callback instruction at the request interface may be Previously, the network request is verified according to the verification information carried in the received network request. When the check passes, the callback instruction in the request interface is executed.
  • the request interface is an interface that does not need to verify the identity of the user who has successfully logged in
  • the callback instruction in the request interface can be directly executed.
  • step S104 may be implemented by the following steps.
  • the token carried in the received network request is parsed to obtain the session ID and the first parameter information.
  • the server 100 For each network request sent by the client 200 after the user successfully logs in, the server 100 searches for the token from the request header of the network request for parsing.
  • the method of parsing the token matches the method of generating the token. For example, if the token is generated by the JWT encryption algorithm, the corresponding JWT decryption algorithm should also be used for decryption. Since the token is generated according to the session ID and the first parameter information, the session ID and the first parameter information are also obtained by parsing the token.
  • the user information associated with the session ID is found, and the network request verification is determined when the searched user information is not expired, and/or the second parameter carried in the network request is obtained. And determining, by the information, whether the second parameter information is the same as the parsed first parameter information, and determining that the network request verification passes when the second parameter information is the same as the first parameter information.
  • the network request sent by the client 200 after the login request verification is passed carries the second parameter information that is the same as the parameter type included in the first parameter information. Therefore, during the verification, the first parameter information may be obtained according to the token, and then the first parameter information is compared with the second parameter information, and the network request is determined whether the verification is passed according to the comparison result. Thereby verifying the identity of the user.
  • the first parameter information includes a user access IP and browser information.
  • the user access IP may be an IP address of the client.
  • the second parameter information also includes the current user's user access IP and browser information.
  • the current user's user access IP address may be the IP address of the client where the current user is located.
  • the server 100 may obtain the session ID according to the token carried in the received network request, and read the user information used by the user in the non-relational database redis by using the session ID.
  • the network request is further verified according to the user information. If the read user information has not expired, it is determined that the network request verification is passed, and the network request may be responded to.
  • the server 100 may select at least one of the two verification modes to check the received network request.
  • the step S104 may be implemented by the following steps.
  • step S104 may include:
  • the network ID is carried in the network request, the user information associated with the session ID is found, and the network request verification is determined when the user information is not expired, including:
  • the session ID is carried in the network request
  • the user information used by the user to log in is read in the non-relational database by using the session ID, and if the read user information is not expired, The network request verification is passed.
  • the session ID does not exist in the network request sent by the client 200 to the server 100.
  • step S104 may include:
  • the server 100 may first detect whether the session ID is included in the received network request, and does not include the received network request. When the session ID is used, the identity of the user is verified by the token.
  • the verification method provided by the present disclosure is not limited by the type of the request interface provided by the server 100, and the verification mode can be flexibly adjusted according to actual needs.
  • the preferred embodiment of the present disclosure further provides a verification apparatus 110, which is applied to the server 100 in communication with the client 200.
  • the verification device 110 includes a verification information generation module 111, a verification information transmission module 112, a reception module 113, and a verification module 114.
  • the verification information generating module 111 is configured to generate verification information according to the login request after the login request verification sent by the client 200 is passed.
  • step S101 can be performed by the verification information generating module 111.
  • the verification information may include a token.
  • the verification information generating module 111 may generate the verification information according to the information carried in the login request of the secondary login by the client 200 after the user successfully logs in through the client 200. .
  • a session is generated.
  • the manner in which the verification information generating module 111 associates the user information carried in the login request with the session ID of the session, and stores the associated user information and the session ID includes:
  • the key-value pairs are stored in the non-relational database.
  • the manner in which the verification information generating module 111 generates the token according to the session ID and the first parameter information carried in the login request includes:
  • the first parameter information is used as a parameter of the createtoken method, and the token is generated by using a JWT temporary token generation algorithm.
  • the verification information sending module 112 is configured to send the verification information to the client 200.
  • the verification information transmitting module 112 for a description of the verification information transmitting module 112, reference may be made to the detailed description of step S102 shown in FIG. 3, that is, the step S102 may be performed by the verification information transmitting module 112.
  • the verification information further includes the session ID
  • the manner in which the verification information sending module 112 sends the verification information to the client includes:
  • the receiving module 113 is configured to receive a network request that is sent by the client 200 and that carries the verification information.
  • the description about the receiving module 113 can refer to the detailed description of step S103 shown in FIG. 3, that is, the step S103 can be performed by the receiving module 113.
  • the verification module 114 is configured to check the network request according to the verification information carried in the received network request, and invoke the network request to declare the invoked interface when the verification is passed.
  • step S104 can be performed by the verification module 114.
  • the verification module 114 can verify the identity information requested by the network according to the verification information carried in the network request.
  • the token carried in the received network request is parsed to obtain the session ID and the first parameter information.
  • the manner in which the verification module 114 verifies the network request according to the verification information carried in the received network request includes:
  • the session ID is carried in the network request, the user information associated with the session ID is found, and when the user information is not expired, the network request verification is determined to pass.
  • the check module 114 detects that the session ID is carried in the network request, the user information associated with the session ID is found, and the network is determined when the user information is not expired.
  • the way to request verification is as follows:
  • the session ID is carried in the network request
  • the user information used by the user to log in is read in the non-relational database by using the session ID, and if the read user information is not expired, The network request verification is passed.
  • the manner in which the verification module 114 verifies the network request according to the verification information carried in the received network request includes:
  • session ID is not carried in the network request, parsing the token carried in the network request, and obtaining the session ID and the first parameter information;
  • Each of the above modules may be implemented by software code.
  • each of the above modules may be stored in the memory 120.
  • the above units can also be implemented by hardware such as an integrated circuit chip.
  • verification device 110 The implementation principle and the technical effects of the verification device 110 provided in this embodiment are the same as those of the foregoing method embodiments. For the sake of brief description, where the device embodiment is not mentioned, reference may be made to the corresponding content in the foregoing method embodiments.
  • the verification method, the device, the server, and the readable storage medium are configured to verify the network request initiated by the client 200 after the user successfully logs in, thereby implementing the identity of the user. Test. After the user successfully logs in through the client 200, the server 100 generates verification information according to the information carried in the login request and sends the verification information to the client 200.
  • the server 100 receives the network request that is sent by the client 200 after the user successfully logs in, and the identity of the user is performed according to the verification information carried in the network request before the request interface called by the network request is called back. Check it out.
  • the verification method and device provided by the present disclosure need to be applied in the request interface that needs to be verified, and the front end does not need to be adjusted according to the type of the interface, thereby greatly reducing the workload of the developer and improving the development efficiency.
  • each block of the flowchart or block diagram can represent a module, a program segment, or a portion of code that comprises one or more of the Executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the blocks may also occur in a different order than those illustrated in the drawings.
  • each block of the block diagrams and/or flowcharts, and combinations of blocks in the block diagrams and/or flowcharts can be implemented in a dedicated hardware-based system that performs the specified function or function. Or it can be implemented by a combination of dedicated hardware and computer instructions.
  • each functional module in various embodiments of the present disclosure may be integrated to form a separate part, or each module may exist separately, or two or more modules may be integrated to form a separate part.
  • the functions, if implemented in the form of software functional modules and sold or used as separate products, may be stored in a computer readable storage medium.
  • a computer readable storage medium including: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like.
  • the embodiment of the present disclosure can be applied to the request interface that needs to be verified, and the verification method and device provided in this embodiment are applied to the request interface that needs to be verified. Greatly reduced the workload of developers and improved development efficiency.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Computer Security & Cryptography (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

本公开提供一种校验方法、装置、服务端及可读存储介质,方法及装置应用于与客户端通信的服务端。方法包括:在客户端发送的登录请求验证通过后,根据所述登录请求生成校验信息;将所述校验信息发送至所述客户端;接收所述客户端发送的携带有所述校验信息的网络请求;根据接收到的网络请求中携带的校验信息对该网络请求进行校验,并在校验通过时调用该网络请求申明调用的接口。如此,可以不必根据业务接口类型的变化而更改校验方式,大大提高了开发的便捷性。

Description

校验方法、装置、服务端及可读存储介质
相关申请的交叉引用
本申请要求于2017年06月12日提交中国专利局的申请号为201710439302.2、名称为“校验方法、装置及服务端”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本公开涉及身份校验技术领域,具体而言,涉及一种校验方法、装置、服务端及可读存储介质。
背景技术
在用户登录成功之后,为了避免恶意构造的非法请求访问,服务端还需要对客户端发送的网络请求进行校验。现有的校验方法大多站在服务端开发的角度去实现,为前端开发带来许多不便。随着业务接口类型的变化,所使用的校验方式也需要随之改变,进而需要对前端项目的业务架构进行调整以适应新的校验方式,导致开发人员的工作量巨大,开发效率低。
发明内容
有鉴于此,本公开的目的包括,提供一种校验方法、装置、服务端及可读存储介质,以改善上述问题。
为了达到上述目的,本公开实施例提供一种校验方法,应用于与客户端通信的服务端,所述方法包括:
在客户端发送的登录请求验证通过后,根据所述登录请求生成校验信息;
将所述校验信息发送至所述客户端;
接收所述客户端发送的携带有所述校验信息的网络请求;
根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验,并在校验通过时调用该网络请求申明调用的接口。
可选地,在客户端发送的登录请求验证通过后,根据所述登录请求生成校验信息,包括:
在客户端发送的登录请求验证通过后,生成一个会话;
将所述登录请求中携带的用户信息与所述会话的会话ID关联,并将关联后的所述用户信息与会话ID进行存储;
根据所述会话ID与所述登录请求中携带的第一参数信息生成令牌,所述校验信息包括 所述令牌。
可选地,所述服务端中存储有非关系型数据库;将所述登录请求中携带的用户信息与所述会话的会话ID关联,并将关联后的所述用户信息与会话ID进行存储,包括:
以所述会话ID为键,以所述登录请求中携带的用户信息为值,形成一键-值对;
将所述键-值对存放至所述非关系型数据库。
可选地,根据所述会话ID与所述登录请求中携带的第一参数信息生成令牌,包括:
将所述第一参数信息作为createtoken方法的参数,利用JWT临时令牌生成算法生成所述令牌。
可选地,根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验,包括:
解析接收到的网络请求中携带的所述令牌,得到所述会话ID及所述第一参数信息;
查找出与所述会话ID关联的用户信息,并在查找出的所述用户信息未过期时确定所述网络请求校验通过,和/或,获取所述网络请求中携带的第二参数信息,判断所述第二参数信息与解析得到的第一参数信息是否相同,并在所述第二参数信息与所述第一参数信息相同时,确定所述网络请求校验通过。
可选地,所述校验信息还包括所述会话ID;将所述校验信息发送至所述客户端,包括:
生成一个cookie信息,并将所述会话ID存入所述cookie信息,所述cookie信息的有效期限为与所述会话ID关联的用户信息的有效期限;
将所述cookie信息发送至所述客户端,使所述客户端在所述cookie信息未过期时将所述cookie信息中的会话ID存放至网络请求中。
可选地,根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验,包括:
检测接收到的网络请求中是否携带有所述会话ID;
若所述网络请求中携带有所述会话ID,则查找出与所述会话ID关联的用户信息,并在所述用户信息未过期时确定该网络请求校验通过。
可选地,若所述网络请求中携带有所述会话ID,则查找出与所述会话ID关联的用户信息,并在所述用户信息未过期时确定该网络请求校验通过,包括:
若所述网络请求中携带有所述会话ID,通过所述会话ID在所述非关系型数据库中读取该用户登录时所用的用户信息,若读取到的用户信息未过期,则确定所述网络请求校验通过。
可选地,根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验,包括:
检测接收到的网络请求中是否携带有所述会话ID;
若所述网络请求中未携带所述会话ID,则解析所述网络请求中携带的所述令牌,得到所述会话ID及所述第一参数信息;
查找出与所述会话ID关联的用户信息,并在查找出的所述用户信息未过期时确定所述网络请求校验通过,和/或,获取所述网络请求中携带的第二参数信息,判断所述第二参数信息与解析得到的第一参数信息是否相同,并在所述第二参数信息与所述第一参数信息相同时确定所述网络请求校验通过。
本公开实施例还提供一种校验装置,应用于与客户端通信的服务端,所述装置包括:
校验信息生成模块,配置成在客户端发送的登录请求验证通过后,根据所述登录请求生成校验信息;
校验信息发送模块,配置成将所述校验信息发送至所述客户端;
接收模块,配置成接收所述客户端发送的携带有所述校验信息的网络请求;
校验模块,配置成根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验,并在校验通过时调用该网络请求申明调用的接口。
可选地,所述校验信息包括令牌;所述校验信息生成模块在客户端发送的登录请求验证通过后,根据所述登录请求生成校验信息的方式,包括:
在客户端发送的登录请求验证通过后,生成一个会话;
将所述登录请求中携带的用户信息与所述会话的会话ID关联,并将关联后的所述用户信息与会话ID进行存储;
根据所述会话ID与所述登录请求中携带的第一参数信息生成所述令牌。
可选地,所述服务端中存储有非关系型数据库,所述校验信息生成模块将所述登录请求中携带的用户信息与所述会话的会话ID关联,并将关联后的所述用户信息与会话ID进行存储的方式包括:
以所述会话ID为键,以所述登录请求中携带的用户信息为值,形成一键-值对;
将所述键-值对存放至所述非关系型数据库。
可选地,所述校验信息生成模块根据所述会话ID与所述登录请求中携带的第一参数信息生成所述令牌的方式包括:
将所述第一参数信息作为createtoken方法的参数,利用JWT临时令牌生成算法生成所述令牌。
可选地,所述校验模块根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验的方式,包括:
解析接收到的网络请求中携带的所述令牌,得到所述会话ID及所述第一参数信息;
查找出与所述会话ID关联的用户信息,并在查找出的所述用户信息未过期时确定所述网络请求校验通过,和/或,获取所述网络请求中携带的第二参数信息,判断所述第二参数信息与解析得到的第一参数信息是否相同,并在所述第二参数信息与所述第一参数信息相 同时,确定所述网络请求校验通过。
可选地,所述校验信息还包括所述会话ID,所述校验信息发送模块将所述校验信息发送至所述客户端的方式包括:
生成一个cookie信息,并将所述会话ID存入所述cookie信息,所述cookie信息的有效期限为与所述会话ID关联的用户信息的有效期限;
将所述cookie信息发送至所述客户端,使所述客户端在所述cookie信息未过期时将所述cookie信息中的会话ID存放至网络请求中。
可选地,所述校验模块根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验的方式,包括:
检测接收到的网络请求中是否携带有所述会话ID;
若所述网络请求中携带有所述会话ID,则查找出与所述会话ID关联的用户信息,并在所述用户信息未过期时确定该网络请求校验通过。
可选地,所述校验模块若检测到所述网络请求中携带有所述会话ID,则查找出与所述会话ID关联的用户信息,并在所述用户信息未过期时确定该网络请求校验通过的方式包括:
若所述网络请求中携带有所述会话ID,通过所述会话ID在所述非关系型数据库中读取该用户登录时所用的用户信息,若读取到的用户信息未过期,则确定所述网络请求校验通过。
可选地,所述校验模块根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验的方式,包括:
检测接收到的网络请求中是否携带有所述会话ID;
若所述网络请求中未携带所述会话ID,则解析所述网络请求中携带的所述令牌,得到所述会话ID及所述第一参数信息;
查找出与所述会话ID关联的用户信息,并在查找出的所述用户信息未过期时确定所述网络请求校验通过,和/或,获取所述网络请求中携带的第二参数信息,判断所述第二参数信息与解析得到的第一参数信息是否相同,并在所述第二参数信息与所述第一参数信息相同时确定所述网络请求校验通过。
本公开实施例还提供一种服务端,包括处理器以及存储有若干计算机指令的非易失性存储器,所述计算机指令被所述处理器执行时,所述服务端执行上述的校验方法。
本公开实施例还提供了一种可读存储介质,所述可读存储介质包括计算机程序,所述计算机程序运行时控制所述可读存储介质所在服务端执行上述的校验方法。
本公开实施例提供的校验方法、装置、服务端及可读存储介质,用于校验客户端在用 户登录成功后发起的网络请求,进而实现对该用户的身份校验。服务端在客户端发送的登录请求验证通过后,根据登录请求生成校验信息发送至客户端。服务端接收客户端在登录请求验证通过后发送的携带有校验信息的网络请求,根据该校验信息对接收到的网络请求进行校验,并在校验通过时调用该网络请求申明调用的接口。如此,只需针对需要进行校验的请求接口应用本公开提供的校验方法及装置,不必根据接口的类型对前端进行调整,大大降低了开发人员的工作量,提高了开发效率。
附图说明
为了更清楚地说明本公开实施例的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,应当理解,以下附图仅示出了本公开的某些实施例,因此不应被看作是对范围的限定,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他相关的附图。
图1为本公开实施例提供的一种服务端与客户端的交互示意图。
图2为本公开实施例提供的一种服务端的方框示意图。
图3为本公开实施例提供的一种校验方法的流程示意图。
图4为图3所示步骤S101的子步骤示意图。
图5为本公开实施例提供的一种校验装置的功能模块框图。
图标:100-服务端;110-校验装置;111-校验信息生成模块;112-校验信息发送模块;113-接收模块;114-校验模块;120-存储器;130-处理器;140-通信单元;200-客户端;300-网络。
具体实施方式
为使本公开实施例的目的、技术方案和优点更加清楚,下面将结合本公开实施例中的附图,对本公开实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本公开一部分实施例,而不是全部的实施例。通常在此处附图中描述和示出的本公开实施例的组件可以以各种不同的配置来布置和设计。
因此,以下对在附图中提供的本公开的实施例的详细描述并非旨在限制要求保护的本公开的范围,而是仅仅表示本公开的选定实施例。基于本公开中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本公开保护的范围。
应注意到:相似的标号和字母在下面的附图中表示类似项,因此,一旦某一项在一个附图中被定义,则在随后的附图中不需要对其进行进一步定义和解释。
如图1所示,是本公开较佳实施例提供的一种服务端100与客户端200的交互示意图。在本实施例中,客户端200可以为多个(图1中示出一个)。服务端100可通过网络300与 客户端200通信,以进行数据通信或交互。所述网络300可以是有线或无线网络。本实施例中,客户端200和服务器100能够通过通信网络直接连接。客户端200、服务器100可以在Wi-Fi(无线保真)网络、2G/3G/4G/5G网络或局域网中建立通信连接。
在本公开实施例中,客户端200可以为移动终端设备,例如,智能手机、平板电脑、穿戴式移动终端、个人数字助理(personal digital assistant,PDA)、PC(personal computer)电脑、智能电视、机顶盒、车载终端、移动上网设备(mobile Internet device,MID)等。在本实施例中,客户端200中安装有应用程序(APP),与服务端100相对应,为用户提供服务。用户可通过客户端200中安装的应用程序访问服务端100。
作为一种实施方式,所述应用程序可以为浏览器,所述服务端100可以为web服务器。
如图2所示,是本公开较佳实施例提供的一种服务端100的方框示意图。所述服务端100包括校验装置110、存储器120、一个或多个处理器130(图2中仅示出一个)及通信单元140。
所述存储器120、处理器130及通信单元140各元件相互之间接或间接地电性连接,以实现数据的传输或交互。例如,这些元件相互之间可通过一条或多条通讯总线或信号线实现电性连接。所述校验装置110包括至少一个可以软件或固件(firmware)形式存储于存储器120中或固化在客户端200的操作系统(operating system,OS)中的软件功能模块。
在本实施例中,所述存储器120可以是,但不限于,随机存取存储器(Random Access Memory,RAM),只读存储器(Read Only Memory,ROM),可编程只读存储器(Programmable Read-Only Memory,PROM),可擦除只读存储器(Erasable Programmable Read-Only Memory,EPROM),电可擦除只读存储器(Electric Erasable Programmable Read-Only Memory,EEPROM)等。
所述处理器130可以是一种集成电路芯片,具有信号的处理能力。上述的处理器可以是通用处理器,包括中央处理器(Central Processing Unit,CPU)、网络处理器(Network Processor,NP)等;还可以是数字信号处理器(DSP))、专用集成电路(ASIC)、现场可编程门阵列(FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。可以实现或者执行本公开实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。所述通信单元140配置成通过网络300建立服务端100与客户端200之间的通信连接。
应当理解,图2所示的结构仅为示意。服务端100还可以包括比图2所示更多或者更少的组件,或者具有与图2所示不同的配置。在本实施例中,图2所示的各组件可以软件、硬件或其组合实现。
如图3所示,是本公开实施例提供的一种应用于图2所示服务端100的校验方法的流 程示意图。下面将对图3所示流程及具体步骤进行详细阐述。所述方法可以包括步骤S101、步骤S102、步骤S103以及步骤S104。
步骤S101,在客户端200发送的登录请求验证通过后,根据所述登录请求生成校验信息。
本公开提供的校验方法用于对客户端200发送的登录请求验证通过后发起的网络请求进行验证。
实施时,用户可在客户端200输入用户信息(如,用户名和用户密码)并确认登录后,客户端200发送包括所述用户信息的登录请求至服务端100。服务端100接收到所述登录请求并验证所述登录请求中携带的用户信息,当验证通过时确认该用户登录成功。此时,服务端100记录登录请求中携带的用户信息,并生成一校验信息及将所述校验信息返回至客户端200,使得所述客户端200下次可通过携带有所述校验信息的网络请求来访问所述服务端100。如此,服务端100可通过所述校验信息来校验接收到的网络请求。
需要说明的是,本实施例中,所述登录请求可以是该用户首次通过客户端200登录时发出的登录请求,也可以是服务端100中记录的用户信息过期后,用户首次通过客户端200登录时发出的登录请求。
在本实施例中,所述服务端100包括可供客户端200登录的登录接口。所述登录接口配置成接收客户端200发送的登录请求进行验证,并在验证通过时,生成所述校验信息及将所述校验信息发送至所述客户端200。
可选地,所述校验信息可以有多种。例如,所述校验信息可以包括令牌(token)。在这一情形下,如图4所示,步骤S101可以包括步骤S201、步骤S202以及步骤S203三个子步骤。
步骤S201,在客户端200发送的登录请求验证通过后,生成一个会话(session)。
在本实施例中,所述会话通过express-session生成,所述会话具有一会话ID(sessionid)。
步骤S202,将所述登录请求中携带的用户信息与所述会话的会话ID关联,并将关联后的所述用户信息与会话ID进行存储。
在本实施例中,所述服务端100可以通过nodejs技术与非关系型数据库redis配合搭建而成,所述服务端100可通过所述非关系型数据库redis缓存和查询数据。
因而,可选地,在本实施例中,步骤S202可通过如下步骤实现。
以所述会话ID为键,以所述登录请求中携带的用户信息为值,形成一键-值对,并将所述键-值对存放至所述非关系型数据库redis中。
步骤S203,根据所述会话ID与所述登录请求中携带的第一参数信息生成所述令牌。
在本实施例中,所述第一参数信息可以包括,但不限于,用户访问IP、应用程序信息 等。所述用户访问IP可以为所述客户端的IP地址。所述应用程序信息可以为浏览器信息。作为一种实施方式,服务端100可以采用JWT(Json Web Tokens)方式生成所述令牌。可选地,服务端100可以将所述第一参数信息作为createtoken方法的参数,利用JWT临时令牌生成算法生成所述令牌。相较于传统的时效性token,本公开提供的校验方法安全性更高,附加操作更少。
可选地,所述会话ID也可直接作为所述校验信息,此时,所述校验信息包括所述令牌及所述会话ID。
步骤S102,将所述校验信息发送至所述客户端200。
在本实施例中,针对不同的校验信息,服务端100的发送方式有所不同。
例如,针对所述令牌,所述服务端100可直接将所述令牌返回至所述客户端200。又例如,针对所述会话ID,所述服务端100可在所述登录请求验证通过后,生成一个cookie信息,并将所述会话ID存放至所述cookie信息。所述服务端100将所述cookie信息发送至所述客户端200,使所述客户端200将所述cookie信息中的会话ID存放至网络请求中。
在本实施例中,所述cookie信息中包括所述cookie信息的有效期限。所述cookie信息的有效期限为与所述会话ID关联的用户信息的有效期限。如此,当所述用户信息过期时,所述cookie信息也会过期,客户端200也就无法实现提取出所述会话ID并存放至网络请求中,换言之,服务端100将无法从接收到的网络请求中检测到该会话ID。
步骤S103,接收所述客户端200发送的携带有所述校验信息的网络请求。
在本实施例中,所述校验方法用于对客户端200在所述登录请求验证通过后发送的所有网络请求进行校验。因而,服务端100接收到的网络请求,是指,所述客户端200在所述登录请求验证通过后发送的所有网络请求。并且,每个所述网络请求中携带有所述校验信息。
在本实施例中,网络请求可以是HTTP请求,HTTP请求头中的信息会在每个HTTP请求中自动发送至服务端100。因而,若所述校验信息包括所述令牌,所述客户端200在接收到所述令牌后,将所述令牌插入所述HTTP请求的请求头中。如此,所述客户端200发出的每一个HTTP请求中都携带有所述令牌,而不必在每次发送HTTP请求时将所述令牌作为请求参数一并提交。
若所述校验信息包括所述会话ID,则所述客户端200在接收到所述cookie信息后将所述cookie信息中存放的所述会话ID作为所述HTTP请求的参数一并发送至所述服务端100。如此,当所述cookie信息过期时,所述HTTP请求中不存在所述会话ID。
步骤S104,根据接收到的网络请求中携带的校验信息对该网络请求进行校验,并在校验通过时调用该网络请求申明调用的接口。
在本实施例中,所述服务端100还包括多个可供客户端200访问的请求接口。客户端200发送至服务端100的网络请求中通常申明有要访问的请求接口,若该请求接口为需要对已成功登录的用户的身份进行校验的接口,则可在该请求接口的回调指令之前,根据接收到的网络请求中携带的校验信息对该网络请求进行校验。当校验通过时,再执行该请求接口中的回调指令。
若该请求接口为不需要对已成功登录的用户的身份进行校验的接口,则可以直接执行该请求接口中的回调指令。
如此,所有类型的接口都可通过本公开提供的校验方法对已登录用户的身份进行校验,而不必根据请求接口的类型调整前端架构,大大降低了前端开发的工作量。
在本实施例中,由于所述校验信息可以有多种,对应的校验方式也可以有多种。作为一种实施方式,若所述校验信息包括令牌,步骤S104可通过如下步骤实现。
首先,解析接收到的网络请求中携带的所述令牌,得到所述会话ID及所述第一参数信息。
对于客户端200在用户登录成功后发送的每一个网络请求,服务端100从该网络请求的请求头中查找出所述令牌进行解析。解析所述令牌的方法与生成所述令牌的方法相匹配,例如,若所述令牌采用JWT加密算法生成,也应当采用对应的JWT解密算法进行解密。由于所述令牌根据所述会话ID及所述第一参数信息生成,因而,解析所述令牌也会得到所述会话ID及所述第一参数信息。
然后,查找出与所述会话ID关联的用户信息,并在查找出的所述用户信息未过期时确定所述网络请求校验通过,和/或者,获取所述网络请求中携带的第二参数信息,判断所述第二参数信息与解析得到的第一参数信息是否相同,并在所述第二参数信息与所述第一参数信息相同时,确定所述网络请求校验通过。
根据实际情况,所述客户端200在所述登录请求验证通过后发送的网络请求中携带有与所述第一参数信息所包括的参数类型相同的第二参数信息。因而,在校验时,可根据所述令牌得到所述第一参数信息,进而将所述第一参数信息与所述第二参数信息进行对比,根据对比结果判断网络请求是否校验通过,从而实现对用户的身份进行校验。例如,所述第一参数信息中包括用户访问IP和浏览器信息。所述用户访问IP可以为所述客户端的IP地址。第二参数信息中也包括当前用户的用户访问IP和浏览器信息。当前用户的用户访问IP可以为当前用户所在的客户端的IP地址。
此外,服务端100也可根据接收到的网络请求中携带的令牌得到所述会话ID,并通过所述会话ID在所述非关系型数据库redis中读取该用户登录时所用的用户信息,进而根据所述用户信息对所述网络请求进行校验。若读取到的用户信息未过期,则确定所述网络请 求校验通过,可响应所述网络请求。
在本实施例中,针对所述校验信息包括所述令牌的情形,所述服务端100可选取上述两种校验方式中的至少一种对接收到的网络请求进行校验。
可选地,作为另一种实施方式,若除所述令牌之外,所述校验信息还包括所述会话ID,则所述步骤S104可以通过如下步骤实现。
作为一种实施方式,步骤S104可以包括:
检测接收到的网络请求中是否携带有所述会话ID,若所述网络请求中携带有所述会话ID,则查找出与所述会话ID关联的用户信息,并在所述用户信息未过期时确定所述网络请求校验通过,调用该网络请求申明调用的接口。
可选地,若所述网络请求中携带有所述会话ID,则查找出与所述会话ID关联的用户信息,并在所述用户信息未过期时确定该网络请求校验通过,包括:
若所述网络请求中携带有所述会话ID,通过所述会话ID在所述非关系型数据库中读取该用户登录时所用的用户信息,若读取到的用户信息未过期,则确定所述网络请求校验通过。
在本实施例中,若cookie信息过期,则所述客户端200发送至所述服务端100的网络请求中不存在所述会话ID。
作为另一种实施方式,步骤S104可以包括:
检测接收到的网络请求中是否携带有所述会话ID,若所述网络请求中未携带所述会话ID,则解析所述网络请求中携带的令牌,得到所述会话ID及所述第一参数信息。
查找出与所述会话ID关联的用户信息,并在查找出的所述用户信息未过期时确定所述网络请求校验通过,和/或,获取所述网络请求中携带的第二参数信息,判断所述第二参数信息与解析得到的第一参数信息是否相同,并在所述第二参数信息与所述第一参数信息相同时确定所述网络请求校验通过,调用该网络请求申明调用的接口。
在本实施例中,当所述校验信息还包括所述会话ID时,所述服务端100可先检测接收到的网络请求中是否包括所述会话ID,在接收到的网络请求中不包括所述会话ID时,再通过所述令牌对所述用户的身份进行校验。
由此可见,相较于现有技术,本公开提供的校验方法不受服务端100提供的请求接口类型的限制,可根据实际需求灵活调整校验方式。
如图5所示,本公开较佳实施例还提供一种校验装置110,所述校验装置110应用于与客户端200通信的服务端100。所述校验装置110包括校验信息生成模块111、校验信息发送模块112、接收模块113以及校验模块114。
在本实施例中,所述校验信息生成模块111,配置成在客户端200发送的登录请求验证 通过后,根据所述登录请求生成校验信息。
在本实施例中,关于所述校验信息生成模块111的描述可参考对图3所示步骤S101的详细描述。也即,所述步骤S101可由所述校验信息生成模块111执行。
可选地,所述校验信息可包括令牌。在这一情形下,所述校验信息生成模块111可通过如下方式在用户通过客户端200登录成功后,根据所述客户端200请求该次登录的登录请求中所携带的信息生成校验信息。
在客户端200发送的登录请求验证通过后,生成一个会话。
将所述登录请求中携带的用户信息与所述会话的会话ID关联,并将关联后的所述用户信息与会话ID进行存储。
根据所述会话ID与所述登录请求中携带的第一参数信息生成所述令牌。
可选地,所述校验信息生成模块111将所述登录请求中携带的用户信息与所述会话的会话ID关联,并将关联后的所述用户信息与会话ID进行存储的方式包括:
以所述会话ID为键,以所述登录请求中携带的用户信息为值,形成一键-值对;
将所述键-值对存放至所述非关系型数据库。
可选地,所述校验信息生成模块111根据所述会话ID与所述登录请求中携带的第一参数信息生成所述令牌的方式包括:
将所述第一参数信息作为createtoken方法的参数,利用JWT临时令牌生成算法生成所述令牌。
所述校验信息发送模块112,配置成将所述校验信息发送至所述客户端200。在本实施例中,关于所述校验信息发送模块112的描述可参考对图3所示步骤S102的详细描述,也即,所述步骤S102可由所述校验信息发送模块112执行。
可选地,所述校验信息还包括所述会话ID,所述校验信息发送模块112将所述校验信息发送至所述客户端的方式包括:
生成一个cookie信息,并将所述会话ID存入所述cookie信息,所述cookie信息的有效期限为与所述会话ID关联的用户信息的有效期限;
将所述cookie信息发送至所述客户端,使所述客户端在所述cookie信息未过期时将所述cookie信息中的会话ID存放至网络请求中。
所述接收模块113,配置成接收所述客户端200发送的携带有所述校验信息的网络请求。
在本实施例中,关于所述接收模块113的描述可参考对图3所示步骤S103的详细描述,也即,所述步骤S103可由所述接收模块113执行。
所述校验模块114,配置成根据接收到的网络请求中携带的校验信息对该网络请求进行 校验,并在校验通过时调用该网络请求申明调用的接口。
在本实施例中,关于所述校验模块114的描述可参考对图3所示步骤S104的详细描述。也即,所述步骤S104可由所述校验模块114执行。
可选地,所述校验模块114可通过如下方式根据所述网络请求中携带的校验信息对所述网络请求的身份信息进行校验。
解析接收到的网络请求中携带的令牌,得到所述会话ID及所述第一参数信息。
查找出与所述会话ID关联的用户信息,并在查找出的所述用户信息未过期时确定所述网络请求校验通过,和/或,获取所述网络请求中携带的第二参数信息,判断所述第二参数信息与解析得到的第一参数信息是否相同,并在所述第二参数信息与所述第一参数信息相同时,确定所述网络请求校验通过。
可选地,所述校验模块114根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验的方式,包括:
检测接收到的网络请求中是否携带有所述会话ID;
若所述网络请求中携带有所述会话ID,则查找出与所述会话ID关联的用户信息,并在所述用户信息未过期时确定该网络请求校验通过。
可选地,所述校验模块114若检测到所述网络请求中携带有所述会话ID,则查找出与所述会话ID关联的用户信息,并在所述用户信息未过期时确定该网络请求校验通过的方式包括:
若所述网络请求中携带有所述会话ID,通过所述会话ID在所述非关系型数据库中读取该用户登录时所用的用户信息,若读取到的用户信息未过期,则确定所述网络请求校验通过。
可选地,所述校验模块114根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验的方式,包括:
检测接收到的网络请求中是否携带有所述会话ID;
若所述网络请求中未携带所述会话ID,则解析所述网络请求中携带的所述令牌,得到所述会话ID及所述第一参数信息;
查找出与所述会话ID关联的用户信息,并在查找出的所述用户信息未过期时确定所述网络请求校验通过,和/或,获取所述网络请求中携带的第二参数信息,判断所述第二参数信息与解析得到的第一参数信息是否相同,并在所述第二参数信息与所述第一参数信息相同时确定所述网络请求校验通过。
以上各模块可以是由软件代码实现,此时,上述的各模块可存储于存储器120内。以上各单元同样可以由硬件例如集成电路芯片实现。
本实施例提供的校验装置110,其实现原理及产生的技术效果和前述方法实施例相同,为简要描述,装置实施例部分未提及之处,可参考前述方法实施例中相应内容。
本领域普通技术人员可以理解上述实施例的各种方法中的全部或部分步骤是可以通过程序来指令相关的硬件来完成,该程序可以存储于一计算机可读存储介质中,存储介质可以包括:只读存储器(ROM,Read Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁盘或光盘等。综上所述,本公开实施例提供的校验方法、装置、服务端及可读存储介质,配置成校验客户端200在用户登录成功后发起的网络请求,进而实现对该用户的身份校验。服务端100在用户通过客户端200登录成功后,根据登录请求中携带的信息生成校验信息发送至客户端200。服务端100接收客户端200在用户登录成功后发送的携带有该校验信息的网络请求,并在网络请求所访问的请求接口回调之前,根据网络请求中携带的该校验信息对用户的身份进行校验。如此,只需在需要进行校验的请求接口中应用本公开提供的校验方法及装置,不必根据接口的类型对前端进行调整,大大降低了开发人员的工作量,提高了开发效率。
在本公开所提供的几个实施例中,应该理解到,所揭露的装置和方法,也可以通过其它的方式实现。以上所描述的装置实施例仅仅是示意性的,例如,附图中的流程图和框图显示了根据本公开的多个实施例的装置、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段或代码的一部分,所述模块、程序段或代码的一部分包含一个或多个配置成实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现方式中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个连续的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或动作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。
另外,在本公开各个实施例中的各功能模块可以集成在一起形成一个独立的部分,也可以是各个模块单独存在,也可以两个或两个以上模块集成形成一个独立的部分。
所述功能如果以软件功能模块的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本公开的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本公开各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的 介质。
需要说明的是,在本公开中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。
以上所述仅为本公开的优选实施例而已,并不用于限制本公开,对于本领域的技术人员来说,本公开可以有各种更改和变化。凡在本公开的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本公开的保护范围之内。
工业实用性
本公开实施例能够不受服务端提供的请求接口类型的限制,可根据实际需求灵活调整校验方式,即只需针对需要进行校验的请求接口应用本实施例提供的校验方法及装置。大大降低了开发人员的工作量,提高了开发效率。

Claims (20)

  1. 一种校验方法,其特征在于,应用于与客户端通信的服务端,所述方法包括:
    在客户端发送的登录请求验证通过后,根据所述登录请求生成校验信息;
    将所述校验信息发送至所述客户端;
    接收所述客户端发送的携带有所述校验信息的网络请求;
    根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验,并在校验通过时调用该网络请求申明调用的接口。
  2. 根据权利要求1所述的校验方法,其特征在于,在客户端发送的登录请求验证通过后,根据所述登录请求生成校验信息,包括:
    在客户端发送的登录请求验证通过后,生成一个会话;
    将所述登录请求中携带的用户信息与所述会话的会话ID关联,并将关联后的所述用户信息与会话ID进行存储;
    根据所述会话ID与所述登录请求中携带的第一参数信息生成令牌,所述校验信息包括所述令牌。
  3. 根据权利要求2所述的校验方法,其特征在于,所述服务端中存储有非关系型数据库;将所述登录请求中携带的用户信息与所述会话的会话ID关联,并将关联后的所述用户信息与会话ID进行存储,包括:
    以所述会话ID为键,以所述登录请求中携带的用户信息为值,形成一键-值对;
    将所述键-值对存放至所述非关系型数据库。
  4. 根据权利要求2所述的校验方法,其特征在于,根据所述会话ID与所述登录请求中携带的第一参数信息生成令牌,包括:
    将所述第一参数信息作为createtoken方法的参数,利用JWT临时令牌生成算法生成所述令牌。
  5. 根据权利要求3所述的校验方法,其特征在于,根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验,包括:
    解析接收到的网络请求中携带的所述令牌,得到所述会话ID及所述第一参数信息;
    查找出与所述会话ID关联的用户信息,并在查找出的所述用户信息未过期时确定所述网络请求校验通过,和/或,获取所述网络请求中携带的第二参数信息,判断所述第二参数信息与解析得到的第一参数信息是否相同,并在所述第二参数信息与所述第一参数信息相同时,确定所述网络请求校验通过。
  6. 根据权利要求3-5任一项所述的校验方法,其特征在于,所述校验信息还包括所 述会话ID;将所述校验信息发送至所述客户端,包括:
    生成一个cookie信息,并将所述会话ID存入所述cookie信息,所述cookie信息的有效期限为与所述会话ID关联的用户信息的有效期限;
    将所述cookie信息发送至所述客户端,使所述客户端在所述cookie信息未过期时将所述cookie信息中的会话ID存放至网络请求中。
  7. 根据权利要求6所述的校验方法,其特征在于,根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验,包括:
    检测接收到的网络请求中是否携带有所述会话ID;
    若所述网络请求中携带有所述会话ID,则查找出与所述会话ID关联的用户信息,并在所述用户信息未过期时确定该网络请求校验通过。
  8. 根据权利要求7所述的校验方法,其特征在于,若所述网络请求中携带有所述会话ID,则查找出与所述会话ID关联的用户信息,并在所述用户信息未过期时确定该网络请求校验通过,包括:
    若所述网络请求中携带有所述会话ID,通过所述会话ID在所述非关系型数据库中读取该用户登录时所用的用户信息,若读取到的用户信息未过期,则确定所述网络请求校验通过。
  9. 根据权利要求2-4任一项所述的校验方法,其特征在于,根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验,包括:
    检测接收到的网络请求中是否携带有所述会话ID;
    若所述网络请求中未携带所述会话ID,则解析所述网络请求中携带的所述令牌,得到所述会话ID及所述第一参数信息;
    查找出与所述会话ID关联的用户信息,并在查找出的所述用户信息未过期时确定所述网络请求校验通过,和/或,获取所述网络请求中携带的第二参数信息,判断所述第二参数信息与解析得到的第一参数信息是否相同,并在所述第二参数信息与所述第一参数信息相同时确定所述网络请求校验通过。
  10. 一种校验装置,其特征在于,应用于与客户端通信的服务端,所述装置包括:
    校验信息生成模块,配置成在客户端发送的登录请求验证通过后,根据所述登录请求生成校验信息;
    校验信息发送模块,配置成将所述校验信息发送至所述客户端;
    接收模块,配置成接收所述客户端发送的携带有所述校验信息的网络请求;
    校验模块,配置成根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验,并在校验通过时调用该网络请求申明调用的接口。
  11. 根据权利要求10所述的校验装置,其特征在于,所述校验信息包括令牌;所述校验信息生成模块在客户端发送的登录请求验证通过后,根据所述登录请求生成校验信息的方式,包括:
    在客户端发送的登录请求验证通过后,生成一个会话;
    将所述登录请求中携带的用户信息与所述会话的会话ID关联,并将关联后的所述用户信息与会话ID进行存储;
    根据所述会话ID与所述登录请求中携带的第一参数信息生成所述令牌。
  12. 根据权利要求11所述的校验装置,其特征在于,所述服务端中存储有非关系型数据库,所述校验信息生成模块将所述登录请求中携带的用户信息与所述会话的会话ID关联,并将关联后的所述用户信息与会话ID进行存储的方式包括:
    以所述会话ID为键,以所述登录请求中携带的用户信息为值,形成一键-值对;
    将所述键-值对存放至所述非关系型数据库。
  13. 根据权利要求11所述的校验装置,其特征在于,所述校验信息生成模块根据所述会话ID与所述登录请求中携带的第一参数信息生成所述令牌的方式包括:
    将所述第一参数信息作为createtoken方法的参数,利用JWT临时令牌生成算法生成所述令牌。
  14. 根据权利要求12所述的校验装置,其特征在于,所述校验模块根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验的方式,包括:
    解析接收到的网络请求中携带的所述令牌,得到所述会话ID及所述第一参数信息;
    查找出与所述会话ID关联的用户信息,并在查找出的所述用户信息未过期时确定所述网络请求校验通过,和/或,获取所述网络请求中携带的第二参数信息,判断所述第二参数信息与解析得到的第一参数信息是否相同,并在所述第二参数信息与所述第一参数信息相同时,确定所述网络请求校验通过。
  15. 根据权利要求12-14任一项所述的校验装置,其特征在于,所述校验信息还包括所述会话ID,所述校验信息发送模块将所述校验信息发送至所述客户端的方式包括:
    生成一个cookie信息,并将所述会话ID存入所述cookie信息,所述cookie信息的有效期限为与所述会话ID关联的用户信息的有效期限;
    将所述cookie信息发送至所述客户端,使所述客户端在所述cookie信息未过期时将所述cookie信息中的会话ID存放至网络请求中。
  16. 根据权利要求15所述的校验装置,其特征在于,所述校验模块根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验的方式,包括:
    检测接收到的网络请求中是否携带有所述会话ID;
    若所述网络请求中携带有所述会话ID,则查找出与所述会话ID关联的用户信息,并在所述用户信息未过期时确定该网络请求校验通过。
  17. 根据权利要求16所述的校验装置,其特征在于,所述校验模块若检测到所述网络请求中携带有所述会话ID,则查找出与所述会话ID关联的用户信息,并在所述用户信息未过期时确定该网络请求校验通过的方式包括:
    若所述网络请求中携带有所述会话ID,通过所述会话ID在所述非关系型数据库中读取该用户登录时所用的用户信息,若读取到的用户信息未过期,则确定所述网络请求校验通过。
  18. 根据权利要求11-13任一项所述的校验装置,其特征在于,所述校验模块根据接收到的网络请求中携带的所述校验信息对该网络请求进行校验的方式,包括:
    检测接收到的网络请求中是否携带有所述会话ID;
    若所述网络请求中未携带所述会话ID,则解析所述网络请求中携带的所述令牌,得到所述会话ID及所述第一参数信息;
    查找出与所述会话ID关联的用户信息,并在查找出的所述用户信息未过期时确定所述网络请求校验通过,和/或,获取所述网络请求中携带的第二参数信息,判断所述第二参数信息与解析得到的第一参数信息是否相同,并在所述第二参数信息与所述第一参数信息相同时确定所述网络请求校验通过。
  19. 一种服务端,包括处理器以及存储有若干计算机指令的非易失性存储器,其特征在于,所述计算机指令被所述处理器执行时,所述服务端执行权利要求1-9中任意一项所述的校验方法。
  20. 一种可读存储介质,其特征在于,所述可读存储介质包括计算机程序,所述计算机程序运行时控制所述可读存储介质所在服务端执行权利要求1-9中任意一项所述的校验方法。
PCT/CN2018/082350 2017-06-12 2018-04-09 校验方法、装置、服务端及可读存储介质 WO2018228036A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201710439302.2A CN107196950B (zh) 2017-06-12 2017-06-12 校验方法、装置及服务端
CN201710439302.2 2017-06-12

Publications (1)

Publication Number Publication Date
WO2018228036A1 true WO2018228036A1 (zh) 2018-12-20

Family

ID=59876460

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/082350 WO2018228036A1 (zh) 2017-06-12 2018-04-09 校验方法、装置、服务端及可读存储介质

Country Status (2)

Country Link
CN (1) CN107196950B (zh)
WO (1) WO2018228036A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110535851A (zh) * 2019-08-27 2019-12-03 浪潮云信息技术有限公司 一种基于oauth2协议的用户认证系统
CN111314362A (zh) * 2020-02-23 2020-06-19 湖南警察学院 一种银行安保系统的网络安全验证方法及系统

Families Citing this family (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107196950B (zh) * 2017-06-12 2020-06-16 武汉斗鱼网络科技有限公司 校验方法、装置及服务端
CN109756337B (zh) * 2017-11-06 2022-01-07 北京京东尚科信息技术有限公司 一种服务接口的安全接入方法和装置
CN108462581B (zh) * 2018-01-08 2020-09-04 平安科技(深圳)有限公司 网络令牌生成的方法、装置、终端设备及存储介质
CN108900557B (zh) * 2018-09-12 2023-09-22 国际商业机器(中国)投资有限公司 登录方法及系统
CN110718219B (zh) 2019-09-12 2022-07-22 百度在线网络技术(北京)有限公司 一种语音处理方法、装置、设备和计算机存储介质
CN110718218B (zh) * 2019-09-12 2022-08-23 百度在线网络技术(北京)有限公司 一种语音处理方法、装置、设备和计算机存储介质
CN110719285A (zh) * 2019-10-11 2020-01-21 永诚恒易网络科技股份有限公司 一种基于http协议的token的封装方法
CN111132076B (zh) * 2019-12-31 2024-04-09 斑马网络技术有限公司 车机通信方法、装置、车机及终端
CN111404804A (zh) * 2020-03-10 2020-07-10 安徽以萨数据技术有限公司 基于Swoole的即时通讯系统、方法、终端及介质
CN112363935A (zh) * 2020-11-11 2021-02-12 平安普惠企业管理有限公司 数据联调方法、装置、电子设备及存储介质
CN114615459A (zh) * 2022-05-10 2022-06-10 全时云商务服务股份有限公司 一种视频会议入会方法及装置

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106302346A (zh) * 2015-05-27 2017-01-04 阿里巴巴集团控股有限公司 Api调用的安全认证方法、装置、系统
CN106453661A (zh) * 2016-12-09 2017-02-22 北京酷我科技有限公司 一种http服务器集群的会话管理方法
CN107196950A (zh) * 2017-06-12 2017-09-22 武汉斗鱼网络科技有限公司 校验方法、装置及服务端

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7225464B2 (en) * 2002-04-03 2007-05-29 Yodlee.Com, Inc. Method for verifying the identity of a user for session authentication purposes during Web navigation
CN103944900B (zh) * 2014-04-18 2017-11-24 中国科学院计算技术研究所 一种基于加密的跨站请求攻击防范方法及其装置

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106302346A (zh) * 2015-05-27 2017-01-04 阿里巴巴集团控股有限公司 Api调用的安全认证方法、装置、系统
CN106453661A (zh) * 2016-12-09 2017-02-22 北京酷我科技有限公司 一种http服务器集群的会话管理方法
CN107196950A (zh) * 2017-06-12 2017-09-22 武汉斗鱼网络科技有限公司 校验方法、装置及服务端

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110535851A (zh) * 2019-08-27 2019-12-03 浪潮云信息技术有限公司 一种基于oauth2协议的用户认证系统
CN111314362A (zh) * 2020-02-23 2020-06-19 湖南警察学院 一种银行安保系统的网络安全验证方法及系统

Also Published As

Publication number Publication date
CN107196950A (zh) 2017-09-22
CN107196950B (zh) 2020-06-16

Similar Documents

Publication Publication Date Title
WO2018228036A1 (zh) 校验方法、装置、服务端及可读存储介质
US11588639B2 (en) System and method for a token gateway environment
US11431501B2 (en) Coordinating access authorization across multiple systems at different mutual trust levels
US8898764B2 (en) Authenticating user through web extension using token based authentication scheme
US10581827B2 (en) Using application level authentication for network login
CN111556006B (zh) 第三方应用系统登录方法、装置、终端及sso服务平台
WO2016188290A1 (zh) Api调用的安全认证方法、装置、系统
US10917397B2 (en) Establishing a trusted login procedure
KR101850677B1 (ko) 웹사이트에 로그인하는 단말기가 모바일 단말기인지를 결정하기 위한 방법 및 시스템
TWI587672B (zh) Login authentication method, client, server and system
WO2018036314A1 (zh) 一种单点登录认证方法及装置、存储介质
US11863677B2 (en) Security token validation
US20180205745A1 (en) System, method and computer program product for access authentication
US12003505B2 (en) Custom authorization of network connected devices using signed credentials
US8959335B2 (en) Secure password-based authentication for cloud computing services
WO2016101635A1 (zh) 一种同步登录状态的方法、装置、设备和计算机存储介质
US10630574B2 (en) Link processing method, apparatus, and system
WO2015196908A1 (zh) 业务处理方法、终端、服务器及系统
WO2015143855A1 (zh) 一种对数据资源进行访问的方法、装置和系统
US9590972B2 (en) Application authentication using network authentication information
KR20220019834A (ko) 디바이스로의 보안 자격증명 전송을 인증하는 방법 및 시스템
CN109842616B (zh) 账号绑定方法、装置及服务器
US10484369B2 (en) Voice authentication via secondary device
US20220394039A1 (en) Seamlessly securing access to application programming interface gateways
CN113225348B (zh) 请求防重放校验方法和装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18817996

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 18817996

Country of ref document: EP

Kind code of ref document: A1