diff --git a/packages/oidc/test/mock_client.dart b/packages/oidc/test/mock_client.dart index d130823..6236f61 100644 --- a/packages/oidc/test/mock_client.dart +++ b/packages/oidc/test/mock_client.dart @@ -76,7 +76,7 @@ Future _handleRequest( final url = request.url; if (_eq.equals(url.pathSegments, ['.well-known', 'openid-configuration'])) { - return Response(jsonEncode(mockProviderMetadata), 304); + return Response(jsonEncode(mockProviderMetadata), 200); } if (url.pathSegments.first == 'token') { final tokenResp = createMockTokenResponse( diff --git a/packages/oidc_core/lib/src/endpoints/facade.dart b/packages/oidc_core/lib/src/endpoints/facade.dart index 62ea43c..05ff049 100644 --- a/packages/oidc_core/lib/src/endpoints/facade.dart +++ b/packages/oidc_core/lib/src/endpoints/facade.dart @@ -20,6 +20,7 @@ class OidcEndpoints { }) { try { final body = jsonDecode(response.body) as Map; + if (body.containsKey(OidcConstants_AuthParameters.error)) { final resp = OidcErrorResponse.fromJson(body); throw OidcException.serverError( @@ -28,6 +29,13 @@ class OidcEndpoints { rawResponse: response, ); } + if (!(response.statusCode >= 200 && response.statusCode < 400)) { + throw OidcException( + 'Failed to handle the response from endpoint (status code ${response.statusCode}): ${request.url}', + rawRequest: request, + rawResponse: response, + ); + } return mapper(body); } on OidcException { rethrow;