Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/identity/identity/review/identity.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class UsernamePasswordCredential implements TokenCredential {
// @public
export class VisualStudioCodeCredential implements TokenCredential {
constructor(options?: VisualStudioCodeCredentialOptions);
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
getToken(scopes: string | string[]): Promise<AccessToken | null>;
Comment thread
mohsin-mehmood marked this conversation as resolved.
Outdated
}

// @public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/* eslint-disable @typescript-eslint/no-unused-vars */
Comment thread
mohsin-mehmood marked this conversation as resolved.
Outdated

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";

Expand All @@ -28,22 +28,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<AccessToken | null> {
public getToken(): Promise<AccessToken | null> {
logger.getToken.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@

/* 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<AccessToken | null> {
getToken(): Promise<AccessToken | null> {
logger.getToken.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class AzureCliCredential implements TokenCredential {
`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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

/* 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(
Expand All @@ -13,20 +12,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<AccessToken | null> {
public getToken(): Promise<AccessToken | null> {
logger.getToken.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,19 @@

/* 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<AccessToken | null> {
public getToken(): Promise<AccessToken | null> {
logger.getToken.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}
Expand Down
12 changes: 5 additions & 7 deletions sdk/identity/identity/src/credentials/deviceCodeCredential.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -117,7 +115,7 @@ export class DeviceCodeCredential implements TokenCredential {
* TokenCredential implementation might make.
*/
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null> {
const { span, options: newOptions } = createSpan("DeviceCodeCredential-getToken", options);
const { span } = createSpan("DeviceCodeCredential-getToken", options);

const scopeArray = typeof scopes === "object" ? scopes : [scopes];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

/* 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(
Expand All @@ -13,12 +12,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<AccessToken | null> {
getToken(): Promise<AccessToken | null> {
logger.getToken.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

/* eslint-disable @typescript-eslint/no-unused-vars */

import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
import { TokenCredential, AccessToken, GetTokenOptions } from "@azure/core-http";
import { InteractiveBrowserCredentialOptions } from "./interactiveBrowserCredentialOptions";
import { credentialLogger, formatError } from "../util/logging";
import { TokenCredentialOptions, IdentityClient } from "../client/identityClient";
import { credentialLogger } from "../util/logging";
import { DefaultTenantId, DeveloperSignOnClientId } from "../constants";
import { Socket } from "net";

Expand All @@ -15,46 +14,30 @@ const SERVER_PORT = process.env.PORT || 80;
import express from "express";
import { PublicClientApplication, TokenCache, AuthorizationCodeRequest } from "@azure/msal-node";
import open from "open";
import path from "path";
import http from "http";

const BrowserNotSupportedError = new Error(
"InteractiveBrowserCredential is not supported in Node.js."
);
const logger = credentialLogger("InteractiveBrowserCredential");

interface AuthenticationRecord {
authority?: string;
homeAccountId: string;
environment: string;
tenantId: string;
username: string;
}

/**
* Enables authentication to Azure Active Directory inside of the web browser
* using the interactive login flow, either via browser redirects or a popup
* window. This credential is not currently supported in Node.js.
*/
export class InteractiveBrowserCredential implements TokenCredential {
private identityClient: IdentityClient;
private pca: PublicClientApplication;
private msalCacheManager: TokenCache;
private tenantId: string;
private clientId: string;
private persistenceEnabled: boolean;
private redirectUri: string;
private authorityHost: string;
private authenticationRecord: AuthenticationRecord | undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jonathandturner This was added in #10994
Was curious as to how you envisioned this being used as it is currently unused

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mohsin Mehmood (@mohsin-mehmood) Looks like the latest changes in the master branch do make use of the authenticationRecord. Can you pull in the changes from master and update the PR?


constructor(options?: InteractiveBrowserCredentialOptions) {
this.identityClient = new IdentityClient(options);
this.tenantId = (options && options.tenantId) || DefaultTenantId;
this.clientId = (options && options.clientId) || DeveloperSignOnClientId;

// Future update: this is for persistent caching
this.persistenceEnabled = false;
this.authenticationRecord = undefined;

if (options && options.redirectUri) {
if (typeof options.redirectUri === "string") {
Expand Down Expand Up @@ -100,6 +83,7 @@ export class InteractiveBrowserCredential implements TokenCredential {
*/
public getToken(
scopes: string | string[],
//@ts-ignore
Comment thread
mohsin-mehmood marked this conversation as resolved.
Outdated
options?: GetTokenOptions
): Promise<AccessToken | null> {
const scopeArray = typeof scopes === "object" ? scopes : [scopes];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/* 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";

Expand All @@ -15,18 +15,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<AccessToken | null> {
public async getToken(): Promise<AccessToken | null> {
logger.getToken.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

/* 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(
Expand All @@ -13,15 +12,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<AccessToken | null> {
public getToken(): Promise<AccessToken | null> {
logger.getToken.info(formatError(BrowserNotSupportedError));
throw BrowserNotSupportedError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/* eslint-disable @typescript-eslint/no-unused-vars */

import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-http";
import { TokenCredential, AccessToken } from "@azure/core-http";
import { TokenCredentialOptions, IdentityClient } from "../client/identityClient";
import fs from "fs";
import os from "os";
Expand Down Expand Up @@ -140,10 +140,7 @@ export class VisualStudioCodeCredential implements TokenCredential {
* @param options The options used to configure any requests this
* `TokenCredential` implementation might make.
*/
public async getToken(
scopes: string | string[],
options?: GetTokenOptions
): Promise<AccessToken | null> {
public async getToken(scopes: string | string[]): Promise<AccessToken | null> {
await this.prepareOnce();
if (!keytar) {
throw new CredentialUnavailable(
Expand Down
2 changes: 2 additions & 0 deletions sdk/identity/identity/test/internal/identityClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
6 changes: 3 additions & 3 deletions sdk/identity/identity/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"declarationDir": "./types",
"outDir": "./dist-esm",
"resolveJsonModule": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": false
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true
Comment thread
mohsin-mehmood marked this conversation as resolved.
Outdated
},
"include": ["src/**/*", "test/**/*"],
"exclude": ["test/manual*/**/*", "node_modules"]
Expand Down