twitter_oauth2_pkce 0.1.0 copy "twitter_oauth2_pkce: ^0.1.0" to clipboard
twitter_oauth2_pkce: ^0.1.0 copied to clipboard

outdated

Provides the easiest way to authenticate with the Twitter API using the OAuth 2.0 PKCE method in Dart and 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:example/scope.dart';
import 'package:example/twitter_oauth2_client.dart';
import 'package:flutter/material.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;
  String? _refreshToken;

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

                  final response = await oauth2.executeAuthCodeFlowWithPKCE(
                    scopes: Scope.values,
                  );

                  super.setState(() {
                    _accessToken = response.accessToken;
                    _refreshToken = response.refreshToken;
                  });
                },
                child: const Text('Push!'),
              )
            ],
          ),
        ),
      );
}
16
likes
0
points
157
downloads

Publisher

verified publishershinyakato.dev

Weekly Downloads

Provides the easiest way to authenticate with the Twitter API using the OAuth 2.0 PKCE method in Dart and Flutter.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

crypto, flutter, flutter_web_auth, http

More

Packages that depend on twitter_oauth2_pkce