Browse Source

dynamite,dynamite_runtime: Correctly search for authentication

pull/418/head
jld3103 1 year ago
parent
commit
1dac4e6b82
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 5
      packages/dynamite/dynamite/lib/src/openapi_builder.dart
  2. 15
      packages/dynamite/dynamite_runtime/lib/src/http_client.dart

5
packages/dynamite/dynamite/lib/src/openapi_builder.dart

@ -353,9 +353,10 @@ class OpenAPIBuilder implements Builder {
if (requirement.keys.isEmpty) {
continue;
}
final securityScheme = spec.components!.securitySchemes![requirement.keys.single]!;
code.write('''
if (${isRootClient ? '' : 'rootClient.'}authentications.map((final a) => a.id).contains('${requirement.keys.single}')) {
headers.addAll(${isRootClient ? '' : 'rootClient.'}authentications.singleWhere((final a) => a.id == '${requirement.keys.single}').headers);
if (${isRootClient ? '' : 'rootClient.'}authentications.where((final a) => a.type == '${securityScheme.type}' && a.scheme == '${securityScheme.scheme}').isNotEmpty) {
headers.addAll(${isRootClient ? '' : 'rootClient.'}authentications.singleWhere((final a) => a.type == '${securityScheme.type}' && a.scheme == '${securityScheme.scheme}').headers);
}
''');
if (!isOptionalSecurity ||

15
packages/dynamite/dynamite_runtime/lib/src/http_client.dart

@ -59,7 +59,8 @@ class DynamiteApiException implements Exception {
}
abstract class DynamiteAuthentication {
String get id;
String get type;
String get scheme;
Map<String, String> get headers;
}
@ -74,7 +75,11 @@ class DynamiteHttpBasicAuthentication extends DynamiteAuthentication {
final String password;
@override
String get id => 'basic_auth';
String type = 'http';
@override
String scheme = 'basic';
@override
Map<String, String> get headers => {
'Authorization': 'Basic ${base64.encode(utf8.encode('$username:$password'))}',
@ -89,7 +94,11 @@ class DynamiteHttpBearerAuthentication extends DynamiteAuthentication {
final String token;
@override
String get id => 'bearer';
String type = 'http';
@override
String scheme = 'bearer';
@override
Map<String, String> get headers => {
'Authorization': 'Bearer $token',

Loading…
Cancel
Save