var ApiKeyAuth = require('./apikey'),
    OAuthAuth  = require('./oauth');

function AuthApi(req, requestParams) {
    this.req = req;
    this.authBacked = getAuthBackend(req, requestParams);

    this._hasCredentials = null;
}

AuthApi.prototype.getType = function () {
    if (this.authBacked instanceof ApiKeyAuth) {
        return 'apiKey';
    } else if (this.authBacked instanceof OAuthAuth) {
        return 'oAuth';
    }
};

AuthApi.prototype.hasCredentials = function() {
    if (this._hasCredentials === null) {
        this._hasCredentials = this.authBacked.hasCredentials();
    }
    return this._hasCredentials;
};

AuthApi.prototype.getCredentials = function() {
    return this.authBacked.getCredentials();
};

AuthApi.prototype.verifyCredentials = function(callback) {
    if (this.hasCredentials()) {
        this.authBacked.verifyCredentials(callback);
    } else {
        callback(null, false);
    }
};

function getAuthBackend(req, requestParams) {
    if (requestParams.api_key) {
        return new ApiKeyAuth(req, requestParams.metadataBackend, requestParams.user, requestParams.api_key);
    } else {
        return new OAuthAuth(req, requestParams.metadataBackend);
    }
}

module.exports = AuthApi;

@@ -146,16 +146,17 @@
 uthBacke
+n
 d = getA
@@ -280,32 +280,33 @@
  (this.authBacke
+n
 d instanceof Api
@@ -370,16 +370,17 @@
 uthBacke
+n
 d instan
@@ -565,16 +565,17 @@
 uthBacke
+n
 d.hasCre
@@ -702,16 +702,17 @@
 uthBacke
+n
 d.getCre
@@ -841,16 +841,17 @@
 uthBacke
+n
 d.verify

fix typo: Backed -> Backend