All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dart-dio.auth.oauth.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
{{>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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy