Giter Club home page Giter Club logo

openvpn_flutter's Introduction

Connect OpenVPN service with Flutter, Issues and PRs are very welcome!

Android Setup

1. Permission handler

Add this to your onActivityResult in MainActivity.java

    OpenVPNFlutterPlugin.connectWhileGranted(requestCode == 24 && resultCode == RESULT_OK);

So it look like this

    ...
    import id.laskarmedia.openvpn_flutter.OpenVPNFlutterPlugin;
    ...
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        OpenVPNFlutterPlugin.connectWhileGranted(requestCode == 24 && resultCode == RESULT_OK);
        super.onActivityResult(requestCode, resultCode, data);
    }

iOS Setup

1. Add Capabillity

Add 2 capabillity on Runner's Target, App Groups and Network Extensions, Look at the image below to get clearer details

2. Add New Target

Click + button on bottom left, Choose NETWORK EXTENSION, and follow instruction's image bellow

Add Capabillity on VPNExtension, Do it same like Runner's Capabillitiy

3. Copy Paste

Add the following lines to your Podfile (ios/Podfile)

target 'VPNExtension' do
  use_frameworks!
  pod 'OpenVPNAdapter', :git => 'https://github.com/ss-abramchuk/OpenVPNAdapter.git', :tag => '0.8.0'
end

Open VPNExtension > PacketTunnelProvider.swift and copy paste this script PacketTunnelProvider.swift

Note

You must use iOS Devices instead of Simulator to connect

Recipe

Initialize

Before start, you have to initialize the OpenVPN plugin.

    late OpenVPN openvpn;

    @override
    void initState() {
        openvpn = OpenVPN(onVpnStatusChanged: _onVpnStatusChanged, onVpnStageChanged: _onVpnStageChanged);
        openvpn.initialize(
            groupIdentifier: "GROUP_IDENTIFIER", ///Example 'group.com.laskarmedia.vpn'
            providerBundleIdentifier: "NETWORK_EXTENSION_IDENTIFIER", ///Example 'id.laskarmedia.openvpnFlutterExample.VPNExtension'
            localizedDescription: "LOCALIZED_DESCRIPTION" ///Example 'Laskarmedia VPN'
        );
    }

    void _onVpnStatusChanged(VPNStatus? vpnStatus){
        setState((){
            this.status = vpnStatus;
        });
    }

    void _onVpnStageChanged(VPNStage? stage){
        setState((){
            this.stage = stage;
        });
    }

Connect to VPN

    void connect(){
        openvpn.connect(config, name, username: username, password: password, bypassPackages: [], certIsRequired: false);
    }

Disconnect

    void disconnect(){
        openvpn.disconnect();
    }

Publishing to Play Store and App Store

Android

  1. You can use appbundle to publish the app

iOS

  1. View Apple Guidelines Relating to VPN
  2. This plugin DOES use Encryption BUT, It uses Exempt Encryptions

Licenses

Love my work?

Don't forget to give me a πŸ‘ Β or support me with a cup of β˜•οΈ

openvpn_flutter's People

Contributors

nizwar avatar 0ttik avatar

Forkers

tomislavatos

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.