How does LiveNVR implement cross-domain authentication
LiveNVR provides simple login authentication. After the client successfully logs in using the user name and password, the server returns a cookie to authenticate the token. In subsequent interface access, the server reads the token from the cookie for verification. However, when integrating with the customer system, the authentication process must be completed in the customer system. This is where cross-domain issues come in. So how does this set of authentication procedures apply to cross-domain scenarios?
Server-side processing
The server needs to perform the following operations:
-
After the login succeeds, the server writes the token to the cookie
According to the previous interface design, after successful login, the server returns the token in the HTTP Response Body, and the client is responsible for writing the token into the cookie. In a cross-domain scenario, this does not work because clients cannot write tokens to non-subdomain cookies due to browser restrictions. This problem is solved when the server writes token to cookie. The server adds the set-cookie field to the HTTP Response Header and writes token= XXX
-
The server allows cross-domain access Settings uniformly
The server configuration is allowed to cross domains and carry cookies. You need to add the following two items to the HTTP Response Header:
Access-Control-Allow-Credentials: true Access-Control-Allow-Origin: $http_origin Copy the code
Access-control-allow-origin cannot be set to *. Instead, the Origin of the client is obtained before HTTT
-
During logout, the server deletes the token from the cookie
Set-Cookie: token=; expires=Thu, 01 Jan 1970 00:00:00 GMT; Copy the code
Client processing
Clients do not need to display saving tokens to cookies. All interfaces to LiveNVR need to add cross-domain configuration, xhrFields: {withCredentials: true} and crossDomain: true
The following is an example of invoking the cross-domain login interface:
$.ajax({
type: "GET",
url: "http://other-domain/api/v1/login",
xhrFields: {
withCredentials: true
},
crossDomain: true,
data: {
username: 'admin',
password: '21232f297a57a5a743894a0e4a801fc3'//admin
}
});
Copy the code
About LiveNVR
LiveNVR can access RTSP protocol output devices such as HIGH-DEFINITION network Camera IP Camera and NVR in traditional monitoring industry through simple network Camera channel configuration. LiveNVR can pull audio and video data from these video sources and convert them to RTMP/HLS. Conduct H5 live broadcast on all-platform terminals (Web, Android and iOS), and LiveNVR can connect the live broadcast data of video sources to the third-party CDN network to achieve Internet-level live broadcast distribution;
cs/download/LiveNVR.html
LiveQing Video streaming media without plug-ins live streaming solution: www.liveqing.com
Copyright © LiveQing Team 2016-2019