sts.js (2173B)
1 var AWS = require('../core'); 2 3 AWS.util.update(AWS.STS.prototype, { 4 /** 5 * @overload credentialsFrom(data, credentials = null) 6 * Creates a credentials object from STS response data containing 7 * credentials information. Useful for quickly setting AWS credentials. 8 * 9 * @note This is a low-level utility function. If you want to load temporary 10 * credentials into your process for subsequent requests to AWS resources, 11 * you should use {AWS.TemporaryCredentials} instead. 12 * @param data [map] data retrieved from a call to {getFederatedToken}, 13 * {getSessionToken}, {assumeRole}, or {assumeRoleWithWebIdentity}. 14 * @param credentials [AWS.Credentials] an optional credentials object to 15 * fill instead of creating a new object. Useful when modifying an 16 * existing credentials object from a refresh call. 17 * @return [AWS.TemporaryCredentials] the set of temporary credentials 18 * loaded from a raw STS operation response. 19 * @example Using credentialsFrom to load global AWS credentials 20 * var sts = new AWS.STS(); 21 * sts.getSessionToken(function (err, data) { 22 * if (err) console.log("Error getting credentials"); 23 * else { 24 * AWS.config.credentials = sts.credentialsFrom(data); 25 * } 26 * }); 27 * @see AWS.TemporaryCredentials 28 */ 29 credentialsFrom: function credentialsFrom(data, credentials) { 30 if (!data) return null; 31 if (!credentials) credentials = new AWS.TemporaryCredentials(); 32 credentials.expired = false; 33 credentials.accessKeyId = data.Credentials.AccessKeyId; 34 credentials.secretAccessKey = data.Credentials.SecretAccessKey; 35 credentials.sessionToken = data.Credentials.SessionToken; 36 credentials.expireTime = data.Credentials.Expiration; 37 return credentials; 38 }, 39 40 assumeRoleWithWebIdentity: function assumeRoleWithWebIdentity(params, callback) { 41 return this.makeUnauthenticatedRequest('assumeRoleWithWebIdentity', params, callback); 42 }, 43 44 assumeRoleWithSAML: function assumeRoleWithSAML(params, callback) { 45 return this.makeUnauthenticatedRequest('assumeRoleWithSAML', params, callback); 46 } 47 });