Skip to content
pubscout

oauth2_client

5.0.0, released yesterday by femtopedia.de

Interact with OAuth2 servers and handle token storage and refreshing in Flutter.

WASM-readyRock solid
$ flutter pub add oauth2_client
Source repository

What it does

A Flutter library that helps interact with OAuth2 servers using flows like Authorization Code, Client Credentials, and Implicit Grant. It includes classes for transparent authorized requests, secure token storage, and automatic token refreshing, along with predefined clients for popular services like Google, Facebook, and GitHub.

AI-written summary of version 5.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to authenticate users via custom or third-party OAuth2 providers in Flutter.
  • You want automatic handling of token refreshing and storage using secure storage.

Skip it when

  • You only need built-in Firebase Authentication or Google Sign-In via specialized SDKs.

Strengths

  • Supports multiple OAuth2 flows (Authorization Code, Client Credentials, Implicit Grant).
  • Pre-defined clients for many popular providers (Google, Facebook, GitHub, Microsoft, etc.).
  • Helper class automates token refreshing and secure storage.

Weaknesses

  • Requires platform-specific configuration such as custom URI schemes and Android Manifest updates.
  • Tokens on the web platform are stored in localStorage which is unencrypted.

Setup

Kind
Flutter widgets
Effort
Medium
Code generation
No
Direct dependencies
6

Requires adding intent filters for custom URI schemes in AndroidManifest.xml, setting the platform version in ios/Podfile, and following setup guides for flutter_web_auth_2 and flutter_secure_storage.

GoogleOAuth2Client client = GoogleOAuth2Client(customUriScheme: 'my.test.app', redirectUri: 'my.test.app:/oauth2redirect');
OAuth2Helper oauth2Helper = OAuth2Helper(client, grantType: OAuth2Helper.authorizationCode, clientId: 'your_client_id', clientSecret: 'your_client_secret', scopes: ['https://www.googleapis.com/auth/drive.readonly']);
http.Response resp = await oauth2Helper.get('https://www.googleapis.com/drive/v3/files');

Alternatives

Packages that do the same job and could replace oauth2_client.

  • google_sign_in

    If you specifically need native Google sign-in integration rather than generic OAuth2.

  • firebase_auth

    If you are using Firebase for backend authentication instead of a custom OAuth2 server.

Works with

Packages commonly used together with oauth2_client: ones it builds on, ones built on it, and its own family.