Skip to content

Commit 2188341

Browse files
shenjJian Shennguyencuong2596axhaferllarialbanx
authored
Add native auth feature to support the external ID authentication (sign-in, sign-up and SSPR) (#7599)
The changes in this PR include: - Add native auth feature to supporte the external ID authentication (sign-in, sign-up and SSPR). --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Jian Shen <[email protected]> Co-authored-by: nguyencuong2596 <[email protected]> Co-authored-by: Alban Xhaferllari <[email protected]> Co-authored-by: Alban <[email protected]> Co-authored-by: yongdiw <[email protected]> Co-authored-by: Thomas Norling <[email protected]> Co-authored-by: Sameera Gajjarapu <[email protected]> Co-authored-by: Robbie-Microsoft <[email protected]> Co-authored-by: MSAL.js Release Automation <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: shylasummers <[email protected]>
1 parent 45eea6b commit 2188341

File tree

143 files changed

+14417
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+14417
-9
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
# MSAL Browser
88
/lib/msal-browser/ @sameerag @tnorling @hectormmg @jo-arroyo @peterzenz @konstantin-msft @lalimasharda @shylasummers
9+
/lib/msal-browser/custom-auth @shenj @yongdiw
910
/samples/msal-browser-samples/ @sameerag @tnorling @hectormmg @jo-arroyo @peterzenz @konstantin-msft @lalimasharda @shylasummers
1011

1112
# MSAL Common

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ The [`lib`](https://github.com/AzureAD/microsoft-authentication-library-for-js/t
1818
- [On-behalf-of Flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow)
1919

2020
- [Microsoft Authentication Library for JavaScript](lib/msal-browser/): A browser-based, framework-agnostic browser library that enables authentication and token acquisition with the Microsoft Identity platform in JavaScript applications. Implements the OAuth 2.0 [Authorization Code Flow with PKCE](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-auth-code-flow), and is [OpenID-compliant](https://docs.microsoft.com/azure/active-directory/develop/v2-protocols-oidc).
21+
22+
- [Native Authentication Support for JavaScript](lib/msal-browser/src/custom_auth/): MSAL also provides native authentication APIs that allow applications to implement a native experience with end-to-end customizable flows in their applications. With native authentication, users are guided through a rich, native, sign-up and sign-in journey without leaving the app. The native authentication feature is available for SPAs on [External ID for customers](https://learn.microsoft.com/en-us/entra/identity-platform/concept-native-authentication). It is recommended to always use the most up-to-date version of the SDK.
23+
24+
> **Note:** The native authentication feature is currently in preview and is not considered production-stable. Features and APIs may change before general availability.
25+
>
26+
> **Terminology:** In the codebase, the term "Custom Auth" is used instead of "Native Auth". You will find classes, interfaces, and configuration options prefixed with `CustomAuth` (e.g., `CustomAuthPublicClientApplication`, `CustomAuthConfiguration`). Please refer to these when implementing or exploring the native authentication feature in the code.
27+
2128
- [Microsoft Authentication Library for React](lib/msal-react/): A wrapper of the msal-browser library for apps using React.
2229
- [Microsoft Authentication Library for Angular](lib/msal-angular/): A wrapper of the msal-browser library for apps using Angular framework.
2330
- [Microsoft Authentication Extensions for Node](extensions/msal-node-extensions/): The Microsoft Authentication Extensions for Node offers secure mechanisms for client applications to perform cross-platform token cache serialization and persistence. It gives additional support to the Microsoft Authentication Library for Node (MSAL).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Add native authentication feaetures for the external ID",
4+
"packageName": "@azure/msal-browser",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

lib/msal-browser/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
"module": "./dist/index.mjs",
2828
"types": "./dist/index.d.ts",
2929
"exports": {
30+
"./custom-auth": {
31+
"import": {
32+
"types": "./dist/custom-auth-path/custom_auth/index.d.ts",
33+
"default": "./dist/custom-auth-path/custom_auth/index.mjs"
34+
},
35+
"require": {
36+
"types": "./lib/custom-auth-path/types/custom_auth/index.d.ts",
37+
"default": "./lib/custom-auth-path/msal-custom-auth.cjs"
38+
}
39+
},
3040
".": {
3141
"import": {
3242
"types": "./dist/index.d.ts",

lib/msal-browser/rollup.config.js

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const fileHeader = `${libraryHeader}\n${useStrictHeader}`;
1717

1818
export default [
1919
{
20-
// for es build
20+
// Main SDK - ES build
2121
input: "src/index.ts",
2222
output: {
2323
dir: "dist",
@@ -32,17 +32,16 @@ export default [
3232
moduleSideEffects: false,
3333
propertyReadSideEffects: false,
3434
},
35-
external: [
36-
"@azure/msal-common/browser"
37-
],
35+
external: ["@azure/msal-common/browser"],
3836
plugins: [
3937
typescript({
4038
typescript: require("typescript"),
4139
tsconfig: "tsconfig.build.json",
42-
})
40+
}),
4341
],
4442
},
4543
{
44+
// Main SDK - CommonJS build
4645
input: "src/index.ts",
4746
output: [
4847
{
@@ -65,10 +64,11 @@ export default [
6564
sourceMap: true,
6665
compilerOptions: { outDir: "lib/types" },
6766
}),
68-
createPackageJson({libPath: __dirname})
67+
createPackageJson({ libPath: __dirname }),
6968
],
7069
},
7170
{
71+
// Main SDK - UMD build
7272
input: "src/index.ts",
7373
output: [
7474
{
@@ -90,12 +90,16 @@ export default [
9090
typescript: require("typescript"),
9191
tsconfig: "tsconfig.build.json",
9292
sourceMap: true,
93-
compilerOptions: { outDir: "lib/types", declaration: false, declarationMap: false },
93+
compilerOptions: {
94+
outDir: "lib/types",
95+
declaration: false,
96+
declarationMap: false,
97+
},
9498
}),
9599
],
96100
},
97101
{
98-
// Minified version of msal
102+
// Main SDK - UMD minified build
99103
input: "src/index.ts",
100104
output: [
101105
{
@@ -117,7 +121,11 @@ export default [
117121
typescript: require("typescript"),
118122
tsconfig: "tsconfig.build.json",
119123
sourceMap: false,
120-
compilerOptions: { outDir: "lib/types", declaration: false, declarationMap: false },
124+
compilerOptions: {
125+
outDir: "lib/types",
126+
declaration: false,
127+
declarationMap: false,
128+
},
121129
}),
122130
terser({
123131
output: {
@@ -126,4 +134,52 @@ export default [
126134
}),
127135
],
128136
},
137+
{
138+
// Custom Auth - ES module build
139+
input: "src/custom_auth/index.ts",
140+
output: {
141+
dir: "dist/custom-auth-path",
142+
preserveModules: true,
143+
preserveModulesRoot: "src",
144+
format: "es",
145+
entryFileNames: "[name].mjs",
146+
banner: fileHeader,
147+
sourcemap: true,
148+
},
149+
treeshake: {
150+
moduleSideEffects: false,
151+
propertyReadSideEffects: false,
152+
},
153+
external: ["@azure/msal-common/browser"],
154+
plugins: [
155+
typescript({
156+
typescript: require("typescript"),
157+
tsconfig: "tsconfig.custom-auth.build.json",
158+
}),
159+
],
160+
},
161+
{
162+
// Custom Auth - CommonJS build
163+
input: "src/custom_auth/index.ts",
164+
output: {
165+
dir: "lib/custom-auth-path",
166+
format: "cjs",
167+
banner: fileHeader,
168+
sourcemap: true,
169+
entryFileNames: "msal-custom-auth.cjs",
170+
inlineDynamicImports: true,
171+
},
172+
plugins: [
173+
nodeResolve({
174+
browser: true,
175+
resolveOnly: ["@azure/msal-common", "tslib"],
176+
}),
177+
typescript({
178+
typescript: require("typescript"),
179+
tsconfig: "tsconfig.custom-auth.build.json",
180+
sourceMap: true,
181+
compilerOptions: { outDir: "lib/custom-auth-path/types" },
182+
}),
183+
],
184+
},
129185
];
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import { UserAccountAttributes } from "./UserAccountAttributes.js";
7+
8+
export type CustomAuthActionInputs = {
9+
correlationId?: string;
10+
};
11+
12+
export type AccountRetrievalInputs = CustomAuthActionInputs;
13+
14+
export type SignInInputs = CustomAuthActionInputs & {
15+
username: string;
16+
password?: string;
17+
scopes?: Array<string>;
18+
};
19+
20+
export type SignUpInputs = CustomAuthActionInputs & {
21+
username: string;
22+
password?: string;
23+
attributes?: UserAccountAttributes;
24+
};
25+
26+
export type ResetPasswordInputs = CustomAuthActionInputs & {
27+
username: string;
28+
};
29+
30+
export type AccessTokenRetrievalInputs = {
31+
forceRefresh: boolean;
32+
scopes?: Array<string>;
33+
};
34+
35+
export type SignInWithContinuationTokenInputs = {
36+
scopes?: Array<string>;
37+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import { Constants } from "@azure/msal-common/browser";
7+
import { version } from "../packageMetadata.js";
8+
9+
export const GrantType = {
10+
PASSWORD: "password",
11+
OOB: "oob",
12+
CONTINUATION_TOKEN: "continuation_token",
13+
REDIRECT: "redirect",
14+
ATTRIBUTES: "attributes",
15+
} as const;
16+
17+
export const ChallengeType = {
18+
PASSWORD: "password",
19+
OOB: "oob",
20+
REDIRECT: "redirect",
21+
} as const;
22+
23+
export const DefaultScopes = [
24+
Constants.OPENID_SCOPE,
25+
Constants.PROFILE_SCOPE,
26+
Constants.OFFLINE_ACCESS_SCOPE,
27+
] as const;
28+
29+
export const HttpHeaderKeys = {
30+
CONTENT_TYPE: "Content-Type",
31+
X_MS_REQUEST_ID: "x-ms-request-id",
32+
} as const;
33+
34+
export const DefaultPackageInfo = {
35+
SKU: "msal.browser",
36+
VERSION: version,
37+
OS: "",
38+
CPU: "",
39+
} as const;
40+
41+
export const ResetPasswordPollStatus = {
42+
IN_PROGRESS: "in_progress",
43+
SUCCEEDED: "succeeded",
44+
FAILED: "failed",
45+
NOT_STARTED: "not_started",
46+
} as const;
47+
48+
export const DefaultCustomAuthApiCodeLength = -1; // Default value indicating that the code length is not specified
49+
export const DefaultCustomAuthApiCodeResendIntervalInSec = 300; // seconds
50+
export const PasswordResetPollingTimeoutInMs = 300000; // milliseconds

0 commit comments

Comments
 (0)