diff --git a/sdk/identity/identity/review/identity.api.md b/sdk/identity/identity/review/identity.api.md index 9854513c0799..4c661f5c448c 100644 --- a/sdk/identity/identity/review/identity.api.md +++ b/sdk/identity/identity/review/identity.api.md @@ -57,7 +57,11 @@ export enum AzureAuthorityHosts { // @public export class AzureCliCredential implements TokenCredential { - protected getAzureCliAccessToken(resource: string): Promise; + protected getAzureCliAccessToken(resource: string): Promise<{ + stdout: string; + stderr: string; + error: Error | null; + }>; getToken(scopes: string | string[], options?: GetTokenOptions): Promise; } @@ -143,7 +147,7 @@ export { GetTokenOptions } // @public export class InteractiveBrowserCredential implements TokenCredential { constructor(options?: InteractiveBrowserCredentialOptions); - getToken(scopes: string | string[], options?: GetTokenOptions): Promise; + getToken(scopes: string | string[], _options?: GetTokenOptions): Promise; } // @public @@ -188,7 +192,7 @@ export class UsernamePasswordCredential implements TokenCredential { // @public export class VisualStudioCodeCredential implements TokenCredential { constructor(options?: VisualStudioCodeCredentialOptions); - getToken(scopes: string | string[], options?: GetTokenOptions): Promise; + getToken(scopes: string | string[], _options?: GetTokenOptions): Promise; } // @public diff --git a/sdk/identity/identity/src/client/identityClient.ts b/sdk/identity/identity/src/client/identityClient.ts index 9911fbb23e0f..7fd8a0a21ab8 100644 --- a/sdk/identity/identity/src/client/identityClient.ts +++ b/sdk/identity/identity/src/client/identityClient.ts @@ -10,11 +10,7 @@ import { RequestPrepareOptions, GetTokenOptions, createPipelineFromOptions, - isNode, - OperationArguments, - OperationSpec, - RawHttpHeaders, - HttpHeaders + isNode } from "@azure/core-http"; import { INetworkModule, NetworkRequestOptions, NetworkResponse } from "@azure/msal-node"; diff --git a/sdk/identity/identity/src/credentials/authorizationCodeCredential.browser.ts b/sdk/identity/identity/src/credentials/authorizationCodeCredential.browser.ts index db071506261a..a15d10568e4a 100644 --- a/sdk/identity/identity/src/credentials/authorizationCodeCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/authorizationCodeCredential.browser.ts @@ -1,9 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable @typescript-eslint/no-unused-vars */ - -import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http"; +import { TokenCredential, AccessToken } from "@azure/core-http"; import { TokenCredentialOptions } from "../client/identityClient"; import { credentialLogger, formatError } from "../util/logging"; @@ -28,22 +26,12 @@ export class AuthorizationCodeCredential implements TokenCredential { redirectUri: string, options?: TokenCredentialOptions ); - constructor( - tenantId: string | "common", - clientId: string, - clientSecretOrAuthorizationCode: string, - authorizationCodeOrRedirectUri: string, - redirectUriOrOptions: string | TokenCredentialOptions | undefined, - options?: TokenCredentialOptions - ) { + constructor() { logger.info(formatError(BrowserNotSupportedError)); throw BrowserNotSupportedError; } - public getToken( - scopes: string | string[], - options?: GetTokenOptions - ): Promise { + public getToken(): Promise { logger.getToken.info(formatError(BrowserNotSupportedError)); throw BrowserNotSupportedError; } diff --git a/sdk/identity/identity/src/credentials/azureCliCredential.browser.ts b/sdk/identity/identity/src/credentials/azureCliCredential.browser.ts index 26846879d885..0392517e365e 100644 --- a/sdk/identity/identity/src/credentials/azureCliCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/azureCliCredential.browser.ts @@ -1,22 +1,19 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable @typescript-eslint/no-unused-vars */ - -import { AccessToken, TokenCredential, GetTokenOptions } from "@azure/core-http"; -import { TokenCredentialOptions } from "../client/identityClient"; +import { AccessToken, TokenCredential } from "@azure/core-http"; import { credentialLogger, formatError } from "../util/logging"; const BrowserNotSupportedError = new Error("AzureCliCredential is not supported in the browser."); const logger = credentialLogger("AzureCliCredential"); export class AzureCliCredential implements TokenCredential { - constructor(options?: TokenCredentialOptions) { + constructor() { logger.info(formatError(BrowserNotSupportedError)); throw BrowserNotSupportedError; } - getToken(scopes: string | string[], options?: GetTokenOptions): Promise { + getToken(): Promise { logger.getToken.info(formatError(BrowserNotSupportedError)); throw BrowserNotSupportedError; } diff --git a/sdk/identity/identity/src/credentials/azureCliCredential.ts b/sdk/identity/identity/src/credentials/azureCliCredential.ts index 9414fe2028a2..fbd8d8b2d2ed 100644 --- a/sdk/identity/identity/src/credentials/azureCliCredential.ts +++ b/sdk/identity/identity/src/credentials/azureCliCredential.ts @@ -34,14 +34,16 @@ export class AzureCliCredential implements TokenCredential { * Gets the access token from Azure CLI * @param resource The resource to use when getting the token */ - protected async getAzureCliAccessToken(resource: string) { + protected async getAzureCliAccessToken( + resource: string + ): Promise<{ stdout: string; stderr: string; error: Error | null }> { return new Promise((resolve, reject) => { try { child_process.exec( `az account get-access-token --output json --resource ${resource}`, { cwd: getSafeWorkingDir() }, (error, stdout, stderr) => { - resolve({ stdout: stdout, stderr: stderr }); + resolve({ stdout: stdout, stderr: stderr, error }); } ); } catch (err) { diff --git a/sdk/identity/identity/src/credentials/clientCertificateCredential.browser.ts b/sdk/identity/identity/src/credentials/clientCertificateCredential.browser.ts index 45ade7b02d53..1bfaaab5a8be 100644 --- a/sdk/identity/identity/src/credentials/clientCertificateCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/clientCertificateCredential.browser.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable @typescript-eslint/no-unused-vars */ - -import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http"; -import { TokenCredentialOptions } from "../client/identityClient"; +import { TokenCredential, AccessToken } from "@azure/core-http"; import { credentialLogger, formatError } from "../util/logging"; const BrowserNotSupportedError = new Error( @@ -13,20 +10,12 @@ const BrowserNotSupportedError = new Error( const logger = credentialLogger("ClientCertificateCredential"); export class ClientCertificateCredential implements TokenCredential { - constructor( - tenantId: string, - clientId: string, - certificatePath: string, - options?: TokenCredentialOptions - ) { + constructor() { logger.info(formatError(BrowserNotSupportedError)); throw BrowserNotSupportedError; } - public getToken( - scopes: string | string[], - options?: GetTokenOptions - ): Promise { + public getToken(): Promise { logger.getToken.info(formatError(BrowserNotSupportedError)); throw BrowserNotSupportedError; } diff --git a/sdk/identity/identity/src/credentials/deviceCodeCredential.browser.ts b/sdk/identity/identity/src/credentials/deviceCodeCredential.browser.ts index eefb62c8556a..0b7ff7f9b716 100644 --- a/sdk/identity/identity/src/credentials/deviceCodeCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/deviceCodeCredential.browser.ts @@ -1,31 +1,19 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable @typescript-eslint/no-unused-vars */ - -import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http"; -import { DeviceCodePromptCallback } from "./deviceCodeCredential"; -import { TokenCredentialOptions } from "../client/identityClient"; +import { TokenCredential, AccessToken } from "@azure/core-http"; import { credentialLogger, formatError } from "../util/logging"; const BrowserNotSupportedError = new Error("DeviceCodeCredential is not supported in the browser."); const logger = credentialLogger("DeviceCodeCredential"); export class DeviceCodeCredential implements TokenCredential { - constructor( - tenantId: string | "organizations", - clientId: string, - userPromptCallback: DeviceCodePromptCallback, - options?: TokenCredentialOptions - ) { + constructor() { logger.info(formatError(BrowserNotSupportedError)); throw BrowserNotSupportedError; } - public getToken( - scopes: string | string[], - options?: GetTokenOptions - ): Promise { + public getToken(): Promise { logger.getToken.info(formatError(BrowserNotSupportedError)); throw BrowserNotSupportedError; } diff --git a/sdk/identity/identity/src/credentials/deviceCodeCredential.ts b/sdk/identity/identity/src/credentials/deviceCodeCredential.ts index 09611877d7c9..116dfd87a464 100644 --- a/sdk/identity/identity/src/credentials/deviceCodeCredential.ts +++ b/sdk/identity/identity/src/credentials/deviceCodeCredential.ts @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { AccessToken, TokenCredential, GetTokenOptions, delay } from "@azure/core-http"; -import { TokenCredentialOptions, IdentityClient } from "../client/identityClient"; +import { AccessToken, TokenCredential, GetTokenOptions } from "@azure/core-http"; +import { TokenCredentialOptions } from "../client/identityClient"; import { createSpan } from "../util/tracing"; -import { credentialLogger, formatSuccess } from "../util/logging"; -import { AuthenticationError, AuthenticationErrorName } from "../client/errors"; +import { credentialLogger } from "../util/logging"; +import { AuthenticationErrorName } from "../client/errors"; import { CanonicalCode } from "@opentelemetry/api"; import { PublicClientApplication, DeviceCodeRequest } from "@azure/msal-node"; @@ -55,7 +55,6 @@ export function defaultDeviceCodePromptCallback(deviceCodeInfo: DeviceCodeInfo): * that the user can enter into https://microsoft.com/devicelogin. */ export class DeviceCodeCredential implements TokenCredential { - private identityClient: IdentityClient; private pca: PublicClientApplication; private tenantId: string; private clientId: string; @@ -79,7 +78,6 @@ export class DeviceCodeCredential implements TokenCredential { userPromptCallback: DeviceCodePromptCallback = defaultDeviceCodePromptCallback, options?: TokenCredentialOptions ) { - this.identityClient = new IdentityClient(options); this.tenantId = tenantId; this.clientId = clientId; this.userPromptCallback = userPromptCallback; @@ -120,7 +118,7 @@ export class DeviceCodeCredential implements TokenCredential { * TokenCredential implementation might make. */ getToken(scopes: string | string[], options?: GetTokenOptions): Promise { - const { span, options: newOptions } = createSpan("DeviceCodeCredential-getToken", options); + const { span } = createSpan("DeviceCodeCredential-getToken", options); const scopeArray = typeof scopes === "object" ? scopes : [scopes]; diff --git a/sdk/identity/identity/src/credentials/environmentCredential.browser.ts b/sdk/identity/identity/src/credentials/environmentCredential.browser.ts index 4480d5096a54..fef81c8658f1 100644 --- a/sdk/identity/identity/src/credentials/environmentCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/environmentCredential.browser.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable @typescript-eslint/no-unused-vars */ - -import { AccessToken, TokenCredential, GetTokenOptions } from "@azure/core-http"; -import { TokenCredentialOptions } from "../client/identityClient"; +import { AccessToken, TokenCredential } from "@azure/core-http"; import { credentialLogger, formatError } from "../util/logging"; const BrowserNotSupportedError = new Error( @@ -13,12 +10,12 @@ const BrowserNotSupportedError = new Error( const logger = credentialLogger("EnvironmentCredential"); export class EnvironmentCredential implements TokenCredential { - constructor(options?: TokenCredentialOptions) { + constructor() { logger.info(formatError(BrowserNotSupportedError)); throw BrowserNotSupportedError; } - getToken(scopes: string | string[], options?: GetTokenOptions): Promise { + getToken(): Promise { logger.getToken.info(formatError(BrowserNotSupportedError)); throw BrowserNotSupportedError; } diff --git a/sdk/identity/identity/src/credentials/interactiveBrowserCredential.ts b/sdk/identity/identity/src/credentials/interactiveBrowserCredential.ts index 7cc397f5edf0..0d22005d8d9b 100644 --- a/sdk/identity/identity/src/credentials/interactiveBrowserCredential.ts +++ b/sdk/identity/identity/src/credentials/interactiveBrowserCredential.ts @@ -8,8 +8,8 @@ import { InteractiveBrowserCredentialOptions, AuthenticationRecord } from "./interactiveBrowserCredentialOptions"; -import { credentialLogger, formatError } from "../util/logging"; -import { TokenCredentialOptions, IdentityClient } from "../client/identityClient"; +import { credentialLogger } from "../util/logging"; +import { IdentityClient } from "../client/identityClient"; import { DefaultTenantId, DeveloperSignOnClientId } from "../constants"; import { Socket } from "net"; @@ -21,7 +21,6 @@ import { Configuration } from "@azure/msal-node"; import open from "open"; -import path from "path"; import http from "http"; import { CredentialUnavailable } from "../client/errors"; @@ -108,7 +107,7 @@ export class InteractiveBrowserCredential implements TokenCredential { */ public getToken( scopes: string | string[], - options?: GetTokenOptions + _options?: GetTokenOptions ): Promise { const scopeArray = typeof scopes === "object" ? scopes : [scopes]; diff --git a/sdk/identity/identity/src/credentials/managedIdentityCredential.browser.ts b/sdk/identity/identity/src/credentials/managedIdentityCredential.browser.ts index cf2a0bf1d5b2..30d82e0dc79a 100644 --- a/sdk/identity/identity/src/credentials/managedIdentityCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/managedIdentityCredential.browser.ts @@ -1,9 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable @typescript-eslint/no-unused-vars */ - -import { AccessToken, GetTokenOptions, TokenCredential } from "@azure/core-http"; +import { AccessToken, TokenCredential } from "@azure/core-http"; import { TokenCredentialOptions } from "../client/identityClient"; import { credentialLogger, formatError } from "../util/logging"; @@ -15,18 +13,12 @@ const logger = credentialLogger("ManagedIdentityCredential"); export class ManagedIdentityCredential implements TokenCredential { constructor(clientId: string, options?: TokenCredentialOptions); constructor(options?: TokenCredentialOptions); - constructor( - clientIdOrOptions: string | TokenCredentialOptions | undefined, - options?: TokenCredentialOptions - ) { + constructor() { logger.info(formatError(BrowserNotSupportedError)); throw BrowserNotSupportedError; } - public async getToken( - scopes: string | string[], - options?: GetTokenOptions - ): Promise { + public async getToken(): Promise { logger.getToken.info(formatError(BrowserNotSupportedError)); throw BrowserNotSupportedError; } diff --git a/sdk/identity/identity/src/credentials/visualStudioCodeCredential.browser.ts b/sdk/identity/identity/src/credentials/visualStudioCodeCredential.browser.ts index bcca54b30ab3..9cb4b1315a21 100644 --- a/sdk/identity/identity/src/credentials/visualStudioCodeCredential.browser.ts +++ b/sdk/identity/identity/src/credentials/visualStudioCodeCredential.browser.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable @typescript-eslint/no-unused-vars */ - -import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http"; -import { TokenCredentialOptions } from "../client/identityClient"; +import { TokenCredential, AccessToken } from "@azure/core-http"; import { credentialLogger, formatError } from "../util/logging"; const BrowserNotSupportedError = new Error( @@ -13,15 +10,12 @@ const BrowserNotSupportedError = new Error( const logger = credentialLogger("VisualStudioCodeCredential"); export class VisualStudioCodeCredential implements TokenCredential { - constructor(options?: TokenCredentialOptions) { + constructor() { logger.info(formatError(BrowserNotSupportedError)); throw BrowserNotSupportedError; } - public getToken( - scopes: string | string[], - options?: GetTokenOptions - ): Promise { + public getToken(): Promise { logger.getToken.info(formatError(BrowserNotSupportedError)); throw BrowserNotSupportedError; } diff --git a/sdk/identity/identity/src/credentials/visualStudioCodeCredential.ts b/sdk/identity/identity/src/credentials/visualStudioCodeCredential.ts index 2e91cb349add..355fd58c0281 100644 --- a/sdk/identity/identity/src/credentials/visualStudioCodeCredential.ts +++ b/sdk/identity/identity/src/credentials/visualStudioCodeCredential.ts @@ -1,9 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable @typescript-eslint/no-unused-vars */ - -import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http"; +import { TokenCredential, AccessToken, GetTokenOptions } from "@azure/core-http"; import { TokenCredentialOptions, IdentityClient } from "../client/identityClient"; import fs from "fs"; import os from "os"; @@ -144,7 +142,7 @@ export class VisualStudioCodeCredential implements TokenCredential { */ public async getToken( scopes: string | string[], - options?: GetTokenOptions + _options?: GetTokenOptions ): Promise { await this.prepareOnce(); if (!keytar) { diff --git a/sdk/identity/identity/test/internal/identityClient.spec.ts b/sdk/identity/identity/test/internal/identityClient.spec.ts index cde857eb8026..afb485016885 100644 --- a/sdk/identity/identity/test/internal/identityClient.spec.ts +++ b/sdk/identity/identity/test/internal/identityClient.spec.ts @@ -105,6 +105,8 @@ describe("IdentityClient", function() { assert(new IdentityClient({ authorityHost: "https://correct.url" })); delete process.env.AZURE_AUTHORITY_HOST; + + return; }); it("returns a usable error when the authentication response doesn't contain a body", async () => { diff --git a/sdk/identity/identity/test/mockAzureCliCredentialClient.ts b/sdk/identity/identity/test/mockAzureCliCredentialClient.ts index fe349e50fd5d..222b378ca5bb 100644 --- a/sdk/identity/identity/test/mockAzureCliCredentialClient.ts +++ b/sdk/identity/identity/test/mockAzureCliCredentialClient.ts @@ -24,9 +24,11 @@ export class MockAzureCliCredentialClient extends AzureCliCredential { * command. * @param resource The resources to use when accessing token */ - protected getAzureCliAccessToken(_resource: string): Promise<{ stdout: string; stderr: string }> { + protected getAzureCliAccessToken( + _resource: string + ): Promise<{ stdout: string; stderr: string; error: Error | null }> { return new Promise((resolve) => { - resolve({ stdout: this.stdout, stderr: this.stderr }); + resolve({ stdout: this.stdout, stderr: this.stderr, error: null }); }); } } diff --git a/sdk/identity/identity/tsconfig.json b/sdk/identity/identity/tsconfig.json index b4b1163d62db..a7b400342680 100644 --- a/sdk/identity/identity/tsconfig.json +++ b/sdk/identity/identity/tsconfig.json @@ -5,10 +5,7 @@ "lib": ["DOM"], "declarationDir": "./types", "outDir": "./dist-esm", - "resolveJsonModule": true, - "noUnusedLocals": false, - "noUnusedParameters": false, - "noImplicitReturns": false + "resolveJsonModule": true }, "include": ["src/**/*", "test/**/*"], "exclude": ["test/manual*/**/*", "node_modules"]