Skip to content
pubscout

oauth2

2.0.5, released a year ago by tools.dart.dev

A client library for OAuth2 authentication and authorized HTTP requests.

WASM-readyQuiet but busy
$ flutter pub add oauth2
Source repository

What it does

Allows apps to authenticate with remote services via OAuth2 using flows like Authorization Code Grant, Client Credentials Grant, and Resource Owner Password Grant. Provides an authorized HTTP client to make requests with the user's credentials.

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

Use it when

  • You need to authenticate users via OAuth2 in Dart or Flutter applications
  • You need to persist and automatically refresh user OAuth2 credentials

Skip it when

  • You are using Firebase or Supabase authentication which have dedicated backend SDKs
  • You only need standard unauthenticated HTTP requests

Strengths

  • Supports multiple OAuth2 grant types including Authorization Code with PKCE, Client Credentials, and Resource Owner Password
  • Handles automatic saving and refreshing of credentials
  • Integrates seamlessly with the standard package:http client

Weaknesses

  • Requires manual platform-specific implementation for handling redirect URLs and launching browsers
  • Does not support all possible OAuth2 flows

Setup

Kind
Pure Dart
Effort
Medium
Code generation
No
Direct dependencies
4

Requires setting up URL launching, deep links, or WebViews on mobile and custom web redirection code to capture the OAuth2 redirect response.

import 'package:oauth2/oauth2.dart' as oauth2;

final authorizationEndpoint = Uri.parse('http://example.com/oauth2/authorization');
final tokenEndpoint = Uri.parse('http://example.com/oauth2/token');

var client = await oauth2.clientCredentialsGrant(
    authorizationEndpoint, 'my client identifier', 'my client secret');

var response = await client.read('https://example.com/api/some_resource.json');

Alternatives

Packages that do the same job and could replace oauth2.

Works with

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