From ba18b0b999796462e1f1e2e444c985c749b0a997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Rodr=C3=ADguez?= Date: Sat, 19 Sep 2020 12:05:44 -0400 Subject: [PATCH 1/2] [Identity] Idea for the Device Code Credential Use Console Feature --- sdk/identity/identity/review/identity.api.md | 4 ++-- .../identity/src/credentials/deviceCodeCredential.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/sdk/identity/identity/review/identity.api.md b/sdk/identity/identity/review/identity.api.md index 94b13dadaafa..8acaeb7b504c 100644 --- a/sdk/identity/identity/review/identity.api.md +++ b/sdk/identity/identity/review/identity.api.md @@ -96,7 +96,7 @@ export interface DefaultAzureCredentialOptions extends TokenCredentialOptions { // @public export class DeviceCodeCredential implements TokenCredential { - constructor(tenantId: string | "organizations", clientId: string, userPromptCallback: DeviceCodePromptCallback, options?: TokenCredentialOptions); + constructor(tenantId: string | "organizations", clientId: string, userPromptCallback?: DeviceCodePromptCallback, options?: TokenCredentialOptions); getToken(scopes: string | string[], options?: GetTokenOptions): Promise; } @@ -135,7 +135,7 @@ export { GetTokenOptions } export class InteractiveBrowserCredential implements TokenCredential { constructor(options?: InteractiveBrowserCredentialOptions); getToken(scopes: string | string[], options?: GetTokenOptions): Promise; -} + } // @public export interface InteractiveBrowserCredentialOptions extends TokenCredentialOptions { diff --git a/sdk/identity/identity/src/credentials/deviceCodeCredential.ts b/sdk/identity/identity/src/credentials/deviceCodeCredential.ts index 9598ffbb928c..b1fb3e935f79 100644 --- a/sdk/identity/identity/src/credentials/deviceCodeCredential.ts +++ b/sdk/identity/identity/src/credentials/deviceCodeCredential.ts @@ -42,6 +42,14 @@ export type DeviceCodePromptCallback = (deviceCodeInfo: DeviceCodeInfo) => void; const logger = credentialLogger("DeviceCodeCredential"); +/** + * Method that logs the user code from the DeviceCodeCredential. + * @param deviceCodeInfo The device code. + */ +export function defaultDeviceCodePromptCallback(deviceCodeInfo: DeviceCodeInfo): void { + console.log(deviceCodeInfo.userCode); +} + /** * Enables authentication to Azure Active Directory using a device code * that the user can enter into https://microsoft.com/devicelogin. @@ -62,13 +70,13 @@ export class DeviceCodeCredential implements TokenCredential { * 'organizations' may be used when dealing with multi-tenant scenarios. * @param clientId The client (application) ID of an App Registration in the tenant. * @param userPromptCallback A callback function that will be invoked to show - {@link DeviceCodeInfo} to the user. + {@link DeviceCodeInfo} to the user. If left unassigned, a function will automatically log the user code in the console. * @param options Options for configuring the client which makes the authentication request. */ constructor( tenantId: string | "organizations", clientId: string, - userPromptCallback: DeviceCodePromptCallback, + userPromptCallback: DeviceCodePromptCallback = defaultDeviceCodePromptCallback, options?: TokenCredentialOptions ) { this.identityClient = new IdentityClient(options); From 9e436187edb34f03c917476bdce88f526a950bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Rodr=C3=ADguez?= Date: Mon, 21 Sep 2020 16:24:26 -0400 Subject: [PATCH 2/2] Feedback by Schaab and Vinay --- sdk/identity/identity/src/credentials/deviceCodeCredential.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/identity/identity/src/credentials/deviceCodeCredential.ts b/sdk/identity/identity/src/credentials/deviceCodeCredential.ts index b1fb3e935f79..ef6520f4a4a3 100644 --- a/sdk/identity/identity/src/credentials/deviceCodeCredential.ts +++ b/sdk/identity/identity/src/credentials/deviceCodeCredential.ts @@ -47,7 +47,7 @@ const logger = credentialLogger("DeviceCodeCredential"); * @param deviceCodeInfo The device code. */ export function defaultDeviceCodePromptCallback(deviceCodeInfo: DeviceCodeInfo): void { - console.log(deviceCodeInfo.userCode); + console.log(deviceCodeInfo.message); } /** @@ -70,7 +70,7 @@ export class DeviceCodeCredential implements TokenCredential { * 'organizations' may be used when dealing with multi-tenant scenarios. * @param clientId The client (application) ID of an App Registration in the tenant. * @param userPromptCallback A callback function that will be invoked to show - {@link DeviceCodeInfo} to the user. If left unassigned, a function will automatically log the user code in the console. + {@link DeviceCodeInfo} to the user. If left unassigned, we will automatically log the device code information and the authentication instructions in the console. * @param options Options for configuring the client which makes the authentication request. */ constructor(