mirror of
https://github.com/HackPlan/google-auth-library-nodejs.git
synced 2026-04-29 20:26:09 +08:00
Adds an implementation of IAM credentials
This commit is contained in:
@@ -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
59
lib/auth/iam.js
Normal 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;
|
||||
Reference in New Issue
Block a user