Skip to content

Commit

Permalink
Sign In With Google for MSA federation (No broker), Fixes AB#3100601 (#…
Browse files Browse the repository at this point in the history
…2551)

This pull request adds the Sign In With Google flow to support MSA
federation in Android Common

1. Add abstract class interface to support federated sign ins
(FederatedSignInProviderFactory, IFederatedSignInProvider,
FederatedSignInParameters, FederatedCredential). This can be used for
specific sign in providers like Google. These are thin classes.
2. Add implementation for google (GoogleSignInProvider,
SignInWithGoogleParameters, SignInWithGoogleCredential).
GoogleSignInProvider uses credential manager to get allow user to sign
select google account or added new google account on device and get
credentials for it. Credential is essentially google idtoken. This is
abstracted in SignInWithGoogleCredential and returned to the caller.
SignInWithGoogleParameters include inputs that are used to run the sign
in flow, contains activity/context and whether to use bottom sheet UX or
not. By default dialog is launched (based on Sign in with google button
which is part of UX/PM spec).
3. SignInWithGoogleApi is entry point to start sign in flow and utilizes
above internal classes. This would be exposed to OneAuth.
4. OneAuth interacts with common for performing authorization using
WebView. To launch authorization UX it uses,
AuthorizationActivityFactory methods to get an intent which is later on
launched in the activity or fragment. We expose two methods in this
class to allow sign in with google.

AuthorizationActivityFactory.signInWithGoogleAndGetAuthorizationActivityIntent
- first uses google sign in classes to collect google credentials and
prepares intent based on that. This is intent is returned to caller.
AuthorizationActivityFactory.getAuthorizationActivityIntent(...,
SignInWithGoogleCredential) - If the caller has acquired google sign in
credential previously using SignInWithGoogleApi, then it should call
this method to create intent which would use the credential for running
authorization flow.
The authorization flow is scoped to MSA (v2/consumers endpoint)
5. Broker should be able to use the code in common to get the
credential.
6. Added unit tests cases.



![image](https://github.com/user-attachments/assets/004eeb84-6235-4d3a-be22-36ab7b58e0b4)

Fixes
[AB#3100601](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3100601)
  • Loading branch information
mohitc1 authored Jan 3, 2025
1 parent 690be86 commit 00aace6
Show file tree
Hide file tree
Showing 23 changed files with 1,313 additions and 26 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
vNext
----------
- [MINOR] Add Sign in With Google component for MSA federation (#2551)
- [MINOR] Add SDMBroadcastReceiver for applications to register callbacks for SDM broadcasts (#2547)
- [MINOR] Add switch_browser toMicrosoftStsAuthorizationRequest (#2550)
- [MAJOR] Add suberror for network errors (#2537)
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ dependencies {
//needed for credentials support from play services, for devices running
implementation "androidx.credentials:credentials-play-services-auth:$rootProject.ext.AndroidCredentialsVersion"
implementation "com.google.android.gms:play-services-fido:$rootProject.ext.LegacyFidoApiVersion"
implementation "com.google.android.libraries.identity.googleid:googleid:$rootProject.ext.GoogleIdVersion"

constraints {
implementation ("com.squareup.okio:okio:3.4.0") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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.common.internal.msafederation

/**
* Represents credential artifact as result of successful sign in into a federated sign in provider
* (Google/Apple). It can contain id token and/or auth code. See implementations for more details.
*/
abstract class FederatedCredential(val federatedSignInProviderName: FederatedSignInProviderName)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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.common.internal.msafederation

/**
* Parameters for Federated Sign In. e.g. SignInWithGoogleParameters for Google.
*/
abstract class FederatedSignInParameters {
abstract val providerName: FederatedSignInProviderName
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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.common.internal.msafederation

import com.microsoft.identity.common.internal.msafederation.google.GoogleSignInProvider
import com.microsoft.identity.common.internal.msafederation.google.SignInWithGoogleParameters

/**
* Factory class to get the Federated Sign In Provider based on provider type in parameters
* Currently only Google is supported.
*/
internal object FederatedSignInProviderFactory {

/**
* Get the Federated Sign In Provider based on provider type in parameters.
*/
fun getProvider(parameters: FederatedSignInParameters): IFederatedSignInProvider {
return when (parameters.providerName) {
FederatedSignInProviderName.GOOGLE -> GoogleSignInProvider.create(parameters as SignInWithGoogleParameters, MsaFederationConstants.GOOGLE_MSA_WEB_CLIENT_ID)

else -> {
throw IllegalArgumentException("Unsupported provider type")
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.common.internal.msafederation

/**
* Enum class for Federated Sign In Provider Name like Google, Apple
* Currently only Google is supported.
*/
enum class FederatedSignInProviderName(private val idProviderName: String) {
GOOGLE("google.com"),
APPLE("apple.com"); // would be used later

fun getIdProviderName(): String {
return idProviderName
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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.common.internal.msafederation

/**
* Interface for Federated Credential Callback. Helps calling sign methods
* async from java.
*/
interface IFederatedCredentialCallback<R : FederatedCredential> {
/**
* Called when the sign in is successful.
*/
fun onSuccess(credential: R)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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.common.internal.msafederation

/**
* Internal interface for Federated Sign In Providers.
*/
internal interface IFederatedSignInProvider {
suspend fun signIn(): Result<FederatedCredential>
suspend fun signOut()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.common.internal.msafederation

/**
* Constants used in MSA federation.
*/
internal object MsaFederationConstants {
internal const val SIWG_TEST_WEBCLIENT_ID = "421268256362-r39ud27ddaajrcio0c8iq6snv3po43fb.apps.googleusercontent.com"
internal const val GOOGLE_MSA_WEB_CLIENT_ID = "1057459215779-l3uvdm899ucea09atcc09d9rq6uvkilv.apps.googleusercontent.com"
internal const val MSA_ID_TOKEN_HEADER_KEY = "x-ms-fidp-idtoken"
internal const val MSA_ID_PROVIDER_EXTRA_QUERY_PARAM_KEY = "id_provider"
}
Loading

0 comments on commit 00aace6

Please sign in to comment.