Method and system for non-inductively refreshing access token, terminal and storage medium

By monitoring the validity period and request interval of the access token and refreshing the access token in advance, the lag problem in refreshing the access token in the existing technology is solved, and the user experience and system stability are improved.

CN119341829APending Publication Date: 2025-01-21SHANDONG ARTAPLAY INTELLIGENT TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411522933.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-29
Publication Date
2025-01-21

AI Technical Summary

Technical Problem

The prior art has lag when refreshing the access token, resulting in the request being in a waiting state and cannot be processed in a timely manner, affecting the user experience.

Method used

By monitoring the remaining validity period and request interval time of the token, determine whether to refresh the access token in advance to avoid request waiting. Specific steps include the target server and the previous request time to obtain the request to be sent. Calculate the request interval time. If the interval time exceeds the threshold or the validity period of the token is lower than the threshold, the token refresh request is sent.

Benefits of technology

Realize the inductive refresh access token, avoid the request for a long time, improve the user experience, and enhance the robustness and security of the front end.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119341829A_ABST
    Figure CN119341829A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of application programs, and particularly provides a non-inductive access token refreshing method and system, a terminal and a storage medium, and the method comprises the steps: obtaining a target server side of a to-be-sent request, and obtaining the previous request time of the target server side; calculating the interval time of the requests based on the previous request time and the current moment, and judging whether the to-be-sent request and the previous request belong to the same service based on whether the interval time exceeds a set time threshold; if the to-be-sent request and the previous request belong to the same service, obtaining a residual validity period of an access token, and if the residual validity period is lower than the time threshold, sending a token refreshing request to a target server; if the to-be-sent request and the previous request do not belong to the same service, the access token refreshing service is not supported. The mode of refreshing the access token in advance is adopted, long-time waiting of the request is avoided, and the user experience is further improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of application programs, and in particular relates to a method, system, terminal and storage medium for refreshing access tokens without any sense of touch. Background Art

[0002] In front-end projects, in order to maintain the continuity of user sessions and the smoothness of user experience, it is necessary to rely on Tokens to verify user identities and authorize access. However, due to its design characteristics, Tokens have a validity period limit. Once expired, users will no longer be able to enjoy certain features of the service.

[0003] In order to avoid user service interruption, some front-ends currently use token refresh technology. For example, after receiving the prompt that the access token is invalid returned by the server, the client applies for a new access token from the server.

[0004] This method has a lag. During the application of a new access token, the request is in a waiting state and cannot be processed. How to shorten or eliminate the waiting time is the key to improving user experience. Summary of the invention

[0005] In view of the above-mentioned deficiencies in the prior art, the present invention provides a method, system, terminal and storage medium for refreshing access tokens without any sense, so as to solve the above-mentioned technical problems.

[0006] In a first aspect, the present invention provides a method for refreshing an access token without any sense of touch, comprising: Get the target server to which the request is to be sent, and get the last request time of the target server; Calculate the interval time of the request based on the previous request time and the current time, and determine whether the request to be sent and the previous request belong to the same service based on whether the interval time exceeds a set time threshold; If the request to be sent and the previous request belong to the same service, the remaining validity period of the access token is obtained, and if the remaining validity period is lower than the time threshold, a token refresh request is sent to the target server; If the request to be sent does not belong to the same service as the previous request, the access token refresh service is not supported.

[0007] In an optional implementation, obtaining a target server to which a request is to be sent and obtaining a previous request time of the target server include: Intercepting the request to be sent, and extracting the target server from the request to be sent; Calling the access token to execute the request to be sent, and if the access token is invalid, caching the request to be sent to a task queue; The access record to the target server is obtained from the historical access record, and the last request time closest to the current time is extracted from the access record.

[0008] In an optional implementation, calculating the request interval time based on the previous request time and the current time, and judging whether the request to be sent and the previous request belong to the same service based on whether the interval time exceeds a set time threshold, includes: Calculate the time difference between the current time and the last request time, and record the time difference as the interval time; Determine whether the interval time exceeds the time threshold: If yes, it is determined that the request to be sent and the previous request do not belong to the same service; If not, it is determined that the request to be sent and the previous request belong to the same service.

[0009] In an optional implementation, the method for setting the time threshold includes: Collect historical access records, and extract the server address and access time from the access data in the historical access records; Sort the server addresses by access time to get the access sequence; Dividing the access sequence into a plurality of sequence segments, each of which contains only one server address; The access time differences of adjacent elements of each sequence segment are counted, and the maximum access time difference is screened out, and the maximum access time difference is set as the time threshold.

[0010] In an optional implementation, if the request to be sent and the previous request belong to the same service, the remaining validity period of the access token is obtained, and if the remaining validity period is less than the request interval, a token refresh request is sent to the target server while processing the request to be sent, including: Obtaining the storage time of the access token and the validity period of the access token, and calculating the remaining validity period based on the validity period and the storage time; If the remaining validity period is a negative number, confirm that the access token is invalid, generate a token refresh request using a pre-stored verification token, send the token refresh request to the target server to obtain a new access token, and execute the request to be sent based on the new access token; If the remaining validity period is a positive number and the remaining validity period is not less than the time threshold, executing the request to be sent based on the access token; If the remaining validity period is a positive number and the remaining validity period is lower than the time threshold, a token refresh request is generated using a pre-stored verification token to obtain a new access token of the target server based on the token refresh request.

[0011] In an optional embodiment, the method further comprises: The server receives the token refresh request and extracts a verification token from the token refresh request, where the verification token is a hash value of the user account; Pre-save the hash value of the user account to the verification list, and determine whether there is a hash value consistent with the verification token in the verification list: If yes, a new access token is generated and returned to the client that sent the token refresh request; If not, a prompt message indicating that the token refresh failed is returned.

[0012] In an optional implementation, if the request to be sent does not belong to the same service as the previous request, the access token refresh service is not supported, including: Extract the to-be-executed tasks from the task queue, and jump to the login interface based on the to-be-executed tasks.

[0013] In a second aspect, the present invention provides a system for refreshing access tokens without any sense of touch, comprising: The request monitoring module is used to obtain the target server of the request to be sent and obtain the last request time of the target server; An association analysis module, used to calculate the interval time of the request based on the previous request time and the current time, and determine whether the request to be sent and the previous request belong to the same service based on whether the interval time exceeds a set time threshold; A token refresh module, configured to obtain the remaining validity period of the access token if the request to be sent and the previous request belong to the same service, and to send a token refresh request to the target server if the remaining validity period is lower than the time threshold; The login jump module is used to not support the access token refresh service if the request to be sent does not belong to the same business as the previous request.

[0014] In a third aspect, a terminal is provided, including: A memory for storing a program for refreshing the access token without any sense of touch; A processor is used to implement the steps of the method for seamlessly refreshing an access token as provided in the first aspect when executing the program for seamlessly refreshing an access token.

[0015] In a fourth aspect, a computer-readable storage medium is provided, on which a program for seamlessly refreshing an access token is stored. When the program for seamlessly refreshing an access token is executed by a processor, the steps of the method for seamlessly refreshing an access token provided in the first aspect are implemented.

[0016] The beneficial effect of the present invention lies in that the method, system, terminal and storage medium for seamlessly refreshing access tokens provided by the present invention monitor the remaining validity period of the access token and the request interval time, and then determine whether the access token needs to be refreshed in advance based on the request interval time and the remaining validity period. This method of refreshing the access token in advance will not cause a long waiting time for the request, further improving the user experience.

[0017] In addition, the invention has a reliable design principle, a simple structure and a very broad application prospect. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0019] Figure 1 is a schematic flow chart of a method according to an embodiment of the present invention.

[0020] Figure 2 is a schematic block diagram of a system according to an embodiment of the present invention.

[0021] Figure 3 A schematic diagram of the structure of a terminal provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0022] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0023] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.

[0024] The method for seamlessly refreshing access tokens provided in the embodiment of the present invention is executed by a computer device, and accordingly, the system for seamlessly refreshing access tokens runs in the computer device.

[0025] Figure 1 is a schematic flow chart of a method according to an embodiment of the present invention. Figure 1The execution subject may be a system for refreshing access tokens without any sense. According to different requirements, the order of the steps in the flowchart may be changed, and some may be omitted.

[0026] like Figure 1 As shown, the method includes: S1, obtain the target server of the request to be sent, and obtain the last request time of the target server; S2, calculating the interval time of the request based on the previous request time and the current time, and judging whether the request to be sent and the previous request belong to the same service based on whether the interval time exceeds a set time threshold; S3: if the request to be sent and the previous request belong to the same service, obtain the remaining validity period of the access token, and if the remaining validity period is lower than the time threshold, send a token refresh request to the target server; S4: If the request to be sent and the previous request do not belong to the same service, the access token refresh service is not supported.

[0027] To facilitate understanding of the present invention, the method for seamlessly refreshing an access token provided by the present invention is further described below based on the principle of the method for seamlessly refreshing an access token of the present invention and in combination with the process of seamlessly refreshing an access token in an embodiment.

[0028] In this embodiment, the specific implementation method of step S1 includes: S101, intercepting a request to be sent, and extracting a target server from the request to be sent.

[0029] Use the hook functions provided by some HTTP libraries. For example, when using the requests library to send a request, you can write a wrapper function to intercept the request.

[0030] S102: Obtain access records to the target server from historical access records, and extract the last request time closest to the current time from the access records.

[0031] Extract the target server (i.e. the requested URL) from the intercepted request. The front end uses a database (such as SQLite) to store historical access records, including the target server and request time. Query the target server's history from the database and find the most recent request time.

[0032] In one embodiment of the present invention, after executing S101, the access token is directly retrieved. If the access token is valid, the access token is added to the request to be sent, and the request to be sent is sent to the server. If the access token is not required, the request to be sent is cached in the task queue, and subsequent steps are executed.

[0033] In this way, the request processing and the token refresh judgment and prediction process are executed concurrently without interfering with each other.

[0034] In this embodiment, the specific implementation process of step S2 includes: Calculate the time difference between the current moment and the previous request time, and record the time difference as the interval time; determine whether the interval time exceeds the time threshold: if so, determine that the request to be sent and the previous request do not belong to the same service; if not, determine that the request to be sent and the previous request belong to the same service.

[0035] The time threshold setting is extremely important. If it is set too short, user services will be interrupted. If it is set too long, the access token may be stolen, which will affect data security.

[0036] In this implementation, the time threshold is set as follows: (1) Collect historical access records and extract the server address and access time from the access data in the historical access records.

[0037] Read historical access records from the log file, or query records from the database. Ensure that the records contain the server address and access timestamp. Verify the integrity of the data, such as checking whether the timestamp format is correct and whether the server address is a non-empty string.

[0038] Remove duplicate records. Correct or discard malformed records. Convert timestamps to a uniform time zone to avoid issues caused by time zone differences.

[0039] (2) Sort the server addresses in order of access time to obtain an access sequence.

[0040] Extract the server address and access timestamp from each record.

[0041] Store the extracted data in an easy to handle data structure such as a list or data frame.

[0042] Sort the extracted data by access timestamp.

[0043] If the timestamp has a high precision (for example, including milliseconds), consider whether you need to reduce the precision (for example, only retain it to seconds) to simplify subsequent processing.

[0044] (3) Divide the access sequence into multiple sequence segments, each of which contains only one server address.

[0045] Traverse the sorted access sequence. When a new server address is encountered, a new sequence segment begins.

[0046] Store each sequence segment in a list, where each sequence segment is also a list containing all access records of the server address.

[0047] (4) Counting the access time differences of adjacent elements of each sequence segment, and screening out the maximum access time difference, and setting the maximum access time difference as the time threshold.

[0048] For each sequence segment, calculate the time difference between adjacent access records. Record the maximum time difference in each sequence segment. Filter out the global maximum access time difference from the maximum time differences of all sequence segments. Set this maximum time difference as the time threshold for subsequent analysis or decision-making.

[0049] In a specific example, the implementation method of step S3 includes the following detailed steps: S301. Obtain the storage time of the access token and the validity period of the access token, and calculate the remaining validity period based on the validity period and the storage time.

[0050] Get token information: Retrieve the current access token and its issuance time (or save time) and expiration date from secure storage (such as a key management service, environment variables, or configuration files).

[0051] Calculate the remaining validity period: Use the current system time minus the issuance time (or storage time) of the token to calculate the used time, and then subtract the used time from the token's validity period to get the remaining validity period.

[0052] Logging: Records the token calculation process and results, including the current time, token issuance time, validity period, and remaining validity period.

[0053] Exception handling: If the token information cannot be obtained or an error occurs during the calculation process, record the error log and try to restore the token information from the backup source, or trigger the error handling process.

[0054] S302: If the remaining validity period is a negative number, confirm that the access token is invalid, generate a token refresh request using a pre-stored verification token, send the token refresh request to the target server to obtain a new access token, and execute the request to be sent based on the new access token.

[0055] Check the remaining validity period: If the remaining validity period is a negative number, the access token is invalid.

[0056] Generate refresh request: Generate a token refresh request using pre-stored verification tokens such as refresh token, client ID, and client secret.

[0057] Send refresh request: Send the token refresh request to the target server (such as the authentication server).

[0058] Process the response: Receive the response from the target server and check whether the new access token is successfully obtained. If successful, update the stored access token information; if failed, record the error log and try other recovery strategies (such as user re-login).

[0059] Execute request: Execute the pending request using the newly acquired access token.

[0060] Logging: Records the token refresh process and results, including refresh request time, new token information, request execution results, etc.

[0061] S303: If the remaining validity period is a positive number and the remaining validity period is not less than the time threshold, executing the request to be sent based on the access token.

[0062] Check the remaining validity period: If the remaining validity period is a positive number and is not less than the preset time threshold (such as 15 minutes), the access token is considered to be still valid.

[0063] Execute request: directly use the current access token to execute the request to be sent.

[0064] Logging: Records the request execution process and results, including request time, token information, response results, etc.

[0065] If the request to be sent has already been sent to the target server, this step is ignored.

[0066] S304: If the remaining validity period is a positive number and is lower than the time threshold, the request to be sent is executed based on the access token, and a token refresh request is generated using a pre-stored verification token to obtain a new access token of the target server based on the token refresh request.

[0067] Check the remaining validity period: If the remaining validity period is a positive number but is lower than the preset time threshold (such as 15 minutes), the access token is considered to be about to expire.

[0068] Asynchronous refresh token: Generate a token refresh request in the background (such as using an asynchronous task or thread) using the pre-stored verification token and send it to the target service to obtain a new access token.

[0069] Update token information: If the token refresh is successful, update the stored access token information.

[0070] Log Record: Record the token refresh process and results, including refresh request time, new token information, request execution results, etc. At the same time, record the request execution process and results.

[0071] Error handling: If token refresh fails, log the error and try other recovery strategies (such as prompting the user to log in again before the next request).

[0072] In a specific embodiment of the present invention, the method for refreshing the access token is as follows: The server receives a token refresh request and extracts a verification token from the token refresh request, where the verification token is a hash value of the user account; the hash value of the user account is saved in a verification list in advance, and a determination is made as to whether there is a hash value consistent with the verification token in the verification list: if so, a new access token is generated and returned to the client that sent the token refresh request; if not, a prompt message indicating that the token refresh failed is returned.

[0073] The following is a specific process for refreshing an access token, including: (1) The server receives a token refresh request Receive request: The server receives a token refresh request from the client.

[0074] Logging: Records key information such as the time when the token refresh request is received, the source of the request (such as the client IP address), and the content of the request.

[0075] (2) Extract the verification token from the token refresh request Parse the request: Parse the content of the token refresh request and extract the verification token field.

[0076] Verify token format: Checks whether the verification token format meets expectations (such as length, character set, etc.) to ensure its validity.

[0077] The verification token is the hash value of the user account Understanding verification tokens: It is clear that verification tokens are actually hash values ​​of user account information and are used to verify user identity.

[0078] (3) Pre-save the hash value of the user account to the verification list Load verification list: Load the hash value verification list of the user account from a secure storage (such as a database, memory cache, etc.).

[0079] Regular updates: Ensure that the verification list is regularly updated to include the latest user account hashes.

[0080] Determine whether there is a hash value consistent with the verification token in the verification list Hash value matching: Traverse the verification list and check whether there is a hash value that is exactly the same as the extracted verification token.

[0081] Logging: Records the results of hash value matching, including the time when the match succeeded or failed, verification token value, etc.

[0082] If yes, generate a new access token Generate a new token: If the hash value that matches the verification token exists in the verification list, a new access token is generated according to the security policy.

[0083] Set validity period: Set a suitable validity period for the new access token to ensure its security during use.

[0084] Logging: Records key information such as the generation time, token value, and validity period of the new access token.

[0085] The new access token is returned to the client that sent the token refresh request. Build response: Encapsulate the new access token in a response message, ready to be returned to the client.

[0086] Send Response: Sends a response message to the client that sent the token refresh request.

[0087] Logging: records key information such as the time when the response is sent, the client IP address, and the response content.

[0088] If not, a prompt message indicating that the token refresh failed is returned. Build a failure response: If the hash value that matches the verification token does not exist in the verification list, build a response message containing failure prompt information.

[0089] Send failure response: Send a failure response message to the client that sent the token refresh request.

[0090] Logging: Records key information such as the time when the token refresh failed, the client IP address, and the reason for the failure.

[0091] Security measures: When logging failure information, avoid logging sensitive information (such as the verification token itself) to prevent potential security risks.

[0092] Through specific examples, we can more fully understand the process of the server processing token refresh requests and ensure that the user identity can be correctly verified, a new access token can be generated, and failure prompt information can be returned when necessary. At the same time, the importance of logging and error handling is also emphasized to ensure the security and reliability of the entire process. At the same time, the hash value of the user account is used as the verification token, which not only improves the verification speed but also ensures data security.

[0093] For step S4, in a specific example, if the request to be sent and the previous request do not belong to the same service, the following method is used for processing: Prepare to jump to the login interface: According to the specific implementation of the application, prepare relevant parameters for jumping to the login interface, such as the redirection URL (used to redirect back to the current page after login), error prompt information, etc.

[0094] Execute redirection: redirect the user to the login interface, passing necessary parameters (such as redirection URL, error prompt, etc.). Before the redirection, the old token in the local storage can be cleared (to avoid potential token reuse risks).

[0095] Login interface processing: In the login interface, the user needs to enter credentials (such as username and password) to re-obtain the access token. After successful login, the application should re-execute the previous requests that failed due to token expiration (if necessary).

[0096] Logging and monitoring: Throughout the process, key log information is recorded, such as token acquisition attempts, token verification results, request sending results, and user login operations. Monitor these logs to detect potential security issues or performance bottlenecks.

[0097] Through these steps, you can have a more comprehensive understanding of how to handle the validity check of access tokens in your application and the process when the token expires. At the same time, the importance of error handling, logging, and monitoring is also emphasized.

[0098] Silent Token refresh not only improves the user experience, but also enhances the robustness and security of the front-end. By reducing user interruptions caused by token expiration, it helps the front-end provide a smoother and more seamless interactive experience.

[0099] In some embodiments, the system for refreshing access tokens without any sense of touch may include multiple functional modules composed of computer program segments. The computer programs of each program segment in the system for refreshing access tokens without any sense of touch may be stored in a memory of a computer device and executed by at least one processor to perform (see Figure 1 Description) The function of refreshing access tokens without any sense of touch.

[0100] In this embodiment, the system for refreshing access tokens without any sense of touch can be divided into multiple functional modules according to the functions it performs, such as Figure 2 As shown. The functional modules of the system 200 may include: a request monitoring module 210, an association analysis module 220, a token refresh module 230, and a login jump module 240. The module referred to in the present invention refers to a series of computer program segments that can be executed by at least one processor and can complete fixed functions, which are stored in a memory. In this embodiment, the functions of each module will be described in detail in subsequent embodiments.

[0101] The request monitoring module is used to obtain the target server of the request to be sent and obtain the last request time of the target server; An association analysis module, used to calculate the interval time of the request based on the previous request time and the current time, and determine whether the request to be sent and the previous request belong to the same service based on whether the interval time exceeds a set time threshold; A token refresh module, configured to obtain the remaining validity period of the access token if the request to be sent and the previous request belong to the same service, and to send a token refresh request to the target server if the remaining validity period is lower than the time threshold; The login jump module is used to not support the access token refresh service if the request to be sent does not belong to the same business as the previous request.

[0102] Optionally, as an embodiment of the present invention, obtaining a target server to which a request is to be sent and obtaining a previous request time of the target server include: Intercepting the request to be sent, and extracting the target server from the request to be sent; Calling the access token to execute the request to be sent, and if the access token is invalid, caching the request to be sent to a task queue; The access record to the target server is obtained from the historical access record, and the last request time closest to the current time is extracted from the access record.

[0103] Optionally, as an embodiment of the present invention, calculating the request interval time based on the previous request time and the current time, and judging whether the request to be sent and the previous request belong to the same service based on whether the interval time exceeds a set time threshold, includes: Calculate the time difference between the current time and the last request time, and record the time difference as the interval time; Determine whether the interval time exceeds the time threshold: If yes, it is determined that the request to be sent and the previous request do not belong to the same service; If not, it is determined that the request to be sent and the previous request belong to the same service.

[0104] Optionally, as an embodiment of the present invention, the method for setting the time threshold includes: Collect historical access records, and extract the server address and access time from the access data in the historical access records; Sort the server addresses by access time to get the access sequence; Dividing the access sequence into a plurality of sequence segments, each of which contains only one server address; The access time differences of adjacent elements of each sequence segment are counted, and the maximum access time difference is screened out, and the maximum access time difference is set as the time threshold.

[0105] Optionally, as an embodiment of the present invention, if the request to be sent and the previous request belong to the same service, the remaining validity period of the access token is obtained, and if the remaining validity period is less than the request interval, a token refresh request is sent to the target server while processing the request to be sent, including: Obtaining the storage time of the access token and the validity period of the access token, and calculating the remaining validity period based on the validity period and the storage time; If the remaining validity period is a negative number, confirm that the access token is invalid, generate a token refresh request using a pre-stored verification token, send the token refresh request to the target server to obtain a new access token, and execute the request to be sent based on the new access token; If the remaining validity period is a positive number and the remaining validity period is not less than the time threshold, executing the request to be sent based on the access token; If the remaining validity period is a positive number and the remaining validity period is lower than the time threshold, a token refresh request is generated using a pre-stored verification token to obtain a new access token of the target server based on the token refresh request.

[0106] Optionally, as an embodiment of the present invention, the method further includes: The server receives the token refresh request and extracts a verification token from the token refresh request, where the verification token is a hash value of the user account; Pre-save the hash value of the user account to the verification list, and determine whether there is a hash value consistent with the verification token in the verification list: If yes, a new access token is generated and returned to the client that sent the token refresh request; If not, a prompt message indicating that the token refresh failed is returned.

[0107] Optionally, as an embodiment of the present invention, if the request to be sent and the previous request do not belong to the same service, the access token refresh service is not supported, including: Extract the to-be-executed tasks from the task queue, and jump to the login interface based on the to-be-executed tasks.

[0108] Figure 3 The present invention provides a schematic diagram of the structure of a terminal 300 provided in an embodiment of the present invention. The terminal 300 can be used to execute the method for refreshing access tokens without feeling provided in an embodiment of the present invention.

[0109] The terminal 300 may include: a processor 310, a memory 320 and a communication unit 330. These components communicate via one or more buses. Those skilled in the art will appreciate that the server structure shown in the figure does not limit the present invention, and it may be a bus structure or a star structure, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0110] The memory 320 can be used to store the execution instructions of the processor 310, and the memory 320 can be implemented by any type of volatile or non-volatile storage terminal or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. When the execution instructions in the memory 320 are executed by the processor 310, the terminal 300 can perform some or all of the steps in the following method embodiments.

[0111] The processor 310 is the control center of the storage terminal, and uses various interfaces and lines to connect various parts of the entire electronic terminal. It runs or executes software programs and / or modules stored in the memory 320, and calls data stored in the memory to perform various functions of the electronic terminal and / or process data. The processor can be composed of an integrated circuit (IC), for example, it can be composed of a single packaged IC, or it can be composed of multiple packaged ICs with the same or different functions. For example, the processor 310 can only include a central processing unit (CPU). In the embodiment of the present invention, the CPU can be a single computing core or multiple computing cores.

[0112] The communication unit 330 is used to establish a communication channel so that the storage terminal can communicate with other terminals, receive user data sent by other terminals or send user data to other terminals.

[0113] The present invention also provides a computer storage medium, wherein the computer storage medium may store a program, and when the program is executed, the program may include some or all of the steps in each embodiment provided by the present invention. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM).

[0114] Those skilled in the art can clearly understand that the technology in the embodiments of the present invention can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solution in the embodiments of the present invention, in essence or in other words, the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, and other media that can store program codes, including several instructions for enabling a computer terminal (which can be a personal computer, a server, or a second terminal, a network terminal, etc.) to execute all or part of the steps of the methods described in each embodiment of the present invention.

[0115] In this specification, the same or similar parts between the various embodiments can be referred to each other. In particular, for the terminal embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description in the method embodiment.

[0116] In the several embodiments provided by the present invention, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of systems or modules, which can be electrical, mechanical or other forms.

[0117] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0118] In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.

[0119] Although the present invention has been described in detail with reference to the accompanying drawings and in combination with the preferred embodiments, the present invention is not limited thereto. Without departing from the spirit and essence of the present invention, a person of ordinary skill in the art may make various equivalent modifications or substitutions to the embodiments of the present invention, and these modifications or substitutions shall be within the scope of the present invention. Any person of ordinary skill in the art may easily think of changes or substitutions within the technical scope disclosed by the present invention, and these shall be within the scope of protection of the present invention.

Claims

1. A method for refreshing an access token without any sense of touch, characterized in that: include: Get the target server to which the request is to be sent, and get the last request time of the target server; Calculate the interval time of the request based on the previous request time and the current time, and determine whether the request to be sent and the previous request belong to the same service based on whether the interval time exceeds a set time threshold; If the request to be sent and the previous request belong to the same service, the remaining validity period of the access token is obtained, and if the remaining validity period is lower than the time threshold, a token refresh request is sent to the target server; If the request to be sent does not belong to the same service as the previous request, the access token refresh service is not supported.

2. The method according to claim 1, characterized in that Get the target server to which the request is to be sent, and get the last request time of the target server, including: Intercepting the request to be sent, and extracting the target server from the request to be sent; Calling the access token to execute the request to be sent, and if the access token is invalid, caching the request to be sent to a task queue; The access record to the target server is obtained from the historical access record, and the last request time closest to the current time is extracted from the access record.

3. The method according to claim 1, characterized in that Calculating the request interval time based on the previous request time and the current time, and judging whether the request to be sent and the previous request belong to the same service based on whether the interval time exceeds a set time threshold, including: Calculate the time difference between the current time and the last request time, and record the time difference as the interval time; Determine whether the interval time exceeds the time threshold: If yes, it is determined that the request to be sent and the previous request do not belong to the same service; If not, it is determined that the request to be sent and the previous request belong to the same service.

4. The method according to claim 1, characterized in that: The method for setting the time threshold includes: Collect historical access records, and extract the server address and access time from the access data in the historical access records; Sort the server addresses by access time to get the access sequence; Dividing the access sequence into a plurality of sequence segments, each of which contains only one server address; The access time differences of adjacent elements of each sequence segment are counted, and the maximum access time difference is screened out, and the maximum access time difference is set as the time threshold.

5. The method according to claim 1, characterized in that If the request to be sent and the previous request belong to the same service, the remaining validity period of the access token is obtained. If the remaining validity period is less than the request interval, a token refresh request is sent to the target server while processing the request to be sent, including: Obtaining the storage time of the access token and the validity period of the access token, and calculating the remaining validity period based on the validity period and the storage time; If the remaining validity period is a negative number, confirm that the access token is invalid, generate a token refresh request using a pre-stored verification token, send the token refresh request to the target server to obtain a new access token, and execute the request to be sent based on the new access token; If the remaining validity period is a positive number and the remaining validity period is not less than the time threshold, executing the request to be sent based on the access token; If the remaining validity period is a positive number and the remaining validity period is lower than the time threshold, a token refresh request is generated using a pre-stored verification token to obtain a new access token of the target server based on the token refresh request.

6. The method according to claim 5, characterized in that The method further comprises: The server receives the token refresh request and extracts a verification token from the token refresh request, where the verification token is a hash value of the user account; Pre-save the hash value of the user account to the verification list, and determine whether there is a hash value consistent with the verification token in the verification list: If yes, a new access token is generated and returned to the client that sent the token refresh request; If not, a prompt message indicating that the token refresh failed is returned.

7. The method according to claim 2, characterized in that If the request to be sent does not belong to the same service as the previous request, the access token refresh service is not supported, including: Extract the to-be-executed tasks from the task queue, and jump to the login interface based on the to-be-executed tasks.

8. A system for refreshing access tokens without any sense of touch, characterized in that: include: The request monitoring module is used to obtain the target server of the request to be sent and obtain the last request time of the target server; An association analysis module, used to calculate the interval time of the request based on the previous request time and the current time, and determine whether the request to be sent and the previous request belong to the same service based on whether the interval time exceeds a set time threshold; A token refresh module, configured to obtain the remaining validity period of the access token if the request to be sent and the previous request belong to the same service, and to send a token refresh request to the target server if the remaining validity period is lower than the time threshold; The login jump module is used to not support the access token refresh service if the request to be sent does not belong to the same business as the previous request.

9. A terminal, characterized in that: include: A memory for storing a program for refreshing the access token without any sense of touch; A processor, configured to implement the steps of the method for seamlessly refreshing an access token as described in any one of claims 1 to 7 when executing the program for seamlessly refreshing an access token.

10. A computer-readable storage medium storing a computer program, characterized in that: The readable storage medium stores a program for seamlessly refreshing an access token, and when the program for seamlessly refreshing an access token is executed by a processor, the steps of the method for seamlessly refreshing an access token as described in any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Login token refreshing method and device

    CN121567297A