Well, it was too complicated ApiKey interceptor

This commit is contained in:
Andrew 2023-04-24 19:08:43 +07:00
parent 68cdcf45e7
commit aa04b550c6

View file

@ -2,7 +2,6 @@
// AUTO-GENERATED FILE, DO NOT MODIFY! // AUTO-GENERATED FILE, DO NOT MODIFY!
// //
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:tuuli_api/src/auth/auth.dart'; import 'package:tuuli_api/src/auth/auth.dart';
@ -11,20 +10,12 @@ class ApiKeyAuthInterceptor extends AuthInterceptor {
@override @override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) { void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
final authInfo = getAuthInfo(options, (secure) => secure['type'] == 'apiKey'); for (final entry in apiKeys.entries) {
for (final info in authInfo) { final authName = entry.key;
final authName = info['name'] as String; final apiKey = entry.value;
final authKeyName = info['keyName'] as String; options.headers[authName] = apiKey;
final authWhere = info['where'] as String;
final apiKey = apiKeys[authName];
if (apiKey != null) {
if (authWhere == 'query') {
options.queryParameters[authKeyName] = apiKey;
} else {
options.headers[authKeyName] = apiKey;
}
}
}
super.onRequest(options, handler); super.onRequest(options, handler);
} }
} }
}