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..ef6520f4a4a3 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.message); +} + /** * 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, 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( tenantId: string | "organizations", clientId: string, - userPromptCallback: DeviceCodePromptCallback, + userPromptCallback: DeviceCodePromptCallback = defaultDeviceCodePromptCallback, options?: TokenCredentialOptions ) { this.identityClient = new IdentityClient(options);