Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Identity] Device Code Credential's Use Console Feature #11355

Merged
merged 2 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions sdk/identity/identity/review/identity.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccessToken | null>;
}

Expand Down Expand Up @@ -135,7 +135,7 @@ export { GetTokenOptions }
export class InteractiveBrowserCredential implements TokenCredential {
constructor(options?: InteractiveBrowserCredentialOptions);
getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this move?

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it's an api extractor thing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it's an API extractor thing. This wasn't linting nor prettier.


// @public
export interface InteractiveBrowserCredentialOptions extends TokenCredentialOptions {
Expand Down
12 changes: 10 additions & 2 deletions sdk/identity/identity/src/credentials/deviceCodeCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down