Open speedphp opened 1 year ago
This way, the GetSocket code can use JWT authentication like this:
var jwtToken = await LoginService().getJwtToken();
Get.log("token: $jwtToken");
var wsUrl = Uri(
scheme: "ws",
userInfo: jwtToken,
host: GetPlatform.isAndroid ? "10.0.2.2" : "127.0.0.1",
port: 8080,
path: "/ws");
Get.log(wsUrl.toString());
final socket = GetSocket(wsUrl.toString());
socket.allowSelfSigned = false;
socket.onOpen(() {
Get.log("opened");
});
When GetServer sets WebSocket's GetPage to
needAuth: true
, JWT authentication will fail and a prompt of "Invalid JWT token!" will be thrown.Because the Flutter client's GetSocket can only set the url parameter, there is no place to set other headers.
The websocket implementation of the dart language can support adding userInfo as authentication information in the url parameter,
It's just that the authentication information starts with Basic instead of JWT's Bearer.
Therefore, this modification changed GetServer to add checks for Basic authentication information. Although this Basic information is a JWT authentication Token, this is the minimum modification.
The modifications include: