Создать HTTPS сервер во Флаттере для входа в Instagram - PullRequest
0 голосов
/ 01 мая 2020

Я пытался реализовать вход с Instagram в флаттер. И URL перенаправления находится в https://localhost: 8585 . Но в приложении я реализовал сервер в http://localhost: 8585 . Как я могу решить это.

 Future<Token> getToken(String appId, String appSecret) async {
     Stream<String> onCode = await _server();
     String url =
      "https://api.instagram.com/oauth/authorize?client_id=$appId&redirect_uri=http://localhost:8585&response_type=code";
     final flutterWebviewPlugin = new FlutterWebviewPlugin();
     flutterWebviewPlugin.launch(url);
     final String code = await onCode.first;
     final http.Response response = await http.post(
      "https://api.instagram.com/oauth/access_token",
      body: {"client_id": appId, "redirect_uri": "http://localhost:8585", "client_secret": appSecret,
      "code": code, "grant_type": "authorization_code"});
     flutterWebviewPlugin.close();
     return new Token.fromMap(JSON.decode(response.body));
}

Future<Stream<String>> _server() async {
  final StreamController<String> onCode = new StreamController();
  HttpServer server =
  await HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 8585);
  server.listen((HttpRequest request) async {
    final String code = request.uri.queryParameters["code"];
    request.response
      ..statusCode = 200
      ..headers.set("Content-Type", ContentType.HTML.mimeType)
      ..write("<html><h1>You can now close this window</h1></html>");
    await request.response.close();
    await server.close(force: true);
    onCode.add(code);
    await onCode.close();
  });
  return onCode.stream;
}
...