dart-dio.auth.oauth.mustache Maven / Gradle / Ivy
{{>header}}
import 'dart:async';
import 'package:{{pubName}}/auth/auth.dart';
import 'package:dio/dio.dart';
class OAuthInterceptor extends AuthInterceptor {
Map tokens = {};
@override
Future onRequest(RequestOptions options) {
final authInfo = getAuthInfo(options, 'oauth');
for (final info in authInfo) {
final token = tokens[info['name']];
if (token != null) {
options.headers['Authorization'] = 'Bearer ${token}';
break;
}
}
return super.onRequest(options);
}
}