fromJson static method

OIDCDiscoveryDocument? fromJson(
  1. dynamic value
)

Returns a new OIDCDiscoveryDocument instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static OIDCDiscoveryDocument? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key), 'Required key "OIDCDiscoveryDocument[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "OIDCDiscoveryDocument[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return OIDCDiscoveryDocument(
      issuer: mapValueOfType<String>(json, r'issuer'),
      authorizationEndpoint: mapValueOfType<String>(json, r'authorization_endpoint'),
      tokenEndpoint: mapValueOfType<String>(json, r'token_endpoint'),
      userinfoEndpoint: mapValueOfType<String>(json, r'userinfo_endpoint'),
      jwksUri: mapValueOfType<String>(json, r'jwks_uri'),
      registrationEndpoint: mapValueOfType<String>(json, r'registration_endpoint'),
      scopesSupported: json[r'scopes_supported'] is Iterable
          ? (json[r'scopes_supported'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      responseTypesSupported: json[r'response_types_supported'] is Iterable
          ? (json[r'response_types_supported'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      responseModesSupported: json[r'response_modes_supported'] is Iterable
          ? (json[r'response_modes_supported'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      grantTypesSupported: json[r'grant_types_supported'] is Iterable
          ? (json[r'grant_types_supported'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      subjectTypesSupported: json[r'subject_types_supported'] is Iterable
          ? (json[r'subject_types_supported'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      idTokenSigningAlgValuesSupported: json[r'id_token_signing_alg_values_supported'] is Iterable
          ? (json[r'id_token_signing_alg_values_supported'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      tokenEndpointAuthMethodsSupported: json[r'token_endpoint_auth_methods_supported'] is Iterable
          ? (json[r'token_endpoint_auth_methods_supported'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      claimsSupported: json[r'claims_supported'] is Iterable
          ? (json[r'claims_supported'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      codeChallengeMethodsSupported: json[r'code_challenge_methods_supported'] is Iterable
          ? (json[r'code_challenge_methods_supported'] as Iterable).cast<String>().toList(growable: false)
          : const [],
    );
  }
  return null;
}