Skip to content

Commit

Permalink
Common changes for signin
Browse files Browse the repository at this point in the history
  • Loading branch information
shenj committed Jan 8, 2025
1 parent d810d5f commit b611c3f
Show file tree
Hide file tree
Showing 78 changed files with 2,151 additions and 1,004 deletions.
8 changes: 8 additions & 0 deletions lib/msal-browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export { BaseOperatingContext } from "./operatingcontext/BaseOperatingContext.js
// Cache
export { LoadTokenOptions } from "./cache/TokenCache.js";
export { ITokenCache } from "./cache/ITokenCache.js";
export { BrowserCacheManager } from "./cache/BrowserCacheManager.js";

// Storage
export { MemoryStorage } from "./cache/MemoryStorage.js";
Expand All @@ -86,6 +87,9 @@ export { LocalStorage } from "./cache/LocalStorage.js";
export { SessionStorage } from "./cache/SessionStorage.js";
export { IWindowStorage } from "./cache/IWindowStorage.js";

// Interaction Client
export { StandardInteractionClient } from "./interaction_client/StandardInteractionClient.js";

// Events
export {
EventMessage,
Expand Down Expand Up @@ -160,13 +164,17 @@ export {
PerformanceCallbackFunction,
PerformanceEvent,
PerformanceEvents,
// Crypto
ICrypto,
// Telemetry
InProgressPerformanceEvent,
TenantProfile,
IPerformanceClient,
StubPerformanceClient,
TokenClaims,
Constants,
AADServerParamKeys,
ServerTelemetryManager,
} from "@azure/msal-common/browser";

export { version } from "./packageMetadata.js";
23 changes: 0 additions & 23 deletions lib/msal-custom-auth/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,4 @@ export default [
}),
],
},
{
// sample
input: "samples/index.ts",
output: [
{
dir: "samples/lib",
format: "umd",
name: "msal",
entryFileNames: "msal-custom-auth.samples.js",
banner: useStrictHeader,
inlineDynamicImports: true,
sourcemap: false,
},
],
plugins: [
typescript({
typescript: require("typescript"),
tsconfig: "tsconfig.samples.json",
sourceMap: false,
compilerOptions: { outDir: "samples/lib/types", declaration: false, declarationMap: false },
}),
],
},
];
43 changes: 0 additions & 43 deletions lib/msal-custom-auth/samples/CustomAuthConfig.ts

This file was deleted.

75 changes: 0 additions & 75 deletions lib/msal-custom-auth/samples/SignInSample.ts

This file was deleted.

7 changes: 0 additions & 7 deletions lib/msal-custom-auth/samples/index.ts

This file was deleted.

19 changes: 16 additions & 3 deletions lib/msal-custom-auth/src/CustomAuthConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,36 @@
*/

import { Constants } from "@azure/msal-browser";
import { version } from "./packageMetadata.js";

export const GrantType = {
PASSWORD: "password",
OOB: "oob",
CONTINUATION_TOKEN: "continuation_token",
REDIRECT: "redirect",
ATTRIBUTES: "attributes",
};
} as const;

export const ChallengeType = {
PASSWORD: "password",
OOB: "oob",
REDIRECT: "redirect",
};
} as const;

export const DefaultScopes = [
Constants.OPENID_SCOPE,
Constants.PROFILE_SCOPE,
Constants.OFFLINE_ACCESS_SCOPE,
];
] as const;

export const HttpHeaderKeys = {
CONTENT_TYPE: "Content-Type",
X_MS_REQUEST_ID: "x-ms-request-id",
} as const;

export const DefaultPackageInfo = {
SKU: "msal.custom.auth",
VERSION: version,
OS: "",
CPU: "",
} as const;
99 changes: 80 additions & 19 deletions lib/msal-custom-auth/src/CustomAuthPublicClientApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { PublicClientApplication } from "@azure/msal-browser";
import { Constants, PublicClientApplication } from "@azure/msal-browser";
import { GetAccountResult } from "./account/auth_flow/result/GetAccountResult.js";
import { SignInResult } from "./sign_in/auth_flow/result/SignInResult.js";
import { SignUpResult } from "./sign_up/auth_flow/result/SignUpResult.js";
Expand All @@ -19,6 +19,14 @@ import {
import { CustomAuthConfiguration } from "./configuration/CustomAuthConfiguration.js";
import { CustomAuthOperatingContext } from "./operating_context/CustomAuthOperatingContext.js";
import { ResetPasswordStartResult } from "./reset_password/auth_flow/result/ResetPasswordStartResult.js";
import {
InvalidAuthApiProxyDomain,
InvalidAuthority,
InvalidConfigurationError,
MissingConfiguration,
} from "./core/error/InvalidConfigurationError.js";
import { UrlUtils } from "./core/utils/UrlUtils.js";
import { StringUtils } from "./core/utils/StringUtils.js";

export class CustomAuthPublicClientApplication
extends PublicClientApplication
Expand All @@ -29,31 +37,44 @@ export class CustomAuthPublicClientApplication
/*
* Creates a new instance of a PublicClientApplication with the given configuration.
* @param config - A configuration object for the PublicClientApplication instance
* @param controller - A controller object for the PublicClientApplication instance
*/
static create(
static async create(
config: CustomAuthConfiguration,
): CustomAuthPublicClientApplication {
return new CustomAuthPublicClientApplication(config);
controller?: ICustomAuthStandardController
): Promise<ICustomAuthPublicClientApplication> {
CustomAuthPublicClientApplication.validateConfig(config);

let customAuthController = controller;

if (!customAuthController) {
customAuthController = new CustomAuthStandardController(
new CustomAuthOperatingContext(config)
);

await customAuthController.initialize();
}

const app = new CustomAuthPublicClientApplication(
config,
customAuthController
);

return app;
}

/*
* Creates a new instance of a PublicClientApplication with the given configuration and controller.
* @param config - A configuration object for the PublicClientApplication instance
* @param controller - A controller object for the PublicClientApplication instance
*/
constructor(
private constructor(
config: CustomAuthConfiguration,
controller?: ICustomAuthStandardController,
controller: ICustomAuthStandardController
) {
const customAuthController =
controller ||
new CustomAuthStandardController(
new CustomAuthOperatingContext(config),
);

super(config, customAuthController);
super(config, controller);

this.customAuthController = customAuthController;
this.customAuthController = controller;
}

/*
Expand All @@ -62,10 +83,10 @@ export class CustomAuthPublicClientApplication
* @returns - A promise that resolves to GetAccountResult
*/
getCurrentAccount(
getAccountInputs: GetAccountInputs,
getAccountInputs: GetAccountInputs
): Promise<GetAccountResult> {
throw new Error(
`Method not implemented with parameter ${getAccountInputs}`,
`Method not implemented with parameter ${getAccountInputs}`
);
}

Expand All @@ -85,7 +106,7 @@ export class CustomAuthPublicClientApplication
*/
signUp(signUpInputs: SignUpInputs): Promise<SignUpResult> {
throw new Error(
`Method not implemented with parameter ${signUpInputs}`,
`Method not implemented with parameter ${signUpInputs}`
);
}

Expand All @@ -95,10 +116,50 @@ export class CustomAuthPublicClientApplication
* @returns - A promise that resolves to ResetPasswordStartResult
*/
resetPassword(
resetPasswordInputs: ResetPasswordInputs,
resetPasswordInputs: ResetPasswordInputs
): Promise<ResetPasswordStartResult> {
throw new Error(
`Method not implemented with parameter ${resetPasswordInputs}`,
`Method not implemented with parameter ${resetPasswordInputs}`
);
}

/**
* Validates the configuration to ensure it is a valid CustomAuthConfiguration object.
* @param config The configuration object for the PublicClientApplication.
*/
private static validateConfig(config: CustomAuthConfiguration): void {
// Ensure the configuration object has a valid CIAM authority URL.
if (!config) {
throw new InvalidConfigurationError(
MissingConfiguration,
"The configuration is missing."
);
}

if (!config.auth?.authority) {
throw new InvalidConfigurationError(
InvalidAuthority,
`The authority URL '${config.auth?.authority}' is not set.`
);
}

const trimmedAuthority = StringUtils.trim(config.auth.authority, "/");

if (!trimmedAuthority.endsWith(Constants.CIAM_AUTH_URL)) {
throw new InvalidConfigurationError(
InvalidAuthority,
`The authority URL '${config.auth?.authority}' is not a CIAM authority.`
);
}

if (
config.customAuth.authApiProxyUrl &&
!UrlUtils.IsValidSecureUrl(config.customAuth.authApiProxyUrl)
) {
throw new InvalidConfigurationError(
InvalidAuthApiProxyDomain,
`The authApiProxyDomain URL '${config.customAuth.authApiProxyUrl}' is not a valid secure URL.`
);
}
}
}
Loading

0 comments on commit b611c3f

Please sign in to comment.