casdoor_flutter_sdk 0.0.2+2 copy "casdoor_flutter_sdk: ^0.0.2+2" to clipboard
casdoor_flutter_sdk: ^0.0.2+2 copied to clipboard

outdated

Casdoor_flutter_sdk will allow you to easily connect your application to the Casdoor authentication system without having to implement it from scratch.

example/lib/main.dart

import 'dart:convert';

import 'package:casdoor_flutter_sdk/casdoor.dart';
import 'package:casdoor_flutter_sdk/casdoor_flutter_sdk_config.dart';
import 'package:casdoor_flutter_sdk/casdoor_flutter_sdk_platform_interface.dart';
import 'package:flutter/material.dart';
import 'dart:async';


void main() {

  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _token = 'User is not logged in';


  final CasdoorFlutterSdkConfig _config =  CasdoorFlutterSdkConfig(
      clientId: "014ae4bd048734ca2dea",
      endpoint: "door.casdoor.com",
      organizationName: "casbin",
      appName: "app-casnode",
      redirectUri: "http://localhost:9000/callback",
      callbackUrlScheme: "casdoor"
  );

  @override
  void initState() {
    super.initState();
  }


  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> authenticate() async {
    // Get platform information
    final platform = await CasdoorFlutterSdkPlatform.instance.getPlatformVersion() ?? "";
    String callbackUri;
    if (platform == "web") {
       callbackUri = "${_config.redirectUri}.html";
    } else {
       callbackUri = "${_config.callbackUrlScheme}://callback" ;
    }
    _config.redirectUri = callbackUri;
    final Casdoor _casdoor = Casdoor(config: _config);
    final result = await _casdoor.show();
    // Get code
    final code = Uri.parse(result).queryParameters['code'] ?? "";
    final response = await _casdoor.requestOauthAccessToken(code);
    setState((){_token = jsonDecode(response.body)["access_token"] as String;});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Casdoor flutter SDK example'),
        ),
        body: Center(
          child: Text('Running on: $_token\n'),
        ),
          floatingActionButton: FloatingActionButton(
            onPressed: authenticate,
            tooltip: 'Authenticate',
            child: const Icon(Icons.people),
          )
      ),
    );
  }
}
6
likes
0
pub points
70%
popularity

Publisher

verified publishercasdoor.org

Casdoor_flutter_sdk will allow you to easily connect your application to the Casdoor authentication system without having to implement it from scratch.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

crypto, flutter, flutter_web_plugins, http, plugin_platform_interface

More

Packages that depend on casdoor_flutter_sdk