Skip to content

Tonku/flutter_desktop_webview_auth

 
 

Repository files navigation

Desktop webview auth

This package enables Firebase OAuth on desktop via webview

Supported providers:

  • Google
  • Facebook
  • Twitter

Installation

macOS setup

The recaptcha verification flow is done on the local server, and it requires that the app has the following in the Release.entitlements:

<key>com.apple.security.network.server</key>
<true/>

Linux setup

To display webview on Linux, libwebkit2gtk-4.0-dev is used, if you don't have it already installed:

apt install libwebkit2gtk-4.0-dev

Additionally, if Flutter is installed using snap, you might face issues compiling the app, to fix you would need to uninstall the snap version and install Flutter manually on Linux.

Windows setup

Make sure you are on latest stable channle of Flutter, and have installed the requirements as mentioned here.

Nothing extra is needed to get started on Windows.

Add dependency

flutter pub add desktop_webview_auth

Imports

import 'package:desktop_webview_auth/desktop_webview_auth.dart';
import 'package:desktop_webview_auth/google.dart';
import 'package:desktop_webview_auth/facebook.dart';
import 'package:desktop_webview_auth/twitter.dart';

Usage

  • Configure OAuth providers in firebase console
  • Create an instance of ProviderArgs
final googleSignInArgs = GoogleSignInArgs(
  clientId:
    '448618578101-sg12d2qin42cpr00f8b0gehs5s7inm0v.apps.googleusercontent.com',
  redirectUri:
    'https://react-native-firebase-testing.firebaseapp.com/__/auth/handler',
  scope: 'email',
)
  • call DesktopWebviewAuth.signIn
try {
    final result = await DesktopWebviewAuth.signIn(args);

    print(result?.accessToken);
    print(result?.tokenSecret);
} catch (err) {
    // something went wrong
}
  • create an instance of OAuthCredential and sign in
import 'package:firebase_auth/firebase_auth.dart';

final credential = GoogleAuthProvider.credential(accessToken: result.accessToken)

FirebaseAuth.instance.signInWithCredential(credential);

About

WebView OAuth flows for desktop flutter apps

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 36.7%
  • Dart 35.4%
  • CMake 17.9%
  • Swift 5.5%
  • C 2.5%
  • Ruby 2.0%