GoogleClientSecret.fromJson constructor

GoogleClientSecret.fromJson(
  1. Map<String, dynamic> json
)

Creates a new instance of GoogleClientSecret from a JSON map. Expects the JSON to match the structure of the file downloaded from Google's cloud console.

Example: { "web": { "client_id": "your-client-id.apps.googleusercontent.com", "client_secret": "your-client-secret", "redirect_uris": "http://localhost:8080/auth/google/callback", "https://your-production-domain.com/auth/google/callback" ... }

Implementation

factory GoogleClientSecret.fromJson(final Map<String, dynamic> json) {
  if (json['web'] == null) {
    throw const FormatException('Missing "web" section');
  }

  final web = json['web'] as Map;

  final webClientId = web['client_id'] as String?;
  if (webClientId == null) {
    throw const FormatException('Missing "client_id"');
  }

  final webClientSecret = web['client_secret'] as String?;
  if (webClientSecret == null) {
    throw const FormatException('Missing "client_secret"');
  }

  final webRedirectUris = web['redirect_uris'] as List<dynamic>?;
  if (webRedirectUris == null) {
    throw const FormatException('Missing "redirect_uris"');
  }

  return GoogleClientSecret._(
    clientId: webClientId,
    clientSecret: webClientSecret,
    redirectUris: webRedirectUris.cast<String>(),
  );
}