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

Cl@ve authentication for Spanish government services. Supports Cl@ve PIN, Cl@ve Permanente, Electronic Certificate, European Credential (eIDAS), and Cl@ve Movil flows.

example/example.dart

// ignore_for_file: avoid_print

import 'package:felectronic_clave/felectronic_clave.dart';

Future<void> main() async {
  // 1. Configure the Cl@ve client.
  const config = ClaveConfig(
    discoveryUrl:
        'https://auth-api.redsara.es/auth/realms/.../openid-configuration',
    clientId: 'my-client-id',
    redirectUri: 'com.example.app://login-callback',
    clientSecret: 'my-client-secret',
    userInfoUrl:
        'https://auth-api.redsara.es/auth/realms/.../openid-connect/userinfo',
    logoutUrl:
        'https://auth-api.redsara.es/auth/realms/.../openid-connect/logout',
  );

  final repo = ClaveRepository(config);

  // 2. Login with Cl@ve PIN.
  try {
    final result = await repo.login(method: ClaveAuthMethod.clavePin);
    print('Access token: ${result.accessToken}');
  } on ClaveAuthCancelledError {
    print('User cancelled login');
  } on ClaveError catch (e) {
    print('Login error: ${e.message}');
  }

  // 3. Check stored token.
  final token = await repo.getStoredToken();
  if (token != null) {
    print('Stored token available');
  }

  // 4. Validate a Spanish document number.
  print(DocumentValidator.isValidDni('12345678Z')); // true or false
  print(DocumentValidator.isValidNie('X1234567L')); // true or false

  // 5. Cleanup.
  repo.dispose();
}
0
likes
150
points
29
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Cl@ve authentication for Spanish government services. Supports Cl@ve PIN, Cl@ve Permanente, Electronic Certificate, European Credential (eIDAS), and Cl@ve Movil flows.

Repository (GitHub)
View/report issues

Topics

#oauth #clave #spain #authentication #identity

License

MIT (license)

Dependencies

flutter, flutter_appauth, flutter_secure_storage, http

More

Packages that depend on felectronic_clave