diff --git a/sdk/identity/identity/.eslintignore b/sdk/identity/identity/.eslintignore index 471eb886ff6f..9e679be63366 100644 --- a/sdk/identity/identity/.eslintignore +++ b/sdk/identity/identity/.eslintignore @@ -1 +1,2 @@ -test/manual/ \ No newline at end of file +test/manual/ +test/manual-integration/ diff --git a/sdk/identity/identity/.eslintrc.json b/sdk/identity/identity/.eslintrc.json new file mode 100644 index 000000000000..c6695b65bc04 --- /dev/null +++ b/sdk/identity/identity/.eslintrc.json @@ -0,0 +1,8 @@ +{ + "plugins": ["@azure/azure-sdk"], + "extends": ["plugin:@azure/azure-sdk/azure-sdk-base"], + "ignorePatterns": ["src/core"], + "rules": { + "@azure/azure-sdk/ts-naming-options": "warn" + } +} diff --git a/sdk/identity/identity/package.json b/sdk/identity/identity/package.json index 70a55e306b13..c11d5f61a02b 100644 --- a/sdk/identity/identity/package.json +++ b/sdk/identity/identity/package.json @@ -36,8 +36,9 @@ "integration-test:browser": "echo skipped", "integration-test:node": "echo skipped", "integration-test": "npm run integration-test:node && npm run integration-test:browser", - "lint:fix": "eslint package.json tsconfig.json src test samples --ext .ts --fix --fix-type [problem,suggestion]", - "lint": "eslint package.json tsconfig.json src test samples --ext .ts -f html -o identity-lintReport.html || exit 0", + "lint:fix": "eslint package.json tsconfig.json src test --ext .ts --fix --fix-type [problem,suggestion]", + "lint": "eslint package.json tsconfig.json src test --ext .ts -f html -o identity-lintReport.html", + "lint:terminal": "eslint package.json api-extractor.json src test --ext .ts", "pack": "npm pack 2>&1", "prebuild": "npm run clean", "test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser", @@ -54,9 +55,13 @@ "README.md", "LICENSE" ], + "engines": { + "node": ">=8.0.0" + }, "repository": "github:Azure/azure-sdk-for-js", "keywords": [ - "azure", + "Azure", + "cloud", "active directory", "authentication", "credential", @@ -68,12 +73,12 @@ "author": "Microsoft Corporation", "license": "MIT", "bugs": { - "url": "https://github.com/azure/azure-sdk-for-js/issues" + "url": "https://github.com/Azure/azure-sdk-for-js/issues" }, "engine": { "node": ">=8.0.0" }, - "homepage": "https://github.com/azure/azure-sdk-for-js/tree/master/sdk/identity/identity", + "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity/README.md", "sideEffects": false, "dependencies": { "@azure/core-http": "^1.1.4", @@ -91,6 +96,7 @@ "keytar": "^5.4.0" }, "devDependencies": { + "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@azure/abort-controller": "^1.0.0", "@microsoft/api-extractor": "7.7.11", "@rollup/plugin-commonjs": "11.0.2", diff --git a/sdk/identity/identity/review/identity.api.md b/sdk/identity/identity/review/identity.api.md index db1287539a0c..6c6edd38f6fa 100644 --- a/sdk/identity/identity/review/identity.api.md +++ b/sdk/identity/identity/review/identity.api.md @@ -48,7 +48,6 @@ export enum AzureAuthorityHosts { // @public export class AzureCliCredential implements TokenCredential { - constructor(); protected getAzureCliAccessToken(resource: string): Promise; getToken(scopes: string | string[], options?: GetTokenOptions): Promise; } diff --git a/sdk/identity/identity/src/client/errors.ts b/sdk/identity/identity/src/client/errors.ts index 8b107b97e328..484ac7ef19e6 100644 --- a/sdk/identity/identity/src/client/errors.ts +++ b/sdk/identity/identity/src/client/errors.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. /** * See the official documentation for more details: @@ -153,7 +153,7 @@ export class AggregateAuthenticationError extends Error { public errors: any[]; constructor(errors: any[], errorMessage?: string) { - let errorDetail = errors.join("\n"); + const errorDetail = errors.join("\n"); super(`${errorMessage}\n\n${errorDetail}`); this.errors = errors; diff --git a/sdk/identity/identity/src/client/identityClient.ts b/sdk/identity/identity/src/client/identityClient.ts index 462cf071d49d..0d935496e26b 100644 --- a/sdk/identity/identity/src/client/identityClient.ts +++ b/sdk/identity/identity/src/client/identityClient.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import qs from "qs"; import { diff --git a/sdk/identity/identity/src/constants.ts b/sdk/identity/identity/src/constants.ts index fd9c6cf68ef2..1d5382e89d8a 100644 --- a/sdk/identity/identity/src/constants.ts +++ b/sdk/identity/identity/src/constants.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. /** * The default client ID for authentication diff --git a/sdk/identity/identity/src/credentials/authorizationCodeCredential.browser.ts b/sdk/identity/identity/src/credentials/authorizationCodeCredential.browser.ts index dbaae339a01b..db071506261a 100644 --- a/sdk/identity/identity/src/credentials/authorizationCodeCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/authorizationCodeCredential.browser.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. /* eslint-disable @typescript-eslint/no-unused-vars */ diff --git a/sdk/identity/identity/src/credentials/authorizationCodeCredential.ts b/sdk/identity/identity/src/credentials/authorizationCodeCredential.ts index f3b7431d2f53..fd078d73c8b8 100644 --- a/sdk/identity/identity/src/credentials/authorizationCodeCredential.ts +++ b/sdk/identity/identity/src/credentials/authorizationCodeCredential.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import qs from "qs"; import { createSpan } from "../util/tracing"; diff --git a/sdk/identity/identity/src/credentials/azureCliCredential.browser.ts b/sdk/identity/identity/src/credentials/azureCliCredential.browser.ts index 7001e95f2228..26846879d885 100644 --- a/sdk/identity/identity/src/credentials/azureCliCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/azureCliCredential.browser.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. /* eslint-disable @typescript-eslint/no-unused-vars */ diff --git a/sdk/identity/identity/src/credentials/azureCliCredential.ts b/sdk/identity/identity/src/credentials/azureCliCredential.ts index cdf24ff205fa..cafd964dda17 100644 --- a/sdk/identity/identity/src/credentials/azureCliCredential.ts +++ b/sdk/identity/identity/src/credentials/azureCliCredential.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http"; import { createSpan } from "../util/tracing"; @@ -26,11 +26,6 @@ const logger = credentialLogger("AzureCliCredential"); * with Azure CLI command "az account get-access-token". */ export class AzureCliCredential implements TokenCredential { - /** - * Creates an instance of the AzureCliCredential class. - */ - constructor() {} - /** * Gets the access token from Azure CLI * @param resource The resource to use when getting the token @@ -66,8 +61,7 @@ export class AzureCliCredential implements TokenCredential { options?: GetTokenOptions ): Promise { return new Promise((resolve, reject) => { - let scope: string; - scope = typeof scopes === "string" ? scopes : scopes[0]; + const scope = typeof scopes === "string" ? scopes : scopes[0]; logger.getToken.info(`Using the scope ${scope}`); const resource = scope.replace(/\/.default$/, ""); @@ -85,8 +79,8 @@ export class AzureCliCredential implements TokenCredential { this.getAzureCliAccessToken(resource) .then((obj: any) => { if (obj.stderr) { - let isLoginError = obj.stderr.match("(.*)az login(.*)"); - let isNotInstallError = + const isLoginError = obj.stderr.match("(.*)az login(.*)"); + const isNotInstallError = obj.stderr.match("az:(.*)not found") || obj.stderr.startsWith("'az' is not recognized"); if (isNotInstallError) { @@ -109,10 +103,12 @@ export class AzureCliCredential implements TokenCredential { responseData = obj.stdout; const response: { accessToken: string; expiresOn: string } = JSON.parse(responseData); logger.getToken.info(formatSuccess(scopes)); - resolve({ + const returnValue = { token: response.accessToken, expiresOnTimestamp: new Date(response.expiresOn).getTime() - }); + }; + resolve(returnValue); + return returnValue; } }) .catch((err) => { diff --git a/sdk/identity/identity/src/credentials/chainedTokenCredential.ts b/sdk/identity/identity/src/credentials/chainedTokenCredential.ts index e6b3c29dd140..61b55985c0f0 100644 --- a/sdk/identity/identity/src/credentials/chainedTokenCredential.ts +++ b/sdk/identity/identity/src/credentials/chainedTokenCredential.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import { AccessToken, TokenCredential, GetTokenOptions } from "@azure/core-http"; import { AggregateAuthenticationError, CredentialUnavailable } from "../client/errors"; diff --git a/sdk/identity/identity/src/credentials/clientCertificateCredential.browser.ts b/sdk/identity/identity/src/credentials/clientCertificateCredential.browser.ts index 2a90244b4649..45ade7b02d53 100644 --- a/sdk/identity/identity/src/credentials/clientCertificateCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/clientCertificateCredential.browser.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. /* eslint-disable @typescript-eslint/no-unused-vars */ diff --git a/sdk/identity/identity/src/credentials/clientCertificateCredential.ts b/sdk/identity/identity/src/credentials/clientCertificateCredential.ts index 76e025d2dbe0..fae3ac430e47 100644 --- a/sdk/identity/identity/src/credentials/clientCertificateCredential.ts +++ b/sdk/identity/identity/src/credentials/clientCertificateCredential.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import qs from "qs"; import jws from "jws"; diff --git a/sdk/identity/identity/src/credentials/clientSecretCredential.ts b/sdk/identity/identity/src/credentials/clientSecretCredential.ts index 26450f915fd8..ff1a06ecc3fc 100644 --- a/sdk/identity/identity/src/credentials/clientSecretCredential.ts +++ b/sdk/identity/identity/src/credentials/clientSecretCredential.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import qs from "qs"; import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http"; diff --git a/sdk/identity/identity/src/credentials/defaultAzureCredential.browser.ts b/sdk/identity/identity/src/credentials/defaultAzureCredential.browser.ts index 201ad9b36ee5..eaeff355bce4 100644 --- a/sdk/identity/identity/src/credentials/defaultAzureCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/defaultAzureCredential.browser.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import { TokenCredentialOptions } from "../client/identityClient"; import { ChainedTokenCredential } from "./chainedTokenCredential"; @@ -26,7 +26,7 @@ export class DefaultAzureCredential extends ChainedTokenCredential { * @param options Options for configuring the client which makes the authentication request. */ constructor(tokenCredentialOptions?: TokenCredentialOptions) { - let credentials = []; + const credentials = []; credentials.push(new EnvironmentCredential(tokenCredentialOptions)); credentials.push(new ManagedIdentityCredential(tokenCredentialOptions)); credentials.push(new AzureCliCredential()); diff --git a/sdk/identity/identity/src/credentials/defaultAzureCredential.ts b/sdk/identity/identity/src/credentials/defaultAzureCredential.ts index 32e16241da23..dc1e652454f2 100644 --- a/sdk/identity/identity/src/credentials/defaultAzureCredential.ts +++ b/sdk/identity/identity/src/credentials/defaultAzureCredential.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import { TokenCredentialOptions } from "../client/identityClient"; import { ChainedTokenCredential } from "./chainedTokenCredential"; @@ -7,7 +7,6 @@ import { EnvironmentCredential } from "./environmentCredential"; import { ManagedIdentityCredential } from "./managedIdentityCredential"; import { AzureCliCredential } from "./azureCliCredential"; import { VSCodeCredential } from "./vscodeCredential"; -import { TokenCredential } from "@azure/core-http"; /** * Provides options to configure the default Azure credentials. @@ -37,7 +36,7 @@ export class DefaultAzureCredential extends ChainedTokenCredential { * @param options Options for configuring the client which makes the authentication request. */ constructor(tokenCredentialOptions?: DefaultAzureCredentialOptions) { - let credentials = []; + const credentials = []; credentials.push(new EnvironmentCredential(tokenCredentialOptions)); credentials.push(new ManagedIdentityCredential(tokenCredentialOptions)); if (process.env.AZURE_CLIENT_ID) { diff --git a/sdk/identity/identity/src/credentials/deviceCodeCredential.browser.ts b/sdk/identity/identity/src/credentials/deviceCodeCredential.browser.ts index 545942534de4..eefb62c8556a 100644 --- a/sdk/identity/identity/src/credentials/deviceCodeCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/deviceCodeCredential.browser.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. /* eslint-disable @typescript-eslint/no-unused-vars */ diff --git a/sdk/identity/identity/src/credentials/deviceCodeCredential.ts b/sdk/identity/identity/src/credentials/deviceCodeCredential.ts index 000790b1e23d..4a16db9590c8 100644 --- a/sdk/identity/identity/src/credentials/deviceCodeCredential.ts +++ b/sdk/identity/identity/src/credentials/deviceCodeCredential.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import qs from "qs"; import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http"; diff --git a/sdk/identity/identity/src/credentials/environmentCredential.browser.ts b/sdk/identity/identity/src/credentials/environmentCredential.browser.ts index d4e24a5c73cb..4480d5096a54 100644 --- a/sdk/identity/identity/src/credentials/environmentCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/environmentCredential.browser.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. /* eslint-disable @typescript-eslint/no-unused-vars */ diff --git a/sdk/identity/identity/src/credentials/environmentCredential.ts b/sdk/identity/identity/src/credentials/environmentCredential.ts index 9f1ad9cad15d..c3127d64b8f9 100644 --- a/sdk/identity/identity/src/credentials/environmentCredential.ts +++ b/sdk/identity/identity/src/credentials/environmentCredential.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import { AccessToken, TokenCredential, GetTokenOptions } from "@azure/core-http"; import { TokenCredentialOptions } from "../client/identityClient"; diff --git a/sdk/identity/identity/src/credentials/interactiveBrowserCredential.browser.ts b/sdk/identity/identity/src/credentials/interactiveBrowserCredential.browser.ts index 608e511e7df1..c04c7f990d1b 100644 --- a/sdk/identity/identity/src/credentials/interactiveBrowserCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/interactiveBrowserCredential.browser.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import * as msal from "msal"; import { AccessToken, TokenCredential, GetTokenOptions } from "@azure/core-http"; diff --git a/sdk/identity/identity/src/credentials/interactiveBrowserCredential.ts b/sdk/identity/identity/src/credentials/interactiveBrowserCredential.ts index b8e48a2778ad..accfb595ef5b 100644 --- a/sdk/identity/identity/src/credentials/interactiveBrowserCredential.ts +++ b/sdk/identity/identity/src/credentials/interactiveBrowserCredential.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. /* eslint-disable @typescript-eslint/no-unused-vars */ diff --git a/sdk/identity/identity/src/credentials/interactiveBrowserCredentialOptions.ts b/sdk/identity/identity/src/credentials/interactiveBrowserCredentialOptions.ts index aaaf91f1fbf7..d84bb3a5e751 100644 --- a/sdk/identity/identity/src/credentials/interactiveBrowserCredentialOptions.ts +++ b/sdk/identity/identity/src/credentials/interactiveBrowserCredentialOptions.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import { TokenCredentialOptions } from "../client/identityClient"; diff --git a/sdk/identity/identity/src/credentials/managedIdentityCredential.browser.ts b/sdk/identity/identity/src/credentials/managedIdentityCredential.browser.ts index 1ebf5185d19b..cf2a0bf1d5b2 100644 --- a/sdk/identity/identity/src/credentials/managedIdentityCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/managedIdentityCredential.browser.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. /* eslint-disable @typescript-eslint/no-unused-vars */ diff --git a/sdk/identity/identity/src/credentials/managedIdentityCredential.ts b/sdk/identity/identity/src/credentials/managedIdentityCredential.ts index 642253ff3192..909aeedf88a9 100644 --- a/sdk/identity/identity/src/credentials/managedIdentityCredential.ts +++ b/sdk/identity/identity/src/credentials/managedIdentityCredential.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import qs from "qs"; import { @@ -369,7 +369,7 @@ export class ManagedIdentityCredential implements TokenCredential { message: err.message }); - if (err.code == "ENETUNREACH") { + if (err.code === "ENETUNREACH") { const error = new CredentialUnavailable( "ManagedIdentityCredential is unavailable. No managed identity endpoint found." ); @@ -387,6 +387,7 @@ export class ManagedIdentityCredential implements TokenCredential { "ManagedIdentityCredential is unavailable. No managed identity endpoint found." ); logger.getToken.info(formatError(error)); + // eslint-disable-next-line no-unsafe-finally throw error; } span.end(); diff --git a/sdk/identity/identity/src/credentials/usernamePasswordCredential.ts b/sdk/identity/identity/src/credentials/usernamePasswordCredential.ts index 2859db325a17..e1733cd799a5 100644 --- a/sdk/identity/identity/src/credentials/usernamePasswordCredential.ts +++ b/sdk/identity/identity/src/credentials/usernamePasswordCredential.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import qs from "qs"; import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http"; diff --git a/sdk/identity/identity/src/credentials/vscodeCredential.browser.ts b/sdk/identity/identity/src/credentials/vscodeCredential.browser.ts index 7a95c9a0ac99..402a3d2fa782 100644 --- a/sdk/identity/identity/src/credentials/vscodeCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/vscodeCredential.browser.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. /* eslint-disable @typescript-eslint/no-unused-vars */ diff --git a/sdk/identity/identity/src/credentials/vscodeCredential.ts b/sdk/identity/identity/src/credentials/vscodeCredential.ts index 1a4868a35df8..e48fbba48dcd 100644 --- a/sdk/identity/identity/src/credentials/vscodeCredential.ts +++ b/sdk/identity/identity/src/credentials/vscodeCredential.ts @@ -1,12 +1,13 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. /* eslint-disable @typescript-eslint/no-unused-vars */ import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http"; import { TokenCredentialOptions, IdentityClient } from "../client/identityClient"; +let keytar: any; try { - var keytar = require("keytar"); + keytar = require("keytar"); } catch (er) { keytar = null; } @@ -83,9 +84,9 @@ export class VSCodeCredential implements TokenCredential { scopeString += " offline_access"; } - let refreshToken = await keytar.findPassword(VSCodeUserName); + const refreshToken = await keytar.findPassword(VSCodeUserName); if (refreshToken) { - let tokenResponse = await this.identityClient.refreshAccessToken( + const tokenResponse = await this.identityClient.refreshAccessToken( this.tenantId, AzureAccountClientId, scopeString, diff --git a/sdk/identity/identity/src/index.ts b/sdk/identity/identity/src/index.ts index e817b65bca36..95703a37c06d 100644 --- a/sdk/identity/identity/src/index.ts +++ b/sdk/identity/identity/src/index.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import { TokenCredential } from "@azure/core-http"; import { DefaultAzureCredential } from "./credentials/defaultAzureCredential"; diff --git a/sdk/identity/identity/src/util/authHostEnv.browser.ts b/sdk/identity/identity/src/util/authHostEnv.browser.ts index 0362aee53ff8..1275f06b6ed9 100644 --- a/sdk/identity/identity/src/util/authHostEnv.browser.ts +++ b/sdk/identity/identity/src/util/authHostEnv.browser.ts @@ -1,7 +1,10 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + const BrowserNotSupportedError = new Error( "getAuthorityHostEnvironment is not supported in the browser." ); -export function getAuthorityHostEnvironment() { +export function getAuthorityHostEnvironment(): { authorityHost: string } | undefined { throw BrowserNotSupportedError; } diff --git a/sdk/identity/identity/src/util/authHostEnv.ts b/sdk/identity/identity/src/util/authHostEnv.ts index 75dc218b5978..1f24ae5134f2 100644 --- a/sdk/identity/identity/src/util/authHostEnv.ts +++ b/sdk/identity/identity/src/util/authHostEnv.ts @@ -1,4 +1,7 @@ -export function getAuthorityHostEnvironment() { +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +export function getAuthorityHostEnvironment(): { authorityHost: string } | undefined { if (process.env.AZURE_AUTHORITY_HOST) { return { authorityHost: process.env.AZURE_AUTHORITY_HOST diff --git a/sdk/identity/identity/src/util/delay.ts b/sdk/identity/identity/src/util/delay.ts index 2a6090e37af2..871a855f0d1f 100644 --- a/sdk/identity/identity/src/util/delay.ts +++ b/sdk/identity/identity/src/util/delay.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. let testFunction: ((t: number) => Promise) | undefined; diff --git a/sdk/identity/identity/src/util/logging.ts b/sdk/identity/identity/src/util/logging.ts index 973366cf95f2..73bfb5e1c8d2 100644 --- a/sdk/identity/identity/src/util/logging.ts +++ b/sdk/identity/identity/src/util/logging.ts @@ -1,9 +1,7 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import { createClientLogger, AzureLogger } from "@azure/logger"; -import { TokenCredentialOptions } from "../client/identityClient"; -import { CredentialUnavailable } from "../client/errors"; /** * The AzureLogger used for all clients within the identity package @@ -49,14 +47,14 @@ export function logEnvVars(credentialName: string, supportedEnvVars: string[]): /** * Formatting the success event on the credentials */ -export function formatSuccess(scope: string | string[]) { +export function formatSuccess(scope: string | string[]): string { return `SUCCESS: ${Array.isArray(scope) ? scope.join(", ") : scope}`; } /** * Formatting the success event on the credentials */ -export function formatError(error: Error | string) { +export function formatError(error: Error | string): string { return `ERROR: ${typeof error === "string" ? error : error.message}`; } diff --git a/sdk/identity/identity/src/util/tracing.ts b/sdk/identity/identity/src/util/tracing.ts index 54f98a9a54f9..3471a49495ff 100644 --- a/sdk/identity/identity/src/util/tracing.ts +++ b/sdk/identity/identity/src/util/tracing.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import { GetTokenOptions } from "@azure/core-http"; import { getTracer, OperationTracingOptions } from "@azure/core-tracing"; diff --git a/sdk/identity/identity/test/authTestUtils.ts b/sdk/identity/identity/test/authTestUtils.ts index 04e0f61f3b4b..405a1642d442 100644 --- a/sdk/identity/identity/test/authTestUtils.ts +++ b/sdk/identity/identity/test/authTestUtils.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import assert from "assert"; import { TokenCredentialOptions } from "../src"; diff --git a/sdk/identity/identity/test/chainedTokenCredential.spec.ts b/sdk/identity/identity/test/chainedTokenCredential.spec.ts index fdec1397b822..78fc1dcab9a3 100644 --- a/sdk/identity/identity/test/chainedTokenCredential.spec.ts +++ b/sdk/identity/identity/test/chainedTokenCredential.spec.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import assert from "assert"; import { assertRejects } from "./authTestUtils"; diff --git a/sdk/identity/identity/test/clientSecretCredential.spec.ts b/sdk/identity/identity/test/clientSecretCredential.spec.ts index 990df43bc8d2..6c9fc8097617 100644 --- a/sdk/identity/identity/test/clientSecretCredential.spec.ts +++ b/sdk/identity/identity/test/clientSecretCredential.spec.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import { ClientSecretCredential } from "../src"; import { MockAuthHttpClient, assertClientCredentials } from "./authTestUtils"; diff --git a/sdk/identity/identity/test/errors.spec.ts b/sdk/identity/identity/test/errors.spec.ts index 403fe1c5c7ff..94f3b55721f7 100644 --- a/sdk/identity/identity/test/errors.spec.ts +++ b/sdk/identity/identity/test/errors.spec.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import assert from "assert"; import { AggregateAuthenticationError } from "../src"; diff --git a/sdk/identity/identity/test/identityClient.spec.ts b/sdk/identity/identity/test/identityClient.spec.ts index 7bd8c7de7561..a2024f730ab4 100644 --- a/sdk/identity/identity/test/identityClient.spec.ts +++ b/sdk/identity/identity/test/identityClient.spec.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import assert from "assert"; import { assertRejects } from "./authTestUtils"; @@ -81,6 +81,7 @@ describe("IdentityClient", function() { it("throws an exception when an Env AZURE_AUTHORITY_HOST using 'http' is provided", async function() { if (!isNode) { + // eslint-disable-next-line no-invalid-this return this.skip(); } process.env.AZURE_AUTHORITY_HOST = "http://totallyinsecure.lol"; diff --git a/sdk/identity/identity/test/mockAzureCliCredentialClient.ts b/sdk/identity/identity/test/mockAzureCliCredentialClient.ts index 562cfda3f4c7..186c4ba5cf83 100644 --- a/sdk/identity/identity/test/mockAzureCliCredentialClient.ts +++ b/sdk/identity/identity/test/mockAzureCliCredentialClient.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + import { AzureCliCredential } from "../src/credentials/azureCliCredential"; interface MockCredentialClient { @@ -21,7 +24,7 @@ export class MockAzureCliCredentialClient extends AzureCliCredential { * command. * @param resource The resources to use when accessing token */ - protected getAzureCliAccessToken(resource: string) { + protected getAzureCliAccessToken(_resource: string): Promise<{ stdout: string; stderr: string }> { return new Promise((resolve) => { resolve({ stdout: this.stdout, stderr: this.stderr }); }); diff --git a/sdk/identity/identity/test/node/authorizationCodeCredential.spec.ts b/sdk/identity/identity/test/node/authorizationCodeCredential.spec.ts index 264e0abf7bc4..092bc92a34bf 100644 --- a/sdk/identity/identity/test/node/authorizationCodeCredential.spec.ts +++ b/sdk/identity/identity/test/node/authorizationCodeCredential.spec.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import assert from "assert"; import { AuthorizationCodeCredential } from "../../src"; diff --git a/sdk/identity/identity/test/node/azureCliCredential.spec.ts b/sdk/identity/identity/test/node/azureCliCredential.spec.ts index a601e3664f03..55c65665dd31 100644 --- a/sdk/identity/identity/test/node/azureCliCredential.spec.ts +++ b/sdk/identity/identity/test/node/azureCliCredential.spec.ts @@ -1,22 +1,22 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import assert from "assert"; import { MockAzureCliCredentialClient } from "../mockAzureCliCredentialClient"; describe("AzureCliCredential", function() { it("get access token without error", async function() { - var mockCliCredentialClient = new MockAzureCliCredentialClient({ + const mockCliCredentialClient = new MockAzureCliCredentialClient({ stdout: '{"accessToken": "token","expiresOn": "01/01/1900 00:00:00 +00:00"}', stderr: "" }); - let actualToken = await mockCliCredentialClient.getToken("https://service/.default"); + const actualToken = await mockCliCredentialClient.getToken("https://service/.default"); assert.equal(actualToken!.token, "token"); }); it("get access token when azure cli not installed", async () => { - if (process.platform == "linux" || process.platform == "darwin") { - var mockCliCredentialClient = new MockAzureCliCredentialClient({ + if (process.platform === "linux" || process.platform === "darwin") { + const mockCliCredentialClient = new MockAzureCliCredentialClient({ stdout: "", stderr: "az: command not found" }); @@ -30,7 +30,7 @@ describe("AzureCliCredential", function() { ); } } else { - var mockCliCredentialClient = new MockAzureCliCredentialClient({ + const mockCliCredentialClient = new MockAzureCliCredentialClient({ stdout: "", stderr: "'az' is not recognized" }); @@ -47,7 +47,7 @@ describe("AzureCliCredential", function() { }); it("get access token when azure cli not login in", async () => { - var mockCliCredentialClient = new MockAzureCliCredentialClient({ + const mockCliCredentialClient = new MockAzureCliCredentialClient({ stdout: "", stderr: "Please run 'az login' from a command prompt to authenticate before using this credential." @@ -63,7 +63,7 @@ describe("AzureCliCredential", function() { }); it("get access token when having other access token error", async () => { - var mockCliCredentialClient = new MockAzureCliCredentialClient({ + const mockCliCredentialClient = new MockAzureCliCredentialClient({ stdout: "", stderr: "mock other access token error" }); diff --git a/sdk/identity/identity/test/node/clientCertificateCredential.spec.ts b/sdk/identity/identity/test/node/clientCertificateCredential.spec.ts index 1f43c77f4709..4c8293ba3187 100644 --- a/sdk/identity/identity/test/node/clientCertificateCredential.spec.ts +++ b/sdk/identity/identity/test/node/clientCertificateCredential.spec.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import qs from "qs"; import jws from "jws"; diff --git a/sdk/identity/identity/test/node/deviceCodeCredential.spec.ts b/sdk/identity/identity/test/node/deviceCodeCredential.spec.ts index 8dbcc78c9c49..a0afe142107c 100644 --- a/sdk/identity/identity/test/node/deviceCodeCredential.spec.ts +++ b/sdk/identity/identity/test/node/deviceCodeCredential.spec.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import assert from "assert"; import { TestTracer, setTracer, SpanGraph } from "@azure/core-tracing"; diff --git a/sdk/identity/identity/test/node/environmentCredential.spec.ts b/sdk/identity/identity/test/node/environmentCredential.spec.ts index 0629239d950a..820dbe3ee95b 100644 --- a/sdk/identity/identity/test/node/environmentCredential.spec.ts +++ b/sdk/identity/identity/test/node/environmentCredential.spec.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import assert from "assert"; import path from "path"; diff --git a/sdk/identity/identity/test/node/logger.spec.ts b/sdk/identity/identity/test/node/logger.spec.ts index 2d88951e43a0..c0f935b6f149 100644 --- a/sdk/identity/identity/test/node/logger.spec.ts +++ b/sdk/identity/identity/test/node/logger.spec.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import assert from "assert"; import { @@ -92,7 +92,7 @@ describe("Identity logging utilities", function() { public async getToken( scopes: string | string[], - options?: GetTokenOptions + _options?: GetTokenOptions ): Promise { if (scopes.length) { this.logger.getToken.info(formatSuccess(scopes)); @@ -113,11 +113,10 @@ describe("Identity logging utilities", function() { "FakeCredential => getToken() => SUCCESS: Scope 1, Scope 2" ); - let error: Error | undefined; try { await fakeCredential.getToken([]); - } catch (e) { - error = e; + } catch { + // Nothing to do here } assert.equal( diff --git a/sdk/identity/identity/test/node/managedIdentityCredential.spec.ts b/sdk/identity/identity/test/node/managedIdentityCredential.spec.ts index 8cdc68967da7..ba2ece582754 100644 --- a/sdk/identity/identity/test/node/managedIdentityCredential.spec.ts +++ b/sdk/identity/identity/test/node/managedIdentityCredential.spec.ts @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import qs from "qs"; import assert from "assert"; -import { ManagedIdentityCredential, AuthenticationError, CredentialUnavailable } from "../../src"; +import { ManagedIdentityCredential, AuthenticationError } from "../../src"; import { ImdsEndpoint, ImdsApiVersion, diff --git a/sdk/identity/identity/test/usernamePasswordCredential.spec.ts b/sdk/identity/identity/test/usernamePasswordCredential.spec.ts index 2053ff7a303f..3c038f8725f5 100644 --- a/sdk/identity/identity/test/usernamePasswordCredential.spec.ts +++ b/sdk/identity/identity/test/usernamePasswordCredential.spec.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. +// Licensed under the MIT license. import assert from "assert"; import { UsernamePasswordCredential } from "../src"; diff --git a/sdk/identity/identity/tsconfig.json b/sdk/identity/identity/tsconfig.json index 281793c5edd8..98599cad42f2 100644 --- a/sdk/identity/identity/tsconfig.json +++ b/sdk/identity/identity/tsconfig.json @@ -54,5 +54,5 @@ "forceConsistentCasingInFileNames": true }, "include": ["src/**/*", "test/*", "test/manual/**/*", "test/node/**/*"], - "exclude": ["test/manual"] + "exclude": ["test/manual", "node_modules"] }