-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sign In With Google for MSA federation (No broker), Fixes AB#3100601 (#…
…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
Showing
23 changed files
with
1,313 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...src/main/java/com/microsoft/identity/common/internal/msafederation/FederatedCredential.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
30 changes: 30 additions & 0 deletions
30
...in/java/com/microsoft/identity/common/internal/msafederation/FederatedSignInParameters.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
47 changes: 47 additions & 0 deletions
47
...va/com/microsoft/identity/common/internal/msafederation/FederatedSignInProviderFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} | ||
} | ||
|
36 changes: 36 additions & 0 deletions
36
.../java/com/microsoft/identity/common/internal/msafederation/FederatedSignInProviderName.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...java/com/microsoft/identity/common/internal/msafederation/IFederatedCredentialCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
31 changes: 31 additions & 0 deletions
31
...ain/java/com/microsoft/identity/common/internal/msafederation/IFederatedSignInProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
33 changes: 33 additions & 0 deletions
33
.../main/java/com/microsoft/identity/common/internal/msafederation/MsaFederationConstants.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Oops, something went wrong.