Interface authentication calling method and system capable of being automatically configured based on. NET
By integrating request caller, authentication selector, multiple authentication implementers and Url similarity calculator on the .NET platform, the automation and flexible configuration of interface authentication are realized, solving the problems of complex integration and insufficient support for diverse scenarios and cumbersome configuration in the existing technology, and improving the efficiency and security of interface authentication are improved.
Patent Information
- Application Number
- CN202411563306.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-05
- Publication Date
- 2025-03-18
AI Technical Summary
In the prior art, the integration of interface authentication calls is difficult, insufficient support for diversified authentication scenarios, and the integration configuration process is complicated.
Using an automatically configurable interface authentication call method based on .NET, the automated and flexible configuration of the interface authentication process is realized through components such as request caller, authentication selector, multiple authentication implementers, and Url similarity calculator.
It improves the efficiency and security of interface authentication, enhances the system's adaptability and maintenance convenience, supports multiple authentication methods, can automatically match and authentication, and simplifies the integrated configuration process.
Smart Images

Figure CN119646778A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of electronic digital data processing, in particular to the technical field of computer protection against unauthorized behavior, and specifically to a method and system for automatically configurable interface authentication calling based on .NET. Background Art
[0002] In the field of network communication, the communication between the client and the server, and between the server and the third-party service is the core link. Especially when it comes to third-party service communication, identity authentication becomes the key to ensure data security and interface access control. Usually, the authentication methods are more general or self-defined. The authentication methods are numerous and messy, which is not conducive to development and maintenance by developers. The communication between the server and the third party will also be unstable due to the variability and complexity of authentication.
[0003] .NET is a cross-language development platform that allows developers to create applications using multiple programming languages. The core of this platform is the common language runtime and common type system, which provide a unified programming model and runtime environment.
[0004] Interface authentication refers to the process of authenticating and verifying the identity of the caller when calling the application interface. It is one of the important measures to ensure the security of the application. Interface permissions refer to the permissions for configuring different roles to call the interface. Some sensitive interfaces can only be called by fixed roles and cannot be accessed by ordinary roles. As a bridge for communication between different software systems, the security of the application interface becomes particularly important. Interface permission management can ensure that only authorized entities can access specific resources or perform specific operations, thereby protecting the system from external attacks and improper operations by internal personnel.
[0005] Therefore, it is necessary to improve the method and system for interface authentication calling in the prior art to solve the above problems. Summary of the invention
[0006] The present invention overcomes the deficiencies of the prior art and provides a method and system for automatically configurable interface authentication calling based on .NET, aiming to solve the problems of difficult integration, insufficient support for diversified authentication scenarios and cumbersome integration configuration process in the prior art.
[0007] To achieve the above object, the technical solution adopted by the present invention is: a method for automatically configurable interface authentication calling based on .NET, comprising:
[0008] The request caller receives the interface parameters passed in by the business system, searches for the corresponding interface information in the configuration information, and sends the interface parameters, search results and timestamp to the logger;
[0009] When the corresponding interface information is found, the authentication selector is called; the corresponding interface information is used to trigger the authentication selector to call the authentication implementer and perform authentication;
[0010] When the corresponding interface information is not found, a similarity search request is sent to the Url similarity calculator, wherein the similarity search request is used to trigger the Url similarity calculator to calculate similar interface Urls and obtain similar interface information;
[0011] The similar interface information is sent to the authentication selector by the Url similarity calculator and is used to select the authentication implementer for authentication;
[0012] Grant or restrict the business system's permission to call the interface based on the authentication results.
[0013] In a preferred embodiment of the present invention, the authentication methods include: standard JWT authentication, OAuth2 authentication, and custom authentication;
[0014] The standard JWT authentication information includes: request token Url, user information, token request header information, key corresponding to the returned token request, and key value corresponding to the interface return;
[0015] OAuth2 authentication information includes: client ID, client Secret, authentication address, token address, callback URL, resource scope, key corresponding to token request return value, and key value corresponding to interface return;
[0016] The custom authentication information includes: a custom authentication code block; the return value of the custom authentication code block is a dictionary type, and the return value is placed in the HTTP response header.
[0017] In a preferred embodiment of the present invention, when the corresponding interface information is not found, the Url similarity calculator receives a similarity search request and interface parameters from the request caller;
[0018] The Url similarity calculator parses the interface parameters, obtains the interface key Url, searches for the interface Url in the configuration information according to the similarity, and constructs the Urllist in order of similarity.
[0019] Circulate the Urllist and query the interface information again according to the interface key Url until the interface information is found, that is, similar interface information;
[0020] When the URL similarity is less than 50%, an error is thrown and authentication is stopped.
[0021] In a preferred embodiment of the present invention, the similarity calculation process includes:
[0022] Use regular expressions to separate the URL into two parts: the domain name and the API.
[0023] Use the edit distance algorithm, Jaccard coefficient algorithm and Word2Vec algorithm to comprehensively calculate the similarity between domain names and APIs;
[0024] When the comprehensive domain name similarity is less than 50%, the similarity of the API part is further considered;
[0025] When the comprehensive API similarity is higher than 90%, the overall similarity is directly set to 50%;
[0026] Finally, the calculation of the overall URL similarity is: comprehensive domain name similarity*0.95+comprehensive API similarity*0.05;
[0027] Get the corresponding similar interface information based on the URL with the highest similarity;
[0028] The URL similarity calculator sends the similar interface information to the authentication selector and repeats the query steps of the request caller.
[0029] In a preferred embodiment of the present invention, in the edit distance algorithm, levenshteinSim represents the edit distance similarity between two domain names. Among them, n and m are the lengths of the two strings respectively, and k and l are the number of characters matched in the best matching path;
[0030] In the Jaccard algorithm, jaccardSim represents the Jaccard similarity between two domain names at the character or word level; A and B are sets of two domain names respectively;
[0031] In the Word2Vec algorithm, word2vecSim represents the similarity between the Word2Vec vectors of the words in two domain names, which is calculated using cosine similarity; A i ,B i is the component of two domain names;
[0032] In a preferred embodiment of the present invention, the comprehensive similarity is calculated by taking the logarithmic average of the edit distance similarity, the Jaccard similarity and the Word2Vec similarity:
[0033] The logarithmic calculation is used to handle the cases with small similarity values and ensure that they have an appropriate impact on the final result;
[0034] In a preferred embodiment of the present invention, the authentication implementer includes: a Jwt authentication implementer, an Outh2 authentication implementer and a custom authentication implementer.
[0035] In a preferred embodiment of the present invention, the authentication step of the Jwt authentication implementer includes:
[0036] The Jwt authentication implementer obtains the data passed in by the authentication selector and outputs the token according to the interface key;
[0037] Query the interface information according to the interface key and find the token address in the configuration information;
[0038] Call the token address and get the return parameter to indicate successful call;
[0039] If the call fails, check whether the request status of the calling interface Url is 404;
[0040] When the request status is 404, call the Url similarity calculator to obtain the tokenlist of similar tokens; loop the tokenlist and query the interface information again according to the token address until the interface information is found and the token is obtained; if the similarity is less than 50%, throw an error and stop authentication; the calculation method of similarity is the same as that of URL similarity;
[0041] Return the token and authentication result to the business system, put it into the request to call the interface, obtain the interface return data, and record the log.
[0042] In a preferred embodiment of the present invention, the authentication step of the custom authentication implementer includes:
[0043] The custom authentication implementer obtains the data passed in by the authentication selector and outputs the token according to the interface key;
[0044] According to the key query interface information, query the custom authentication code string and create a CSharpCodeProvider instance;
[0045] Use regular expressions to find out the assemblies used in the authentication code and form a list;
[0046] CSharpCodeProvider.CompileAssemblyFromSource inputs two parameters, one parameter is GenerateInMemory, which represents whether to generate the assembly in memory, and the default is true; the other parameter is ReferencedAssemblies, which represents the referenced assembly, and the value is equal to the assembly list; through the program, get the generated assembly;
[0047] Get the type GetPersonAuthToken through the assembly, create a type instance, get the method based on the type instance, and finally call the type method and return the token result;
[0048] If the call fails, determine whether the custom code has a compilation error, call the Url similarity calculator, obtain the tokenlist of similar tokens, and obtain the token; if the similarity is less than 50%, throw an error and stop authentication; the similarity calculation here is consistent with the steps of the Jwt authentication implementer;
[0049] Return the token and authentication result to the business system, put it into the request to call the interface, obtain the interface return data, and record the log.
[0050] The present invention provides an automatically configurable interface authentication calling system based on .NET, comprising:
[0051] The logger is at the outermost layer of the calling interface, used to record whether the interface is successfully called and the return parameters;
[0052] The request caller is used to query the information in the configuration file, encapsulate the request body, and send the request;
[0053] Authentication selector, which calls different request classes according to different types of authentication methods;
[0054] Jwt authentication implementer, used to obtain standard JWT token;
[0055] Jwt authentication implementer, used to obtain standard Outh2 token;
[0056] Customized authentication implementer, used to obtain customized token, execute the code to obtain customized token, and obtain the corresponding token;
[0057] Url similarity calculator, calculates the Url similarity, and is used to find the relevant configuration of the most similar Url in the configuration.
[0058] The present invention solves the defects existing in the background technology and has the following beneficial effects:
[0059] (1) The present invention realizes the automation and flexible configuration of the interface authentication process by integrating components such as a request caller, an authentication selector, multiple authentication implementers, and a URL similarity calculator, effectively solving the problems of high integration complexity, insufficient support for diversified authentication scenarios, and cumbersome configuration in the prior art, thereby improving the efficiency and security of interface authentication and enhancing the adaptability and maintenance convenience of the system.
[0060] (2) The present invention combines the steps of the request caller receiving parameters and searching for configuration information with the step of the authentication selector calling the authentication implementer. The specific process is: the request caller first receives the interface parameters transmitted by the business system, and searches for the corresponding interface information in the configuration information. When the corresponding interface information is found, the authentication selector is called. The authentication selector then calls the corresponding authentication implementer for authentication according to the authentication method in the interface information, thereby automating the interface authentication process, reducing the complexity of manual configuration, and achieving efficient authentication processing. It can be configured only once, and then automatically matched and authenticated according to the interface information. Compared with the prior art, it further achieves the effect of simplifying the integrated configuration and improving the authentication efficiency.
[0061] (3) The present invention combines the step of calculating similar interface information through the Url similarity calculator with the step of repeated query of the authentication selector. The specific process is: when the request caller fails to find the corresponding interface information, the Url similarity calculator will calculate the similar interface Url and obtain the similar interface information, and then send it to the authentication selector for repeated query and authentication, so that the system can handle the situation where the interface information is not accurately matched, and find the closest configuration for authentication through similarity calculation, thereby improving the flexibility and adaptability of the system, simplifying the workload of personnel, and eliminating the need for re-development when encountering similar authentication interfaces, so as to quickly realize the communication between the business system and the third-party system. Compared with the prior art, it further achieves the effect of enhancing support for diversified authentication scenarios.
[0062] (4) The present invention combines JWT authentication implementer, Outh2 authentication implementer and custom authentication implementer with authentication selector. The specific process is as follows: the authentication selector classifies and calls different authentication implementers for authentication according to the authentication method of the interface information, so that the system can support multiple authentication methods, including standard JWT authentication, OAuth2 authentication and custom authentication, meeting the authentication requirements of different business systems. Only the relevant custom authentication code needs to be modified to realize the authentication function. Compared with the prior art, it further achieves the effect of improving the compatibility and flexibility of the authentication method.
[0063] (5) The present invention combines the Url similarity calculator with the Jwt authentication implementer, Outh2 authentication implementer and custom authentication implementer. The specific process is: when the authentication implementer fails to obtain a token and the request status is 404, the Url similarity calculator will be called to obtain a similar token set, and cyclically try to obtain a token. When the system faces an interface Url change or configuration error, it can find an alternative Url for authentication through similarity calculation, thereby improving the robustness and reliability of the system. Compared with the prior art, it further achieves the effect of enhancing the system's fault tolerance to interface changes and configuration errors. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] 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 are briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work.
[0065] Figure 1 is an overall execution flow chart of a preferred embodiment of the present invention;
[0066] Figure 2 It is a specific flow chart of a preferred embodiment of the present invention. DETAILED DESCRIPTION
[0067] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions 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 are within the scope of protection of the present invention.
[0068] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein. Therefore, the protection scope of the present invention is not limited to the specific embodiments disclosed below.
[0069] Application Overview:
[0070] In the prior art, the API gateway automatic authentication method and system based on the interface realizes the automatic authentication of the interface through the gateway and the unified identity authentication system. However, this technical solution has the problems of difficult integration, insufficient support for diversified authentication scenarios, and cumbersome integration configuration process; this method requires the construction of additional gateways and unified identity authentication systems, which is difficult to quickly integrate into a single application service; at the same time, facing third-party systems that use self-defined authentication methods, this method cannot provide friendly support, which limits its application in diversified authentication scenarios; in addition, the integration configuration process requires registration and maintenance of information in multiple systems, which increases the complexity of configuration and maintenance.
[0071] In view of the above defects of the prior art, this application proposes an automatically configurable interface authentication calling technology solution based on .NET. This solution uses .NET Core as the technical foundation and utilizes the basic methods and dynamic assembly loading function of .NET Core to realize the automatic configuration of interface authentication.
[0072] Exemplary methods:
[0073] like Figure 1 As shown, a method for automatically configurable interface authentication calling based on .NET includes:
[0074] The request caller receives the interface parameters passed in by the business system, searches for the corresponding interface information in the configuration information, and sends the interface parameters, search results and timestamp to the logger;
[0075] When the corresponding interface information is found, the authentication selector is called; the corresponding interface information is used to trigger the authentication selector to call the authentication implementer and perform authentication;
[0076] When the corresponding interface information is not found, a similarity search request is sent to the Url similarity calculator, wherein the similarity search request is used to trigger the Url similarity calculator to calculate similar interface Urls and obtain similar interface information;
[0077] The similar interface information is sent to the authentication selector by the Url similarity calculator and is used to select the authentication implementer for authentication;
[0078] Grant or restrict the business system's permission to call the interface based on the authentication results.
[0079] Specifically, configure the configuration information of the interface in the database or configuration file, the configuration information includes: interface name, interface URL, corresponding authentication method, authentication information, request method, token address;
[0080] Authentication methods include: standard JWT authentication, OAuth2 authentication, and custom authentication;
[0081] The standard JWT authentication information includes: request token Url, user information, token request header information, key corresponding to the returned token request, and key value corresponding to the interface return;
[0082] OAuth2 authentication information includes: client ID, client Secret, authentication address, token address, callback URL, resource scope, key corresponding to token request return value, and key value corresponding to interface return;
[0083] Custom authentication information includes: custom authentication code block; custom authentication code block is a piece of logic used to verify the legitimacy of the request according to specific business rules or security policies; the return value of the custom authentication code block is a dictionary type, and the return value is placed in the HTTP response header;
[0084] The interface parameters passed in by the business system include: interface key, request body, interface key URL and request query parameters;
[0085] The request caller parses the interface parameters and directly compares the interface key with the authentication information in the configuration file. If they are consistent, the corresponding interface information is obtained;
[0086] That is, the interface key in the interface parameter provided by the business system is directly compared with the interface name or interface URL in the configuration file. If the two are completely consistent, it is considered that the correct corresponding interface information has been found;
[0087] The request caller will check whether the key passed in matches the name in the configuration file. It can also check whether the URL passed in is consistent with the URL in the configuration file. If the match is successful, the authentication process will be further executed. For example, the JWT authentication process will be called next in the above embodiment.
[0088] The logger is used to record the log information during the interface call process, which is helpful for debugging, monitoring the application running status, tracking errors and performance analysis;
[0089] like Figure 2 As shown, when the corresponding interface information is found, the authentication selector receives the call request and the corresponding interface information from the request caller, and the authentication selector calls the corresponding authentication implementer through the corresponding authentication method in the corresponding interface information to perform interface authentication.
[0090] When the corresponding interface information is not found, the Url similarity calculator receives the similarity search request and interface parameters of the request caller;
[0091] The Url similarity calculator parses the interface parameters, obtains the interface key Url, searches for the interface Url in the configuration information according to the similarity, and constructs the Urllist in order of similarity.
[0092] Circulate the Urllist and query the interface information again according to the interface key Url until the interface information is found, that is, similar interface information;
[0093] When the URL similarity is less than 50%, an error is thrown and authentication is stopped.
[0094] The error thrown here means that when it is less than 50%, that is, no qualified interface information can be found in the configuration file, that is, there is no permission to access the interface, and an authentication exception is displayed, thereby terminating the authentication.
[0095] The URL consists of the following parts:
[0096] Protocol, domain, port number, API, query parameters, and fragment identifiers;
[0097] Specifically, the similarity calculation process includes:
[0098] Use regular expressions to separate the URL into two parts: the domain name and the API.
[0099] For example: ^(https?:\ / \ / )?([\w.-]+)(\ / .*)?$; this expression can be used to separate the domain name;
[0100] api_path = match.group; used to match the API part;
[0101] Use the edit distance algorithm, Jaccard coefficient algorithm and Word2Vec algorithm to comprehensively calculate the similarity between domain names and APIs;
[0102] Levenshtein distance is a method of measuring the difference between two strings by calculating the minimum number of editing operations required to transform one string into another. In this algorithm, levenshteinSim represents the edit distance similarity between two domain names, levenshteinSim = min 0≤k≤n Edit(n,m,k,l), where n and m are the lengths of the two strings, respectively, and k and l are the number of characters matched in the best matching path;
[0103] The specific comparison is as follows:
[0104] Create a matrix of size (m+1)*(n+1), where m is the length of the first string and n is the length of the second string;
[0105] The first row and the first column represent the number of edit operations required to convert from the empty string to the prefix of the second string and from the empty string to the prefix of the first string, which are 0, 1, 2, ..., n, or m respectively;
[0106] For each cell in the matrix, calculate the minimum of the three directions plus one:
[0107] Left: delete a character;
[0108] Above: insert a character;
[0109] Top left: Replace or keep characters unchanged;
[0110] If the characters at the current position are the same, the value of the upper left column remains unchanged; otherwise, the value of the upper left column increases by one;
[0111] The best matching path is the process of moving from the lower right corner of the matrix back to the upper left corner, each time choosing the direction with the lowest cost;
[0112] In the edit distance algorithm, the "best matching path" refers to the path with the least number of editing operations required when converting from one string to another. This path determines the minimum edit distance between the two strings.
[0113] The Jaccard coefficient is a method to measure the similarity between two sets, which is defined as the size of the intersection of the two sets divided by the size of their union. In this algorithm, jaccardSim represents the Jaccard similarity between two domain names at the character or vocabulary level. A and B are sets of two domain names respectively;
[0114] Word2Vec is a technology for calculating word vectors, which can map words to vectors in high-dimensional space. In this algorithm, word2vecSim represents the similarity between the Word2Vec vectors of words in two domain names, which is calculated using cosine similarity. A i ,B i is the component of two domain names;
[0115] The comprehensive similarity is calculated by taking the logarithmic average of the edit distance similarity, Jaccard similarity, and Word2Vec similarity: The logarithmic calculation is used to handle the cases with small similarity values and ensure that they have an appropriate impact on the final result;
[0116] The above comprehensive similarity can be used to calculate comprehensive domain name similarity and comprehensive API similarity;
[0117] When the comprehensive domain name similarity is less than 50%, the similarity of the API part is further considered;
[0118] When the comprehensive API similarity is higher than 90%, the overall similarity is directly set to 50%;
[0119] To give a certain similarity score when the API parts are extremely similar, but not too high, to avoid frequent changes in the API parts and causing irregularities;
[0120] Finally, the calculation of the overall URL similarity is: comprehensive domain name similarity*0.95+comprehensive API similarity*0.05;
[0121] Get the corresponding similar interface information based on the URL with the highest similarity;
[0122] The URL similarity calculator sends the similar interface information to the authentication selector and repeats the query steps of the request caller.
[0123] The authentication implementers include: Jwt authentication implementer, Outh2 authentication implementer and custom authentication implementer, which correspond to the authentication methods respectively;
[0124] The Jwt authentication implementer obtains the data passed in by the authentication selector and outputs the token according to the interface key;
[0125] Query the interface information according to the interface key and find the token address in the configuration information;
[0126] Call the token address and get the return parameter to indicate successful call;
[0127] If the call fails, check whether the request status of the calling interface Url is 404;
[0128] When the request status is 404, call the Url similarity calculator to obtain a collection of similar tokens, tokenlist; loop tokenlist, query the interface information again according to the token address until the interface information is found and the token is obtained; if the similarity is less than 50%, throw an error and stop authentication; the calculation method of this step is consistent with the calculation of url similarity, so it will not be repeated;
[0129] Return the token and authentication result to the business system, put it into the request to call the interface, obtain the interface return data, and record the log.
[0130] The Outh2 authentication implementer obtains the data passed in by the authentication selector and outputs the token according to the interface key;
[0131] Query the interface information according to the interface key, query the client ID, resource range and authentication address in the configuration information, and output the temporary authorization code;
[0132] Put the client ID, client key, callback URL, and temporary authorization code into the request body, and request the token address to obtain the token;
[0133] If the call fails, check whether the request status of the calling interface Url is 404;
[0134] When the request status is 404, call the Url similarity calculator to obtain the tokenlist of similar tokens and get the token. The steps here are consistent with those of the Jwt authentication implementer.
[0135] Return the token and authentication result to the business system, put it into the request to call the interface, obtain the interface return data, and record the log.
[0136] The custom authentication implementer obtains the data passed in by the authentication selector and outputs the token according to the interface key;
[0137] According to the key query interface information, the custom authentication code string is queried and a CSharpCodeProvider instance is created; CSharpCodeProvider is a dynamic compiler provided by .net for compiling .net code;
[0138] Use regular expressions to find out the assemblies used in the authentication code and form a list;
[0139] Specifically, CSharpCodeProvider.CompileAssemblyFromSource inputs two parameters, one parameter is GenerateInMemory, which represents whether to generate the assembly in memory, and the default is true; the other parameter is ReferencedAssemblies, which represents the referenced assembly, and the value is equal to the assembly list; through the above program, get the generated assembly;
[0140] Get the type GetPersonAuthToken through the assembly, create a type instance, get the method based on the type instance, and finally call the type method and return the token result;
[0141] If the call fails, determine whether the custom code has a compilation error, call the Url similarity calculator, obtain the tokenlist of similar tokens, and obtain the token; the steps here are consistent with those of the Jwt authentication implementer;
[0142] Return the token and authentication result to the business system, put it into the request to call the interface, obtain the interface return data, and record the log.
[0143] Exemplary Systems
[0144] A system for automatically configurable interface authentication calling based on .NET, comprising:
[0145] The logger is at the outermost layer of the calling interface, used to record whether the interface is successfully called and the return parameters;
[0146] The request caller is used to query the information in the configuration file, encapsulate the request body, and send the request;
[0147] Authentication selector, which calls different request classes according to different types of authentication methods;
[0148] Jwt authentication implementer, used to obtain standard JWT token;
[0149] Jwt authentication implementer, used to obtain standard Outh2 token;
[0150] Customized authentication implementer, used to obtain customized token, execute the code to obtain customized token, and obtain the corresponding token;
[0151] Url similarity calculator, calculates the Url similarity, and is used to find the relevant configuration of the most similar Url in the configuration.
[0152] The above is based on the ideal embodiment of the present invention. Through the above description, relevant personnel can make various changes and modifications without departing from the technical concept of the present invention. The technical scope of the present invention is not limited to the content in the specification, and the technical scope must be determined according to the scope of the claims.
Claims
1. A method for automatically configurable interface authentication calling based on .NET, characterized in that: Includes steps: The request caller receives the interface parameters passed in by the business system, searches for the corresponding interface information in the configuration information, and sends the interface parameters, search results and timestamp to the logger; When the corresponding interface information is found, the authentication selector is called; The corresponding interface information is used to trigger the authentication selector to call the authentication implementer and perform authentication; When the corresponding interface information is not found, a similarity search request is sent to the Url similarity calculator, wherein the similarity search request is used to trigger the Url similarity calculator to calculate similar interface Urls and obtain similar interface information; The similar interface information is sent to the authentication selector by the Url similarity calculator and is used to select the authentication implementer for authentication; Grant or restrict the business system's permission to call the interface based on the authentication results.
2. According to claim 1, a method for automatically configurable interface authentication calling based on .NET, characterized in that: Authentication methods include: standard JWT authentication, OAuth2 authentication, and custom authentication; The standard JWT authentication information includes: request token Url, user information, token request header information, key corresponding to the returned token request, and key value corresponding to the interface return; OAuth2 authentication information includes: client ID, client Secret, authentication address, token address, callback URL, resource scope, key corresponding to token request return value, and key value corresponding to interface return; The custom authentication information includes: a custom authentication code block; the return value of the custom authentication code block is a dictionary type, and the return value is placed in the HTTP response header.
3. The method of automatically configurable interface authentication calling based on .NET according to claim 2, characterized in that: When the corresponding interface information is not found, the Url similarity calculator receives the similarity search request and interface parameters of the request caller; The Url similarity calculator parses the interface parameters, obtains the interface key Url, searches for the interface Url in the configuration information according to the similarity, and constructs the Urllist in order of similarity. Circulate the Urllist and query the interface information again according to the interface key Url until the interface information is found, that is, similar interface information; When the URL similarity is less than 50%, an error is thrown and authentication is stopped.
4. The method for automatically configurable interface authentication calling based on .NET according to claim 1, characterized in that: The similarity calculation process includes: Use regular expressions to separate the URL into two parts: the domain name and the API. Use the edit distance algorithm, Jaccard coefficient algorithm and Word2Vec algorithm to comprehensively calculate the similarity between domain names and APIs; When the comprehensive domain name similarity is less than 50%, the similarity of the API part is further considered; When the comprehensive API similarity is higher than 90%, the overall similarity is directly set to 50%; Finally, the calculation of the overall URL similarity is: comprehensive domain name similarity*0.95+comprehensive API similarity*0.05; Get the corresponding similar interface information based on the URL with the highest similarity; The URL similarity calculator sends the similar interface information to the authentication selector and repeats the query steps of the request caller.
5. The method of automatically configurable interface authentication calling based on .NET according to claim 4, characterized in that: In the edit distance algorithm, levenshteinSim represents the edit distance similarity between two domain names. Among them, n and m are the lengths of the two strings respectively, and k and l are the number of characters matched in the best matching path; In the Jaccard algorithm, jaccardSim represents the Jaccard similarity between two domain names at the character or word level; A and B are sets of two domain names respectively; In the Word2Vec algorithm, word2vecSim represents the similarity between the Word2Vec vectors of the words in two domain names, which is calculated using cosine similarity; A i ,B i The components of two domain names.
6. The method of automatically configurable interface authentication calling based on .NET according to claim 5, characterized in that: The comprehensive similarity is calculated by taking the logarithmic average of the edit distance similarity, Jaccard similarity, and Word2Vec similarity: The logarithmic calculation is used to handle small similarity values and ensure that they have an appropriate impact on the final result.
7. The method of automatically configurable interface authentication calling based on .NET according to claim 6, characterized in that: Authentication implementers include: Jwt authentication implementer, Outh2 authentication implementer and custom authentication implementer.
8. The method for automatically configurable interface authentication calling based on .NET according to claim 7, characterized in that: The authentication steps of the Jwt authentication implementer include: The Jwt authentication implementer obtains the data passed in by the authentication selector and outputs the token according to the interface key; Query the interface information according to the interface key and find the token address in the configuration information; Call the token address and get the return parameter to indicate successful call; If the call fails, check whether the request status of the calling interface Url is 404; When the request status is 404, call the Url similarity calculator to obtain the tokenlist of similar tokens; loop the tokenlist and query the interface information again according to the token address until the interface information is found and the token is obtained; if the similarity is less than 50%, throw an error and stop authentication; the calculation method of similarity is the same as that of URL similarity; Return the token and authentication result to the business system, put it into the request to call the interface, obtain the interface return data, and record the log.
9. The method for automatically configurable interface authentication calling based on .NET according to claim 8, characterized in that: The authentication steps of the custom authenticator include: The custom authentication implementer obtains the data passed in by the authentication selector and outputs the token according to the interface key; According to the key query interface information, query the custom authentication code string and create a CSharpCodeProvider instance; Use regular expressions to find out the assemblies used in the authentication code and form a list; CSharpCodeProvider.CompileAssemblyFromSource inputs two parameters, one parameter is GenerateInMemory, which represents whether to generate the assembly in memory, and the default is true; the other parameter is ReferencedAssemblies, which represents the referenced assembly, and the value is equal to the assembly list; through the program, get the generated assembly; Get the type GetPersonAuthToken through the assembly, create a type instance, get the method based on the type instance, and finally call the type method and return the token result; If the call fails, determine whether the custom code has a compilation error, call the Url similarity calculator, obtain the tokenlist of similar tokens, and obtain the token; if the similarity is less than 50%, throw an error and stop authentication; the similarity calculation here is consistent with the steps of the Jwt authentication implementer; Return the token and authentication result to the business system, put it into the request to call the interface, obtain the interface return data, and record the log.
10. A system for automatically configurable interface authentication and calling based on .NET, a method and system for automatically configurable interface authentication and calling based on .NET according to any one of claims 1 to 9, characterized in that: include: The logger is at the outermost layer of the calling interface, used to record whether the interface is successfully called and the return parameters; The request caller is used to query the information in the configuration file, encapsulate the request body, and send the request; Authentication selector, which calls different request classes according to different types of authentication methods; Jwt authentication implementer, used to obtain standard JWT token; Jwt authentication implementer, used to obtain standard Outh2 token; Customized authentication implementer, used to obtain customized token, execute the code to obtain customized token, and obtain the corresponding token; Url similarity calculator, calculates the Url similarity, and is used to find the relevant configuration of the most similar Url in the configuration.