rook_auth 0.3.0 copy "rook_auth: ^0.3.0" to clipboard
rook_auth: ^0.3.0 copied to clipboard

discontinued
PlatformAndroidiOS

Grant usage permissions to other rook packages.

example/README.md

Example with a dedicated widget #

rook_auth_status.dart #

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

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

  @override
  State<RookAuthStatus> createState() => _RookAuthStatusState();
}

class _RookAuthStatusState extends State<RookAuthStatus> {
  final AuthorizationProvider provider = AuthorizationProvider(
    Secrets.rookAuthUrl,
  );

  bool loading = false;
  bool authorized = false;
  DateTime? authorizedUntil;
  String? error;

  @override
  void initState() {
    initialize();

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(10),
      alignment: Alignment.center,
      child: loading
          ? const CircularProgressIndicator()
          : Column(
              children: [
                if (authorized)
                  Row(
                    children: [
                      const Icon(Icons.verified_rounded),
                      const SizedBox(width: 10),
                      Expanded(
                        child: Text(
                          'Authorized until: ${authorizedUntil?.toLocal().toIso8601String()} (Local)',
                        ),
                      ),
                    ],
                  ),
                if (!authorized) Text('Error: $error'),
                if (!authorized) const SizedBox(height: 20),
                if (!authorized)
                  ElevatedButton(
                    onPressed: initialize,
                    child: const Text('Try again'),
                  ),
              ],
            ),
    );
  }

  void initialize() async {
    setState(() => loading = true);

    try {
      final result = await provider.getAuthorization(
        Secrets.clientUUID,
      );

      setState(() {
        loading = false;
        authorized = result.authorization.isNotExpired;
        authorizedUntil = result.authorization.authorizedUntil;
        error = result.authorization.isNotExpired ? null : 'Not authorized';
      });
    } catch (e) {
      setState(() {
        loading = false;
        authorized = false;
        error = 'Error: $e';
      });
    }
  }
}
1
likes
150
points
41
downloads

Publisher

verified publisherrook-connect.com

Weekly Downloads

Grant usage permissions to other rook packages.

Homepage

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter, http, jwt_decode, logging, shared_preferences

More

Packages that depend on rook_auth