Adds an implementation of IAM credentials

This commit is contained in:
Tim Emiola
2015-04-23 08:06:00 -07:00
parent 904dc16f96
commit 2911180c16
3 changed files with 110 additions and 0 deletions

View File

@@ -58,6 +58,11 @@ function createError(message, err) {
return Error(s);
}
/**
* Convenience field mapping in the IAM credential type.
*/
GoogleAuth.prototype.IAM = require('./iam.js');
/**
* Convenience field mapping in the Compute credential type.
*/

59
lib/auth/iam.js Normal file
View File

@@ -0,0 +1,59 @@
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
/**
* IAM credentials.
*
* @param {string=} selector the iam authority selector
* @param {string=} token the token
* @constructor
*/
function IAM(selector, token) {
this.selector = selector;
this.token = token;
}
/**
* Indicates whether the credential requires scopes to be created by calling
* createdScoped before use.
*
* @return {boolean} always false
*/
IAM.prototype.createScopedRequired = function() {
// IAM authorization does not use scopes.
return false;
};
/**
* Pass the selector and token to the metadataFn callback.
*
* @param {string} unused_uri_ is required of the credentials interface
* @param {function} metadataFn a callback invoked with object
* containing request metadata.
*/
IAM.prototype.getRequestMetadata = function(unused_uri_, metadataFn) {
metadataFn(null, {
'x-goog-iam-authority-selector': this.selector,
'x-goog-iam-authorization-token': this.token
});
};
/**
* Export IAM.
*/
module.exports = IAM;