deviceTokenCredentials.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. // Licensed under the MIT License. See License.txt in the project root for license information.
  4. Object.defineProperty(exports, "__esModule", { value: true });
  5. const tokenCredentialsBase_1 = require("./tokenCredentialsBase");
  6. const authConstants_1 = require("../util/authConstants");
  7. class DeviceTokenCredentials extends tokenCredentialsBase_1.TokenCredentialsBase {
  8. /**
  9. * Creates a new DeviceTokenCredentials object that gets a new access token using userCodeInfo (contains user_code, device_code)
  10. * for authenticating user on device.
  11. *
  12. * When this credential is used, the script will provide a url and code. The user needs to copy the url and the code, paste it
  13. * in a browser and authenticate over there. If successful, the script will get the access token.
  14. *
  15. * @constructor
  16. * @param {string} [clientId] The active directory application client id.
  17. * @param {string} [domain] The domain or tenant id containing this application. Default value is "common"
  18. * @param {string} [username] The user name for account in the form: "user@example.com".
  19. * @param {string} [tokenAudience] The audience for which the token is requested. Valid values are 'graph', 'batch', or any other resource like 'https://vault.azure.net/'.
  20. * If tokenAudience is 'graph' then domain should also be provided and its value should not be the default 'common' tenant. It must be a string (preferrably in a guid format).
  21. * See {@link https://azure.microsoft.com/en-us/documentation/articles/active-directory-devquickstarts-dotnet/ Active Directory Quickstart for .Net}
  22. * for an example.
  23. * @param {Environment} [environment] The azure environment to authenticate with. Default environment is "Azure" popularly known as "Public Azure Cloud".
  24. * @param {object} [tokenCache] The token cache. Default value is the MemoryCache object from adal.
  25. */
  26. constructor(clientId, domain, username, tokenAudience, environment, tokenCache) {
  27. if (!username) {
  28. username = "user@example.com";
  29. }
  30. if (!domain) {
  31. domain = authConstants_1.AuthConstants.AAD_COMMON_TENANT;
  32. }
  33. if (!clientId) {
  34. clientId = authConstants_1.AuthConstants.DEFAULT_ADAL_CLIENT_ID;
  35. }
  36. super(clientId, domain, tokenAudience, environment, tokenCache);
  37. this.username = username;
  38. }
  39. getToken() {
  40. // For device auth, this is just getTokenFromCache.
  41. return this.getTokenFromCache(this.username);
  42. }
  43. }
  44. exports.DeviceTokenCredentials = DeviceTokenCredentials;
  45. //# sourceMappingURL=deviceTokenCredentials.js.map