Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native auth to MSAL test app #2001

Merged
merged 16 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
msal/src/main/java/com/microsoft/identity/nativeauth/ @AzureAD/NativeAuthTeam
msal/src/test/java/com/microsoft/identity/nativeauth/ @AzureAD/NativeAuthTeam
msal/src/androidTest/java/com/microsoft/identity/nativeauth/ @AzureAD/NativeAuthTeam
msal/testapps/testapp/src/main/java/com/microsoft/identity/client/testapp/nativeauth @AzureAD/NativeAuthTeam

# If you are interested in reviewing or getting notified of changes in a particular area
# Please add your alias against that specific path below
Expand Down
11 changes: 11 additions & 0 deletions testapps/testapp/build.gradle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be able to test the proguard rules in the dist variant of the test app now, since we incorporate native auth into it.

Copy link
Contributor

@Yuki-YuXin Yuki-YuXin Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yuki-YuXin this is because test app is pulling an outdated MSAL version (4.x), one that doesn't have native auth included yet. I'll update this in the PR.

Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'


def msalVersion = "5.0.0"


if (project.hasProperty("distMsalVersion")) {
msalVersion = distMsalVersion
}
Expand Down Expand Up @@ -83,6 +89,9 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do? and why is it needed?

Copy link
Contributor Author

@SammyO SammyO Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do

https://developer.android.com/topic/libraries/view-binding

why is it needed?

It's a much improved process of managing view (interactions, etc.) that has been rolled out by Android for quite some time. New and improved way of doing things.

viewBinding true
}
lintOptions {
abortOnError false
}
Expand Down Expand Up @@ -111,6 +120,8 @@ dependencies {
localImplementation project(':msal')
distImplementation "com.microsoft.identity.client:msal:${msalVersion}"
implementation "com.google.code.gson:gson:$rootProject.ext.gsonVersion"
implementation "androidx.constraintlayout:constraintlayout:$rootProject.ext.constraintLayoutVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.ext.kotlinXCoroutinesVersion"
implementation "androidx.appcompat:appcompat:$rootProject.ext.appCompatVersion"
implementation "androidx.legacy:legacy-support-v4:$rootProject.ext.legacySupportV4Version"
implementation "com.google.android.material:material:$rootProject.ext.materialVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ public boolean onNavigationItemSelected(final MenuItem item) {
return false;
}
fragment = new AcquireTokenFragment();
} else if ( menuItemId == R.id.nav_native) {
if (getCurrentFragment() instanceof NativeAuthFragment){
return false;
}
fragment = new NativeAuthFragment();
} else if (menuItemId == R.id.nav_result) {
if (getCurrentFragment() instanceof ResultFragment){
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.identity.client.testapp

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.microsoft.identity.client.testapp.nativeauth.AuthClient
import com.microsoft.identity.client.testapp.nativeauth.EmailAttributeSignUpFragment
import com.microsoft.identity.client.testapp.nativeauth.EmailPasswordSignInSignUpFragment
import com.microsoft.identity.client.testapp.nativeauth.EmailSignInSignUpFragment
import com.microsoft.identity.client.testapp.nativeauth.PasswordResetFragment

class NativeAuthFragment : Fragment() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadoc on all classes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't see javadoc on this particular class though

companion object {
private val TAG = MainActivity::class.java.simpleName
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val view = inflater.inflate(R.layout.fragment_native, container, false)

AuthClient.initialize(requireContext())

val emailSignInSignUpFragment = EmailSignInSignUpFragment()
val emailPasswordSignInSignUpFragment = EmailPasswordSignInSignUpFragment()
val emailAttributeSignUpFragment = EmailAttributeSignUpFragment()
val passwordResetFragment = PasswordResetFragment()

val bottomNavigationView = view.findViewById<BottomNavigationView>(R.id.bottom_navigation_view)

setFragment(emailSignInSignUpFragment, R.string.title_email_oob_sisu)

bottomNavigationView.setOnNavigationItemSelectedListener {
when (it.itemId) {
R.id.email_oob_sisu -> setFragment(emailSignInSignUpFragment, R.string.title_email_oob_sisu)
R.id.email_password_sisu -> setFragment(emailPasswordSignInSignUpFragment, R.string.title_email_password_sisu)
R.id.email_attribute_sisu -> setFragment(emailAttributeSignUpFragment, R.string.title_email_attribute_oob_sisu)
R.id.email_oob_sspr -> setFragment(passwordResetFragment, R.string.title_email_oob_sspr)
}
true
}

return view
}

private fun setFragment(fragment: Fragment, title: Int) {
(this.context as AppCompatActivity).supportFragmentManager.beginTransaction().apply {
replace(R.id.scenario_fragment, fragment)
commit()
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line ending; here and everywhere

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.identity.client.testapp.nativeauth

import android.app.Application
import android.content.Context
import com.microsoft.identity.client.PublicClientApplication
import com.microsoft.identity.client.testapp.R
import com.microsoft.identity.nativeauth.INativeAuthPublicClientApplication

object AuthClient : Application() {
private lateinit var authClient: INativeAuthPublicClientApplication

fun getAuthClient(): INativeAuthPublicClientApplication {
return authClient
}

fun initialize(context: Context) {
authClient = PublicClientApplication.createNativeAuthPublicClientApplication(
context,
R.raw.msal_config_native
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.identity.client.testapp.nativeauth

interface Constants {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadoc everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

companion object {
const val STATE = "state"
const val CODE_LENGTH = "code_length"
const val SENT_TO = "sent_to"
const val CHANNEL = "channel"
}
}
Loading