mastodon_oauth2 1.0.0 copy "mastodon_oauth2: ^1.0.0" to clipboard
mastodon_oauth2: ^1.0.0 copied to clipboard

Provides the optimized and easiest way to integrate OAuth 2.0 with Mastodon API in Flutter.

example/lib/main.dart

// Copyright 2022 Kato Shinya. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided the conditions.

import 'package:flutter/material.dart';
import 'package:mastodon_oauth2/mastodon_oauth2.dart';

void main() {
  runApp(const MaterialApp(home: Example()));
}

class Example extends StatefulWidget {
  const Example({Key? key}) : super(key: key);

  @override
  State<Example> createState() => _ExampleState();
}

class _ExampleState extends State<Example> {
  String? _accessToken;

  @override
  Widget build(BuildContext context) => Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text('Access Token: $_accessToken'),
              ElevatedButton(
                onPressed: () async {
                  final oauth2 = MastodonOAuth2Client(
                    instance: 'MASTODON_INSTANCE',
                    clientId: 'YOUR_CLIENT_ID',
                    clientSecret: 'YOUR_CLIENT_SECRET',
                    redirectUri: 'org.example.oauth://callback/',
                    customUriScheme: 'org.example.oauth',
                  );

                  final response = await oauth2.executeAuthCodeFlow(
                    scopes: [
                      Scope.read,
                      Scope.write,
                    ],
                  );

                  super.setState(() {
                    _accessToken = response.accessToken;
                  });
                },
                child: const Text('Push!'),
              )
            ],
          ),
        ),
      );
}
14
likes
125
points
77
downloads

Publisher

verified publishershinyakato.dev

Weekly Downloads

Provides the optimized and easiest way to integrate OAuth 2.0 with Mastodon API in Flutter.

Homepage
Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, flutter_web_auth_2, freezed_annotation, http, json_annotation

More

Packages that depend on mastodon_oauth2