oauth2_client 4.1.0 copy "oauth2_client: ^4.1.0" to clipboard
oauth2_client: ^4.1.0 copied to clipboard

Flutter library for interacting with OAuth2 servers, with classes for transparent authorized requests, secure token storage, automatic token refreshing.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:oauth2_client/google_oauth2_client.dart';
import 'package:oauth2_client/oauth2_helper.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'oauth2_client example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'oauth2_client example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _body = 'Please authenticate.';

  Future<void> _authenticate() async {
    var hlp = OAuth2Helper(
      GoogleOAuth2Client(
          redirectUri: 'com.teranet.app://oauth2redirect',
          customUriScheme: 'com.teranet.app'),
      grantType: OAuth2Helper.authorizationCode,
      clientId: 'XXX-XXX-XXX',
      clientSecret: 'XXX-XXX-XXX',
      scopes: ['https://www.googleapis.com/auth/drive.readonly'],
    );

    var resp = await hlp.get('https://www.googleapis.com/drive/v3/files');
    setState(() {
      _body = resp.body;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              _body,
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _authenticate,
        tooltip: 'Authenticate',
        child: const Icon(Icons.add),
      ),
    );
  }
}
185
likes
160
points
40.5k
downloads

Publisher

verified publisherfemtopedia.de

Weekly Downloads

Flutter library for interacting with OAuth2 servers, with classes for transparent authorized requests, secure token storage, automatic token refreshing.

Repository (GitHub)
View/report issues

Topics

#authentication #network #oauth #web

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

BSD-2-Clause (license)

Dependencies

crypto, flutter, flutter_secure_storage, flutter_web_auth_2, http, meta, random_string, web

More

Packages that depend on oauth2_client