oauth2
2.0.5, released a year ago by tools.dart.dev
A client library for OAuth2 authentication and authorized HTTP requests.
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.
- flutter_web_auth
Authenticate users with web services and OAuth2 via native web authentication sessions.
50Compare - flutter_web_auth_2
Flutter plugin for authenticating a user with a web service.
93Compare - googleapis_auth
Obtain Access credentials and authenticated HTTP clients for Google APIs using OAuth 2.0.
91Compare - oauth2_client
Interact with OAuth2 servers and handle token storage and refreshing in Flutter.
92Compare
Works with
Packages commonly used together with oauth2: ones it builds on, ones built on it, and its own family.
- cryptooauth2 depends on itProvides SHA, MD5, and HMAC hashing functions for Dart.
- http_parseroauth2 depends on itA platform-independent package for parsing and serializing HTTP formats.
- pub_api_clientBuilt on oauth2An unofficial API client for Pub.dev to interact with public package information.
- spotifyBuilt on oauth2A Dart library for interfacing with the Spotify Web API.
- nyxxBuilt on oauth2A complete and efficient wrapper around Discord's API for bots and applications.
- crowdin_sdkBuilt on oauth2Over-the-air translation delivery for Flutter apps using Crowdin CDN and ARB files.
- oauth_webauthBuilt on oauth2WebView-based OAuth 2.0 flow for mobile and web
- flutter_onedriveBuilt on oauth2Upload, download, and manage files on Microsoft OneDrive from a Flutter app.