forked from loafle/openapi-generator-original
* fix runtime deserialisation * add security support for dart dio * regenerate dart dio sample * update dio pubspec.mustache deps * check response type before parsing * add default dateTime serializer * regenerate sample
21 lines
581 B
Dart
21 lines
581 B
Dart
import 'dart:async';
|
|
import 'package:openapi/auth/auth.dart';
|
|
import 'package:dio/dio.dart';
|
|
|
|
class OAuthInterceptor extends AuthInterceptor {
|
|
Map<String, String> tokens = {};
|
|
|
|
@override
|
|
Future onRequest(RequestOptions options) {
|
|
final authInfo = getAuthInfo(options, "oauth");
|
|
for (var info in authInfo) {
|
|
final token = tokens[info["name"]];
|
|
if(token != null) {
|
|
options.headers["Authorization"] = "Bearer ${token}";
|
|
break;
|
|
}
|
|
}
|
|
return super.onRequest(options);
|
|
}
|
|
}
|