Skip to content

Commit 55de7d9

Browse files
committed
Refactor 1
1 parent bedfd47 commit 55de7d9

16 files changed

+146
-153
lines changed

lib/msal-native-auth/samples/SignInSample.ts

+15-16
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
*/
55

66
import {
7-
SignInCodeRequiredHandler,
8-
SignInPasswordRequiredHandler,
7+
SignInCodeRequiredState,
8+
SignInPasswordRequiredState,
99
UserNotFoundError,
1010
} from "@azure/msal-native-auth";
1111
import { AccountInfo } from "@azure/msal-native-auth";
12-
import { SignInOptions } from "@azure/msal-native-auth";
12+
import { SignInInputs } from "@azure/msal-native-auth";
1313
import { NativeAuthConfiguration } from "@azure/msal-native-auth";
1414
import { NativeAuthPublicClientApplication } from "@azure/msal-native-auth";
1515

@@ -26,7 +26,7 @@ export async function signin(
2626

2727
const app = NativeAuthPublicClientApplication.create(config);
2828

29-
const signInOptions: SignInOptions = {
29+
const signInOptions: SignInInputs = {
3030
username: username,
3131
password: password,
3232
};
@@ -48,7 +48,7 @@ export async function signin(
4848
// Check if the flow is completed
4949
if (result.isFlowCompleted()) {
5050
// Get the account info which can be used to get account data, tokens, and sign out.
51-
const accountManager: AccountInfo = result.resultData as AccountInfo;
51+
const accountManager: AccountInfo = result.data as AccountInfo;
5252

5353
accountManager.getAccount();
5454
accountManager.getIdToken();
@@ -59,11 +59,11 @@ export async function signin(
5959
}
6060

6161
// code required
62-
if (result.nextStateHandler instanceof SignInCodeRequiredHandler) {
62+
if (result.state instanceof SignInCodeRequiredState) {
6363
// collect code from customer.
6464
const code = "test-code";
6565

66-
const submitCodeResult = await result.nextStateHandler.submitCode(code);
66+
const submitCodeResult = await result.state.submitCode(code);
6767

6868
if (!submitCodeResult.isSuccess) {
6969
// handle error
@@ -73,7 +73,7 @@ export async function signin(
7373

7474
// Get the account manager which can be used to get account information, tokens, and sign out.
7575
const accountManager: AccountInfo =
76-
submitCodeResult.resultData as AccountInfo;
76+
submitCodeResult.data as AccountInfo;
7777

7878
accountManager.getAccount();
7979
accountManager.getIdToken();
@@ -84,9 +84,9 @@ export async function signin(
8484
}
8585

8686
// resend code and submit code
87-
if (result.nextStateHandler instanceof SignInCodeRequiredHandler) {
87+
if (result.state instanceof SignInCodeRequiredState) {
8888
// resend code
89-
const resendCodeResult = await result.nextStateHandler.resendCode();
89+
const resendCodeResult = await result.state.resendCode();
9090

9191
if (!resendCodeResult.isSuccess) {
9292
// handle error
@@ -98,7 +98,7 @@ export async function signin(
9898
const code = "test-code";
9999

100100
const submitCodeResult = await (
101-
resendCodeResult.nextStateHandler as SignInCodeRequiredHandler
101+
resendCodeResult.state as SignInCodeRequiredState
102102
).submitCode(code);
103103

104104
if (!submitCodeResult.isSuccess) {
@@ -109,7 +109,7 @@ export async function signin(
109109

110110
// Get the account manager which can be used to get account information, tokens, and sign out.
111111
const accountManager: AccountInfo =
112-
submitCodeResult.resultData as AccountInfo;
112+
submitCodeResult.data as AccountInfo;
113113

114114
accountManager.getAccount();
115115
accountManager.getIdToken();
@@ -120,11 +120,10 @@ export async function signin(
120120
}
121121

122122
// password required
123-
if (result.nextStateHandler instanceof SignInPasswordRequiredHandler) {
123+
if (result.state instanceof SignInPasswordRequiredState) {
124124
// collect password from customer.
125125
const pwd = "test-password";
126-
const submitPasswordResult =
127-
await result.nextStateHandler.sumbmitPassword(pwd);
126+
const submitPasswordResult = await result.state.sumbmitPassword(pwd);
128127

129128
if (!submitPasswordResult.isSuccess) {
130129
// handle error
@@ -134,7 +133,7 @@ export async function signin(
134133

135134
// Get the account manager which can be used to get account information, tokens, and sign out.
136135
const accountManager: AccountInfo =
137-
submitPasswordResult.resultData as AccountInfo;
136+
submitPasswordResult.data as AccountInfo;
138137

139138
accountManager.getAccount();
140139
accountManager.getIdToken();

lib/msal-native-auth/samples/lib/msal-native-auth.samples.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
return;
3939
}
4040
// code required
41-
if (result.nextStateHandler instanceof msalNativeAuth.SignInCodeRequiredHandler) {
41+
if (result.nextStateHandler instanceof msalNativeAuth.SignInCodeRequiredState) {
4242
// collect code from customer.
4343
const code = "test-code";
4444
const submitCodeResult = await result.nextStateHandler.submitCode(code);
@@ -47,15 +47,15 @@
4747
return;
4848
}
4949
// Get the account manager which can be used to get account information, tokens, and sign out.
50-
const accountManager = result.resultData;
50+
const accountManager = submitCodeResult.resultData;
5151
accountManager.getAccount();
5252
accountManager.getIdToken();
5353
await accountManager.getAccessToken();
5454
await accountManager.signOut();
5555
return;
5656
}
5757
// resend code and submit code
58-
if (result.nextStateHandler instanceof msalNativeAuth.SignInCodeRequiredHandler) {
58+
if (result.nextStateHandler instanceof msalNativeAuth.SignInCodeRequiredState) {
5959
// resend code
6060
const resendCodeResult = await result.nextStateHandler.resendCode();
6161
if (!resendCodeResult.isSuccess) {
@@ -70,15 +70,15 @@
7070
return;
7171
}
7272
// Get the account manager which can be used to get account information, tokens, and sign out.
73-
const accountManager = result.resultData;
73+
const accountManager = submitCodeResult.resultData;
7474
accountManager.getAccount();
7575
accountManager.getIdToken();
7676
await accountManager.getAccessToken();
7777
await accountManager.signOut();
7878
return;
7979
}
8080
// password required
81-
if (result.nextStateHandler instanceof msalNativeAuth.SignInPasswordRequiredHandler) {
81+
if (result.nextStateHandler instanceof msalNativeAuth.SignInPasswordRequiredState) {
8282
// collect password from customer.
8383
const pwd = "test-password";
8484
const submitPasswordResult = await result.nextStateHandler.sumbmitPassword(pwd);
@@ -87,7 +87,7 @@
8787
return;
8888
}
8989
// Get the account manager which can be used to get account information, tokens, and sign out.
90-
const accountManager = result.resultData;
90+
const accountManager = submitPasswordResult.resultData;
9191
accountManager.getAccount();
9292
accountManager.getIdToken();
9393
await accountManager.getAccessToken();

lib/msal-native-auth/src/INativeAuthPublicClientApplication.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,42 @@ import { ResetPasswordStartResult } from "./auth_flow/result/ResetPasswordResult
88
import { SignInResult } from "./auth_flow/result/SignInResult.js";
99
import { SignUpResult } from "./auth_flow/result/SignUpResult.js";
1010
import {
11-
GetAccountOptions,
12-
ResetPasswordOptions,
13-
SignInOptions,
14-
SignUpOptions,
15-
} from "./NativeAuthActionOptions.js";
11+
GetAccountInputs,
12+
ResetPasswordInputs,
13+
SignInInputs,
14+
SignUpInputs,
15+
} from "./NativeAuthActionInputs.js";
1616

1717
export interface INativeAuthPublicClientApplication {
1818
/*
1919
* Gets the current account from the cache.
20-
* @param getAccountOptions - Options for getting the current cached account
20+
* @param getAccountInputss - Inputss for getting the current cached account
2121
* @returns - A promise that resolves to GetAccountResult
2222
*/
2323
getCurrentAccount(
24-
getAccountOptions: GetAccountOptions
24+
getAccountInputss: GetAccountInputs
2525
): Promise<GetAccountResult>;
2626

2727
/*
2828
* Initiates the sign-in flow.
29-
* @param signInOptions - Options for the sign-in flow
29+
* @param signInInputss - Inputss for the sign-in flow
3030
* @returns - A promise that resolves to SignInResult
3131
*/
32-
signIn(signInOptions: SignInOptions): Promise<SignInResult>;
32+
signIn(signInInputss: SignInInputs): Promise<SignInResult>;
3333

3434
/*
3535
* Initiates the sign-up flow.
36-
* @param signUpOptions - Options for the sign-up flow
36+
* @param signUpInputss - Inputss for the sign-up flow
3737
* @returns - A promise that resolves to SignUpResult
3838
*/
39-
signUp(signUpOptions: SignUpOptions): Promise<SignUpResult>;
39+
signUp(signUpInputss: SignUpInputs): Promise<SignUpResult>;
4040

4141
/*
4242
* Initiates the reset password flow.
43-
* @param resetPasswordOptions - Options for the reset password flow
43+
* @param resetPasswordInputss - Inputss for the reset password flow
4444
* @returns - A promise that resolves to ResetPasswordStartResult
4545
*/
4646
resetPassword(
47-
resetPasswordOptions: ResetPasswordOptions
47+
resetPasswordInputss: ResetPasswordInputs
4848
): Promise<ResetPasswordStartResult>;
4949
}

lib/msal-native-auth/src/NativeAuthActionOptions.ts renamed to lib/msal-native-auth/src/NativeAuthActionInputs.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55

66
import { UserAccountAttributes } from "./UserAccountAttributes.js";
77

8-
export type GetAccountOptions = NativeAuthActionOptions;
8+
export type GetAccountInputs = NativeAuthActionInputs;
99

10-
export type SignInOptions = NativeAuthActionOptions & {
10+
export type SignInInputs = NativeAuthActionInputs & {
1111
username: string;
1212
password?: string;
1313
scopes?: Array<string>;
1414
};
1515

16-
export type SignUpOptions = NativeAuthActionOptions & {
16+
export type SignUpInputs = NativeAuthActionInputs & {
1717
username: string;
1818
password?: string;
1919
attribute?: UserAccountAttributes;
2020
};
2121

22-
export type ResetPasswordOptions = NativeAuthActionOptions & {
22+
export type ResetPasswordInputs = NativeAuthActionInputs & {
2323
username: string;
2424
};
2525

26-
export type NativeAuthActionOptions = {
26+
export type NativeAuthActionInputs = {
2727
correlationId?: string;
2828
};

lib/msal-native-auth/src/NativeAuthPublicClientApplication.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import { INativeAuthStardardController } from "./controller/INativeAuthStandardC
1212
import { NativeAuthStandardController } from "./controller/NativeAuthStandardController.js";
1313
import { INativeAuthPublicClientApplication } from "./INativeAuthPublicClientApplication.js";
1414
import {
15-
GetAccountOptions,
16-
SignInOptions,
17-
SignUpOptions,
18-
ResetPasswordOptions,
19-
} from "./NativeAuthActionOptions.js";
15+
GetAccountInputs,
16+
SignInInputs,
17+
SignUpInputs,
18+
ResetPasswordInputs,
19+
} from "./NativeAuthActionInputs.js";
2020
import { NativeAuthConfiguration } from "./NativeAuthConfiguration.js";
2121
import { NativeAuthOperatingContext } from "./operating_context/NativeAuthOperatingContext.js";
2222

@@ -60,7 +60,7 @@ export class NativeAuthPublicClientApplication
6060
* @returns - A promise that resolves to GetAccountResult
6161
*/
6262
getCurrentAccount(
63-
getAccountOptions: GetAccountOptions
63+
getAccountOptions: GetAccountInputs
6464
): Promise<GetAccountResult> {
6565
throw new Error(
6666
`Method not implemented with parameter ${getAccountOptions}`
@@ -72,7 +72,7 @@ export class NativeAuthPublicClientApplication
7272
* @param signInOptions - Options for the sign-in flow
7373
* @returns - A promise that resolves to SignInResult
7474
*/
75-
signIn(signInOptions: SignInOptions): Promise<SignInResult> {
75+
signIn(signInOptions: SignInInputs): Promise<SignInResult> {
7676
return this.nativeAuthController.signIn(signInOptions);
7777
}
7878

@@ -81,7 +81,7 @@ export class NativeAuthPublicClientApplication
8181
* @param signUpOptions - Options for the sign-up flow
8282
* @returns - A promise that resolves to SignUpResult
8383
*/
84-
signUp(signUpOptions: SignUpOptions): Promise<SignUpResult> {
84+
signUp(signUpOptions: SignUpInputs): Promise<SignUpResult> {
8585
throw new Error(
8686
`Method not implemented with parameter ${signUpOptions}`
8787
);
@@ -93,7 +93,7 @@ export class NativeAuthPublicClientApplication
9393
* @returns - A promise that resolves to ResetPasswordStartResult
9494
*/
9595
resetPassword(
96-
resetPasswordOptions: ResetPasswordOptions
96+
resetPasswordOptions: ResetPasswordInputs
9797
): Promise<ResetPasswordStartResult> {
9898
throw new Error(
9999
`Method not implemented with parameter ${resetPasswordOptions}`

lib/msal-native-auth/src/auth_flow/result/ResetPasswordResult.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,34 @@
44
*/
55

66
import {
7-
ResetPasswordCodeRequiredHandler,
8-
ResetPasswordPasswordRequiredHandler,
9-
} from "../handler/ResetPasswordHandler.js";
7+
ResetPasswordCodeRequiredState,
8+
ResetPasswordPasswordRequiredState,
9+
} from "../state/ResetPasswordState.js";
1010
import { ResultBase } from "./ResultBase.js";
11-
import { SignInContinuationHandler } from "../handler/SignInHandler.js";
11+
import { SignInContinuationState } from "../state/SignInState.js";
1212

1313
/*
1414
* Result of a reset password operation.
1515
*/
1616
export class ResetPasswordStartResult extends ResultBase<
1717
void,
18-
ResetPasswordCodeRequiredHandler
18+
ResetPasswordCodeRequiredState
1919
> {}
2020

2121
/*
2222
* Result of a reset password operation that requires a code.
2323
*/
2424
export class ResetPasswordSubmitCodeResult extends ResultBase<
2525
void,
26-
ResetPasswordPasswordRequiredHandler
26+
ResetPasswordPasswordRequiredState
2727
> {}
2828

2929
/*
3030
* Result of a reset password operation that requires a password.
3131
*/
3232
export class ResetPasswordSubmitPasswordResult extends ResultBase<
3333
void,
34-
SignInContinuationHandler
34+
SignInContinuationState
3535
> {
3636
/*
3737
* Checks if the flow is completed.
@@ -47,5 +47,5 @@ export class ResetPasswordSubmitPasswordResult extends ResultBase<
4747
*/
4848
export class ResetPasswordResendCodeResult extends ResultBase<
4949
void,
50-
ResetPasswordCodeRequiredHandler
50+
ResetPasswordCodeRequiredState
5151
> {}

0 commit comments

Comments
 (0)