Skip to content

Commit 33aab21

Browse files
committed
Fix test app issues
1 parent 4e337f5 commit 33aab21

File tree

7 files changed

+158
-136
lines changed

7 files changed

+158
-136
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class EmailAttributeSignUpFragment : Fragment() {
132132

133133
val actionResult = authClient.signUp(
134134
username = email,
135-
password = password,
135+
// password = password,
136136
attributes = attributes.build()
137137
)
138138

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ class EmailPasswordSignInSignUpFragment : Fragment() {
120120

121121
val actionResult = authClient.signIn(
122122
username = email,
123-
password = password
123+
password = password,
124+
scopes = listOf("User.Read")
124125
)
125126

126127
password.fill('0');
@@ -147,6 +148,9 @@ class EmailPasswordSignInSignUpFragment : Fragment() {
147148
)
148149
)
149150
}
151+
else {
152+
displayDialog("Unexpected result", actionResult.errorMessage)
153+
}
150154
}
151155
else -> {
152156
displayDialog( "Unexpected result", actionResult.toString())
@@ -279,6 +283,8 @@ class EmailPasswordSignInSignUpFragment : Fragment() {
279283
binding.resultAccessToken.text =
280284
getString(R.string.result_access_token_text) + accessToken
281285

286+
Log.d("AccessToken", accessToken)
287+
282288
val idToken = accountState.getIdToken()
283289
binding.resultIdToken.text = getString(R.string.result_id_token_text) + idToken
284290
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ import android.view.View
3030
import android.view.ViewGroup
3131
import android.widget.Toast
3232
import androidx.fragment.app.Fragment
33+
import com.google.android.material.tabs.TabLayout.TabGravity
3334
import com.microsoft.identity.client.exception.MsalException
3435
import com.microsoft.identity.client.testapp.Constants
3536
import com.microsoft.identity.client.testapp.R
3637
import com.microsoft.identity.client.testapp.databinding.FragmentEmailSisuBinding
3738
import com.microsoft.identity.nativeauth.INativeAuthPublicClientApplication
39+
import com.microsoft.identity.nativeauth.UserAttributes
3840
import com.microsoft.identity.nativeauth.statemachine.results.GetAccessTokenResult
3941
import com.microsoft.identity.nativeauth.statemachine.results.GetAccountResult
4042
import com.microsoft.identity.nativeauth.statemachine.results.SignInResult
@@ -112,7 +114,8 @@ class EmailSignInSignUpFragment : Fragment() {
112114
val email = binding.emailText.text.toString()
113115

114116
val actionResult = authClient.signIn(
115-
username = email
117+
username = email,
118+
scopes = listOf("User.Read")
116119
)
117120

118121
when (actionResult) {
@@ -250,6 +253,8 @@ class EmailSignInSignUpFragment : Fragment() {
250253
binding.resultAccessToken.text =
251254
getString(R.string.result_access_token_text) + accessToken
252255

256+
Log.d("AccessToken", accessToken)
257+
253258
val idToken = accountState.getIdToken()
254259
binding.resultIdToken.text = getString(R.string.result_id_token_text) + idToken
255260
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class SignInCodeFragment : Fragment() {
5656
_binding = FragmentCodeBinding.inflate(inflater, container, false)
5757

5858
val bundle = this.arguments
59-
currentState = bundle!!.getSerializable(Constants.STATE) as SignInCodeRequiredState
59+
currentState = (bundle?.getParcelable(Constants.STATE) as? SignInCodeRequiredState)!!
6060
codeLength = bundle.getInt(Constants.CODE_LENGTH)
6161
sentTo = bundle.getString(Constants.SENT_TO)
6262
channel = bundle.getString(Constants.CHANNEL)

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

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ 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
4344
import kotlinx.coroutines.CoroutineScope
4445
import kotlinx.coroutines.Dispatchers
4546
import kotlinx.coroutines.launch
@@ -57,7 +58,7 @@ class SignUpAttributesFragment : Fragment() {
5758
_binding = FragmentAttributeBinding.inflate(inflater, container, false)
5859

5960
val bundle = this.arguments
60-
currentState = bundle!!.getSerializable(Constants.STATE) as SignUpAttributesRequiredState
61+
currentState = (bundle?.getParcelable(Constants.STATE) as? SignUpAttributesRequiredState)!!
6162

6263
init()
6364

@@ -79,21 +80,23 @@ class SignUpAttributesFragment : Fragment() {
7980
try {
8081
val attributes = UserAttributes.Builder
8182

82-
val attr1Key = binding.attr1KeyText.text.toString()
83-
if (attr1Key.isNotBlank()) {
84-
val attr1Value = binding.attr1ValueText.toString()
85-
attributes
86-
.customAttribute(attr1Key, attr1Value)
87-
}
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+
// }
8896

89-
val attr2Key = binding.attr2KeyText.text.toString()
90-
if (attr2Key.isNotBlank()) {
91-
val attr2Value = binding.attr2ValueText.toString()
92-
attributes
93-
.customAttribute(attr2Key, attr2Value)
94-
}
97+
val testAttribute1 = UserAttributes.country("China").build()
9598

96-
val actionResult = currentState.submitAttributes(attributes.build())
99+
val actionResult = currentState.submitAttributes(testAttribute1)
97100

98101
when (actionResult) {
99102
is SignUpResult.Complete -> {
@@ -105,9 +108,17 @@ class SignUpAttributesFragment : Fragment() {
105108
signInAfterSignUp(actionResult.nextState)
106109
}
107110
is SignUpResult.AttributesRequired -> {
108-
navigateToAttributes(
109-
nextState = actionResult.nextState
110-
)
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+
}
111122
}
112123
else -> {
113124
displayDialog(getString(R.string.msal_exception_title),"Unexpected result: $actionResult")

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import com.microsoft.identity.nativeauth.statemachine.errors.SubmitCodeError
3737
import com.microsoft.identity.nativeauth.statemachine.results.SignInResult
3838
import com.microsoft.identity.nativeauth.statemachine.results.SignUpResendCodeResult
3939
import com.microsoft.identity.nativeauth.statemachine.results.SignUpResult
40+
import com.microsoft.identity.nativeauth.statemachine.states.SignInCodeRequiredState
4041
import com.microsoft.identity.nativeauth.statemachine.states.SignInContinuationState
4142
import com.microsoft.identity.nativeauth.statemachine.states.SignUpAttributesRequiredState
4243
import com.microsoft.identity.nativeauth.statemachine.states.SignUpCodeRequiredState
@@ -60,7 +61,7 @@ class SignUpCodeFragment : Fragment() {
6061
_binding = FragmentCodeBinding.inflate(inflater, container, false)
6162

6263
val bundle = this.arguments
63-
currentState = bundle!!.getSerializable(Constants.STATE) as SignUpCodeRequiredState
64+
currentState = (bundle?.getParcelable(Constants.STATE) as? SignUpCodeRequiredState)!!
6465
codeLength = bundle.getInt(Constants.CODE_LENGTH)
6566
sentTo = bundle.getString(Constants.SENT_TO)
6667
channel = bundle.getString(Constants.CHANNEL)

0 commit comments

Comments
 (0)