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

dart-jaguar.auth.api_key_auth.mustache Maven / Gradle / Ivy

There is a newer version: 3.0.0-rc1
Show newest version
import 'dart:async';
import 'package:{{pubName}}/auth/auth.dart';
import 'package:jaguar_retrofit/jaguar_retrofit.dart';

class ApiKeyAuthInterceptor extends AuthInterceptor {
    Map apiKeys = {};

    @override
    FutureOr before(RouteBase route) {
        final authInfo = getAuthInfo(route, "apiKey");
        for (var info in authInfo) {
            final authName = info["name"];
            final authKeyName = info["keyName"];
            final authWhere = info["where"];
            final apiKey = apiKeys[authName];
            if(apiKey != null) {
                if(authWhere == 'query'){
                    route.query(authKeyName, apiKey);
                }
            else {
                    route.header(authKeyName, apiKey);
                }
                break;
            }
        }
        return super.before(route);
    }

    @override
    FutureOr after(StringResponse response) {
        return Future.value(response);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy