Skip to content

[Identity] MSAL integration for interactive browser and device code#10994

Merged
sophiajt merged 12 commits into
Azure:masterfrom
sophiajt:msal_integration
Sep 3, 2020
Merged

[Identity] MSAL integration for interactive browser and device code#10994
sophiajt merged 12 commits into
Azure:masterfrom
sophiajt:msal_integration

Conversation

@sophiajt
Copy link
Copy Markdown
Contributor

@sophiajt sophiajt commented Sep 2, 2020

This integrates @azure/msal-node for handling interactive browser (in Node) and device code credentials.

Interactive browser

The interactive browser credential works by creating an http server that will handle the auth code redirection, opening a web browser for the auth code authentication, and then passing the information received via the redirect to MSAL to complete the authorization. Once authorized, we use the access token as normal.

Device code

The MSAL-based device code credential works similarly to our previous version. The developer can pass in a callback we'll invoke that describes the steps to use for device code authentication and then will wait until the device code was received. The logic for device code is largely based in MSAL itself, with the Azure SDK side acting largely as a shim that fits with our existing API design.

Note: This should be considered this an initial implementation as future features, like caching, are planned and should follow after the first beta release. We're also planning to do a mock testing using the http mock once we enable configuring the http request pipeline.

if (tokenResponse === null) {
const deviceCodeResponse = await this.sendDeviceCodeRequest(scopeString, newOptions);
const deviceCodeRequest = {
deviceCodeCallback: this.userPromptCallback,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm assuming our DeviceCodePromptCallback type has the same shape as the what's expected by deviceCodeCallback?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not quite sure what you're asking here

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm saying the DeviceCodeCredential takes userPromptCallback: DeviceCodePromptCallback, on construction. Here we're passing the callback directly to acquireTokenByDeviceCode. These callbacks have the same shape? Mostly I wanted to make sure we weren't exporting types from MSAL.

Copy link
Copy Markdown
Contributor Author

@sophiajt sophiajt Sep 2, 2020

Choose a reason for hiding this comment

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

Yup, they're different though compatible in this direction.

Here's the MSAL version:

export declare type DeviceCodeResponse = {
    userCode: string;
    deviceCode: string;
    verificationUri: string;
    expiresIn: number;
    interval: number;
    message: string;
};

And here's the identity version:

export interface DeviceCodeInfo {
  /**
   * The device code that the user must enter into the verification page.
   */
  userCode: string;

  /**
   * The verification URI to which the user must navigate to enter the device
   * code.
   */
  verificationUri: string;

  /**
   * A message that may be shown to the user to instruct them on how to enter
   * the device code in the page specified by the verification URI.
   */
  message: string;
}

Comment thread sdk/identity/identity/src/credentials/interactiveBrowserCredential.ts Outdated
Comment thread sdk/identity/identity/src/credentials/interactiveBrowserCredential.ts Outdated
Comment thread sdk/identity/identity/src/credentials/interactiveBrowserCredential.ts Outdated
Copy link
Copy Markdown
Contributor

@sadasant sadasant left a comment

Choose a reason for hiding this comment

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

This is good on the Key Vault part. Thank you!

Comment thread sdk/identity/identity/src/credentials/deviceCodeCredential.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants