Skip to content

Commit 265f21e

Browse files
authored
Update the msal test app for Native Auth (#2143)
Fix the MSAL test app to support custom attribute test cases without the need to modify the source code. [ADO Ticket (2979358)](https://dev.azure.com/IdentityDivision/Engineering/_boards/board/t/DevExDub%20-B2C/Backlog%20items/?workitem=2979358) --------- Co-authored-by: Harold Karibiye <[email protected]>
1 parent 33aab21 commit 265f21e

File tree

3 files changed

+126
-141
lines changed

3 files changed

+126
-141
lines changed

testapps/testapp/src/main/java/com/microsoft/identity/client/testapp/nativeauth/SignUpAttributesFragment.kt

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import com.microsoft.identity.nativeauth.statemachine.results.SignInResult
4040
import com.microsoft.identity.nativeauth.statemachine.results.SignUpResult
4141
import com.microsoft.identity.nativeauth.statemachine.states.SignInContinuationState
4242
import com.microsoft.identity.nativeauth.statemachine.states.SignUpAttributesRequiredState
43-
import com.microsoft.identity.nativeauth.statemachine.states.SignUpCodeRequiredState
4443
import kotlinx.coroutines.CoroutineScope
4544
import kotlinx.coroutines.Dispatchers
4645
import kotlinx.coroutines.launch
@@ -80,23 +79,15 @@ class SignUpAttributesFragment : Fragment() {
8079
try {
8180
val attributes = UserAttributes.Builder
8281

83-
// val attr1Key = binding.attr1KeyText.text.toString()
84-
// if (attr1Key.isNotBlank()) {
85-
// val attr1Value = binding.attr1ValueText.toString()
86-
// attributes
87-
// .customAttribute(attr1Key, attr1Value)
88-
// }
89-
//
90-
// val attr2Key = binding.attr2KeyText.text.toString()
91-
// if (attr2Key.isNotBlank()) {
92-
// val attr2Value = binding.attr2ValueText.toString()
93-
// attributes
94-
// .customAttribute(attr2Key, attr2Value)
95-
// }
82+
val attr1Key = binding.attr1KeyText.text.toString()
83+
val attr1Value = binding.attr1ValueText.text.toString()
84+
attributes.customAttribute(attr1Key, attr1Value)
9685

97-
val testAttribute1 = UserAttributes.country("China").build()
86+
val attr2Key = binding.attr2KeyText.text.toString()
87+
val attr2Value = binding.attr2ValueText.text.toString()
88+
attributes.customAttribute(attr2Key, attr2Value)
9889

99-
val actionResult = currentState.submitAttributes(testAttribute1)
90+
val actionResult = currentState.submitAttributes(attributes.build())
10091

10192
when (actionResult) {
10293
is SignUpResult.Complete -> {
@@ -108,17 +99,9 @@ class SignUpAttributesFragment : Fragment() {
10899
signInAfterSignUp(actionResult.nextState)
109100
}
110101
is SignUpResult.AttributesRequired -> {
111-
val testAttribute2 = UserAttributes.city("Shanghai").build()
112-
val nextState = actionResult.nextState
113-
val result = nextState.submitAttributes(testAttribute2)
114-
if (result is SignUpResult.Complete) {
115-
Toast.makeText(
116-
requireContext(),
117-
getString(R.string.sign_up_successful_message),
118-
Toast.LENGTH_SHORT
119-
).show()
120-
signInAfterSignUp(result.nextState)
121-
}
102+
navigateToAttributes(
103+
nextState = actionResult.nextState
104+
)
122105
}
123106
else -> {
124107
displayDialog(getString(R.string.msal_exception_title),"Unexpected result: $actionResult")

testapps/testapp/src/main/java/com/microsoft/identity/client/testapp/nativeauth/SignUpPasswordFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class SignUpPasswordFragment : Fragment() {
5555
_binding = FragmentPasswordBinding.inflate(inflater, container, false)
5656

5757
val bundle = this.arguments
58-
currentState = bundle!!.getSerializable(Constants.STATE) as SignUpPasswordRequiredState
58+
currentState = (bundle?.getParcelable(Constants.STATE) as? SignUpPasswordRequiredState)!!
5959

6060
init()
6161

testapps/testapp/src/main/res/layout/fragment_attribute.xml

Lines changed: 115 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -10,126 +10,128 @@
1010
android:layout_width="match_parent"
1111
android:layout_height="wrap_content">
1212

13-
<!-- <TextView-->
14-
<!-- android:id="@+id/intro"-->
15-
<!-- android:layout_width="match_parent"-->
16-
<!-- android:layout_height="wrap_content"-->
17-
<!-- android:text="@string/attributes_intro"-->
18-
<!-- app:layout_constraintStart_toStartOf="parent"-->
19-
<!-- app:layout_constraintTop_toBottomOf="parent"-->
20-
<!-- />-->
21-
22-
<!-- <TextView-->
23-
<!-- android:id="@+id/attr1_key_hint"-->
24-
<!-- android:layout_width="wrap_content"-->
25-
<!-- android:layout_height="wrap_content"-->
26-
<!-- android:text="@string/attribute_attr1_key"-->
27-
<!-- app:layout_constraintStart_toStartOf="parent"-->
28-
<!-- app:layout_constraintTop_toBottomOf="@+id/intro"-->
29-
<!-- style="@style/TextViewStyle" />-->
30-
31-
<!-- <com.google.android.material.textfield.TextInputLayout-->
32-
<!-- android:id="@+id/attr1_key_input"-->
33-
<!-- android:layout_width="match_parent"-->
34-
<!-- android:layout_height="wrap_content"-->
35-
<!-- app:layout_constraintStart_toStartOf="parent"-->
36-
<!-- app:layout_constraintEnd_toEndOf="parent"-->
37-
<!-- app:layout_constraintTop_toBottomOf="@+id/attr1_key_hint"-->
38-
<!-- style="@style/TextInputLayoutStyle">-->
39-
40-
<!-- <com.google.android.material.textfield.TextInputEditText-->
41-
<!-- android:id="@+id/attr1_key_text"-->
42-
<!-- android:layout_width="match_parent"-->
43-
<!-- android:inputType="textPersonName"-->
44-
<!-- tools:ignore="SpeakableTextPresentCheck"-->
45-
<!-- style="@style/TextInputEditTextStyle" />-->
46-
<!-- </com.google.android.material.textfield.TextInputLayout>-->
47-
48-
<!-- <TextView-->
49-
<!-- android:id="@+id/attr1_value_hint"-->
50-
<!-- android:layout_width="wrap_content"-->
51-
<!-- android:layout_height="wrap_content"-->
52-
<!-- android:text="@string/attribute_attr1_value"-->
53-
<!-- app:layout_constraintStart_toStartOf="parent"-->
54-
<!-- app:layout_constraintTop_toBottomOf="@+id/attr1_key_input"-->
55-
<!-- style="@style/TextViewStyle" />-->
56-
57-
<!-- <com.google.android.material.textfield.TextInputLayout-->
58-
<!-- android:id="@+id/attr1_value_input"-->
59-
<!-- android:layout_width="match_parent"-->
60-
<!-- android:layout_height="wrap_content"-->
61-
<!-- app:layout_constraintEnd_toEndOf="parent"-->
62-
<!-- app:layout_constraintStart_toStartOf="parent"-->
63-
<!-- app:layout_constraintTop_toBottomOf="@+id/attr1_value_hint"-->
64-
<!-- style="@style/TextInputLayoutStyle">-->
65-
66-
<!-- <com.google.android.material.textfield.TextInputEditText-->
67-
<!-- android:id="@+id/attr1_value_text"-->
68-
<!-- android:layout_width="match_parent"-->
69-
<!-- android:inputType="textPersonName"-->
70-
<!-- tools:ignore="SpeakableTextPresentCheck"-->
71-
<!-- style="@style/TextInputEditTextStyle" />-->
72-
<!-- </com.google.android.material.textfield.TextInputLayout>-->
73-
74-
<!-- <TextView-->
75-
<!-- android:id="@+id/attr2_key_hint"-->
76-
<!-- android:layout_width="wrap_content"-->
77-
<!-- android:layout_height="wrap_content"-->
78-
<!-- android:text="@string/attribute_attr2_key"-->
79-
<!-- app:layout_constraintStart_toStartOf="parent"-->
80-
<!-- app:layout_constraintTop_toBottomOf="@+id/attr1_value_input"-->
81-
<!-- style="@style/TextViewStyle" />-->
82-
83-
<!-- <com.google.android.material.textfield.TextInputLayout-->
84-
<!-- android:id="@+id/attr2_key_input"-->
85-
<!-- android:layout_width="match_parent"-->
86-
<!-- android:layout_height="wrap_content"-->
87-
<!-- app:layout_constraintStart_toStartOf="parent"-->
88-
<!-- app:layout_constraintEnd_toEndOf="parent"-->
89-
<!-- app:layout_constraintTop_toBottomOf="@+id/attr2_key_hint"-->
90-
<!-- style="@style/TextInputLayoutStyle">-->
91-
92-
<!-- <com.google.android.material.textfield.TextInputEditText-->
93-
<!-- android:id="@+id/attr2_key_text"-->
94-
<!-- android:layout_width="match_parent"-->
95-
<!-- android:inputType="textPersonName"-->
96-
<!-- tools:ignore="SpeakableTextPresentCheck"-->
97-
<!-- style="@style/TextInputEditTextStyle" />-->
98-
<!-- </com.google.android.material.textfield.TextInputLayout>-->
99-
100-
<!-- <TextView-->
101-
<!-- android:id="@+id/attr2_value_hint"-->
102-
<!-- android:layout_width="wrap_content"-->
103-
<!-- android:layout_height="wrap_content"-->
104-
<!-- android:text="@string/attribute_attr2_value"-->
105-
<!-- app:layout_constraintStart_toStartOf="parent"-->
106-
<!-- app:layout_constraintTop_toBottomOf="@+id/attr2_key_input"-->
107-
<!-- style="@style/TextViewStyle" />-->
108-
109-
<!-- <com.google.android.material.textfield.TextInputLayout-->
110-
<!-- android:id="@+id/attr2_value_input"-->
111-
<!-- android:layout_width="match_parent"-->
112-
<!-- android:layout_height="wrap_content"-->
113-
<!-- app:layout_constraintEnd_toEndOf="parent"-->
114-
<!-- app:layout_constraintStart_toStartOf="parent"-->
115-
<!-- app:layout_constraintTop_toBottomOf="@+id/attr2_value_hint"-->
116-
<!-- style="@style/TextInputLayoutStyle">-->
117-
118-
<!-- <com.google.android.material.textfield.TextInputEditText-->
119-
<!-- android:id="@+id/attr2_value_text"-->
120-
<!-- android:layout_width="match_parent"-->
121-
<!-- android:inputType="textPersonName"-->
122-
<!-- tools:ignore="SpeakableTextPresentCheck"-->
123-
<!-- style="@style/TextInputEditTextStyle" />-->
124-
<!-- </com.google.android.material.textfield.TextInputLayout>-->
13+
<TextView
14+
android:id="@+id/intro"
15+
android:layout_width="match_parent"
16+
android:layout_height="wrap_content"
17+
android:text="@string/attributes_intro"
18+
app:layout_constraintStart_toStartOf="parent"
19+
app:layout_constraintTop_toTopOf="parent"
20+
style="@style/TextViewStyle"
21+
/>
22+
23+
<TextView
24+
android:id="@+id/attr1_key_hint"
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:text="@string/attribute_attr1_key"
28+
app:layout_constraintStart_toStartOf="parent"
29+
app:layout_constraintTop_toBottomOf="@+id/intro"
30+
style="@style/TextViewStyle" />
31+
32+
<com.google.android.material.textfield.TextInputLayout
33+
android:id="@+id/attr1_key_input"
34+
android:layout_width="match_parent"
35+
android:layout_height="wrap_content"
36+
app:layout_constraintStart_toStartOf="parent"
37+
app:layout_constraintEnd_toEndOf="parent"
38+
app:layout_constraintTop_toBottomOf="@+id/attr1_key_hint"
39+
style="@style/TextInputLayoutStyle">
40+
41+
<com.google.android.material.textfield.TextInputEditText
42+
android:id="@+id/attr1_key_text"
43+
android:layout_width="match_parent"
44+
android:inputType="textPersonName"
45+
tools:ignore="SpeakableTextPresentCheck"
46+
style="@style/TextInputEditTextStyle" />
47+
</com.google.android.material.textfield.TextInputLayout>
48+
49+
<TextView
50+
android:id="@+id/attr1_value_hint"
51+
android:layout_width="wrap_content"
52+
android:layout_height="wrap_content"
53+
android:text="@string/attribute_attr1_value"
54+
app:layout_constraintStart_toStartOf="parent"
55+
app:layout_constraintTop_toBottomOf="@+id/attr1_key_input"
56+
style="@style/TextViewStyle" />
57+
58+
<com.google.android.material.textfield.TextInputLayout
59+
android:id="@+id/attr1_value_input"
60+
android:layout_width="match_parent"
61+
android:layout_height="wrap_content"
62+
app:layout_constraintEnd_toEndOf="parent"
63+
app:layout_constraintStart_toStartOf="parent"
64+
app:layout_constraintTop_toBottomOf="@+id/attr1_value_hint"
65+
style="@style/TextInputLayoutStyle">
66+
67+
<com.google.android.material.textfield.TextInputEditText
68+
android:id="@+id/attr1_value_text"
69+
android:layout_width="match_parent"
70+
android:inputType="textPersonName"
71+
tools:ignore="SpeakableTextPresentCheck"
72+
style="@style/TextInputEditTextStyle" />
73+
</com.google.android.material.textfield.TextInputLayout>
74+
75+
<TextView
76+
android:id="@+id/attr2_key_hint"
77+
android:layout_width="wrap_content"
78+
android:layout_height="wrap_content"
79+
android:text="@string/attribute_attr2_key"
80+
app:layout_constraintStart_toStartOf="parent"
81+
app:layout_constraintTop_toBottomOf="@+id/attr1_value_input"
82+
style="@style/TextViewStyle" />
83+
84+
<com.google.android.material.textfield.TextInputLayout
85+
android:id="@+id/attr2_key_input"
86+
android:layout_width="match_parent"
87+
android:layout_height="wrap_content"
88+
app:layout_constraintStart_toStartOf="parent"
89+
app:layout_constraintEnd_toEndOf="parent"
90+
app:layout_constraintTop_toBottomOf="@+id/attr2_key_hint"
91+
style="@style/TextInputLayoutStyle">
92+
93+
<com.google.android.material.textfield.TextInputEditText
94+
android:id="@+id/attr2_key_text"
95+
android:layout_width="match_parent"
96+
android:inputType="textPersonName"
97+
tools:ignore="SpeakableTextPresentCheck"
98+
style="@style/TextInputEditTextStyle" />
99+
</com.google.android.material.textfield.TextInputLayout>
100+
101+
<TextView
102+
android:id="@+id/attr2_value_hint"
103+
android:layout_width="wrap_content"
104+
android:layout_height="wrap_content"
105+
android:text="@string/attribute_attr2_value"
106+
app:layout_constraintStart_toStartOf="parent"
107+
app:layout_constraintTop_toBottomOf="@+id/attr2_key_input"
108+
style="@style/TextViewStyle" />
109+
110+
<com.google.android.material.textfield.TextInputLayout
111+
android:id="@+id/attr2_value_input"
112+
android:layout_width="match_parent"
113+
android:layout_height="wrap_content"
114+
app:layout_constraintEnd_toEndOf="parent"
115+
app:layout_constraintStart_toStartOf="parent"
116+
app:layout_constraintTop_toBottomOf="@+id/attr2_value_hint"
117+
style="@style/TextInputLayoutStyle">
118+
119+
<com.google.android.material.textfield.TextInputEditText
120+
android:id="@+id/attr2_value_text"
121+
android:layout_width="match_parent"
122+
android:inputType="textPersonName"
123+
tools:ignore="SpeakableTextPresentCheck"
124+
style="@style/TextInputEditTextStyle" />
125+
</com.google.android.material.textfield.TextInputLayout>
125126

126127
<Button
127128
android:id="@+id/submit_attributes"
128129
android:text="@string/submit_attributes"
129130
android:layout_marginTop="@dimen/dimens_30dp"
131+
app:layout_constraintBottom_toBottomOf="parent"
130132
app:layout_constraintEnd_toEndOf="parent"
131133
app:layout_constraintStart_toStartOf="parent"
132-
app:layout_constraintTop_toTopOf="parent"
134+
app:layout_constraintTop_toBottomOf="@+id/attr2_value_input"
133135
style="@style/ActionButtonStyle" />
134136

135137
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)