Skip to content

Commit

Permalink
[identity] Enable browser customization for web view (#27444)
Browse files Browse the repository at this point in the history
  • Loading branch information
KarishmaGhiya committed Oct 23, 2023
1 parent 6d7f635 commit f814d7d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
11 changes: 10 additions & 1 deletion sdk/identity/identity/review/identity.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ export interface AzurePowerShellCredentialOptions extends MultiTenantTokenCreden
tenantId?: string;
}

// @public
export interface BrowserCustomizationOptions {
// (undocumented)
browserCustomizationOptions?: {
errorMessage: string;
successMessage: string;
};
}

// @public
export type BrowserLoginStyle = "redirect" | "popup";

Expand Down Expand Up @@ -282,7 +291,7 @@ export interface InteractiveBrowserCredentialInBrowserOptions extends Interactiv
}

// @public
export interface InteractiveBrowserCredentialNodeOptions extends InteractiveCredentialOptions, CredentialPersistenceOptions {
export interface InteractiveBrowserCredentialNodeOptions extends InteractiveCredentialOptions, CredentialPersistenceOptions, BrowserCustomizationOptions {
clientId?: string;
loginHint?: string;
redirectUri?: string | (() => string);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

/**
* Shared configuration options for browser customization
*/
export interface BrowserCustomizationOptions {
browserCustomizationOptions?: {
/**
* Format for error messages for display in browser
*/
errorMessage: string;
/**
* Format for success messages for display in browser
*/
successMessage: string;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export class InteractiveBrowserCredential implements TokenCredential {
tokenCredentialOptions: options,
logger,
redirectUri,
browserCustomizationOptions: (options as InteractiveBrowserCredentialNodeOptions)
.browserCustomizationOptions,
});
this.disableAutomaticAuthentication = options?.disableAutomaticAuthentication;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { BrowserCustomizationOptions } from "./browserCustomizationOptions";
import { CredentialPersistenceOptions } from "./credentialPersistenceOptions";
import { InteractiveCredentialOptions } from "./interactiveCredentialOptions";

Expand All @@ -20,7 +21,8 @@ export type BrowserLoginStyle = "redirect" | "popup";
*/
export interface InteractiveBrowserCredentialNodeOptions
extends InteractiveCredentialOptions,
CredentialPersistenceOptions {
CredentialPersistenceOptions,
BrowserCustomizationOptions {
/**
* Gets the redirect URI of the application. This should be same as the value
* in the application registration portal. Defaults to `window.location.href`.
Expand Down
2 changes: 1 addition & 1 deletion sdk/identity/identity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export { VisualStudioCodeCredentialOptions } from "./credentials/visualStudioCod
export { OnBehalfOfCredential } from "./credentials/onBehalfOfCredential";
export { WorkloadIdentityCredential } from "./credentials/workloadIdentityCredential";
export { WorkloadIdentityCredentialOptions } from "./credentials/workloadIdentityCredentialOptions";

export { BrowserCustomizationOptions } from "./credentials/browserCustomizationOptions";
export { TokenCachePersistenceOptions } from "./msal/nodeFlows/tokenCachePersistenceOptions";

export { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-auth";
Expand Down
10 changes: 10 additions & 0 deletions sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import open from "open";
export interface MsalOpenBrowserOptions extends MsalNodeOptions {
redirectUri?: string;
loginHint?: string;
browserCustomizationOptions?: {
errorMessage?: string;
successMessage?: string;
};
}

/**
Expand All @@ -31,10 +35,14 @@ export const interactiveBrowserMockable = {
*/
export class MsalOpenBrowser extends MsalNode {
private loginHint?: string;
private errorTemplate?: string;
private successTemplate?: string;

constructor(options: MsalOpenBrowserOptions) {
super(options);
this.loginHint = options.loginHint;
this.errorTemplate = options.browserCustomizationOptions?.errorMessage;
this.successTemplate = options.browserCustomizationOptions?.successMessage;
this.logger = credentialLogger("Node.js MSAL Open Browser");
}

Expand All @@ -52,6 +60,8 @@ export class MsalOpenBrowser extends MsalNode {
claims: options?.claims,
correlationId: options?.correlationId,
loginHint: this.loginHint,
errorTemplate: this.errorTemplate,
successTemplate: this.successTemplate,
});
return this.handleResult(scopes, this.clientId, result || undefined);
} catch (err: any) {
Expand Down

0 comments on commit f814d7d

Please sign in to comment.