Skip to content

Commit 1b85f0b

Browse files
committed
sign out
1 parent ef5ab7f commit 1b85f0b

File tree

5 files changed

+43
-6
lines changed

5 files changed

+43
-6
lines changed

common/src/main/java/com/microsoft/identity/common/internal/msafederation/google/GoogleSignInProvider.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import com.google.android.libraries.identity.googleid.GoogleIdTokenParsingExcept
3535
import com.microsoft.identity.common.internal.msafederation.IFederatedSignInProvider
3636
import com.microsoft.identity.common.java.base64.Base64Util
3737
import com.microsoft.identity.common.java.exception.ClientException
38+
import com.microsoft.identity.common.logging.Logger
3839
import java.security.SecureRandom
3940

4041
/**
@@ -126,6 +127,7 @@ internal class GoogleSignInProvider(private val credentialManager: CredentialMan
126127
private suspend fun getCredential(
127128
option: GetCustomCredentialOption
128129
) : Result<SignInWithGoogleCredential> {
130+
val methodTag = "$TAG:getCredential"
129131
val getCredentialRequest: GetCredentialRequest = GetCredentialRequest.Builder()
130132
.addCredentialOption(option)
131133
.build()
@@ -151,26 +153,37 @@ internal class GoogleSignInProvider(private val credentialManager: CredentialMan
151153
)
152154
} catch (e: GoogleIdTokenParsingException) {
153155
// error parsing Google ID Token
154-
return Result.failure(e)
156+
Logger.warn(TAG, "Error parsing Google ID Token, $e.message")
157+
val clientException = ClientException(
158+
ClientException.SIGN_IN_WITH_GOOGLE_FAILED,
159+
e.message,
160+
e
161+
)
162+
return Result.failure(clientException)
155163
}
156164
} else {
157165
// unsupported credential type
166+
val errorMessage = "Unsupported credential type, " + credential.type
167+
Logger.warn(TAG, errorMessage)
158168
val clientException = ClientException(
159169
ClientException.SIGN_IN_WITH_GOOGLE_FAILED,
160-
"Unsupported credential type" + credential.type
170+
errorMessage
161171
)
162172
return Result.failure(clientException)
163173
}
164174
} else {
165175
// Unexpected credential type
176+
val errorMessage = "Unexpected credential type" + credential.javaClass.simpleName
177+
Logger.warn(TAG, errorMessage)
166178
val clientException = ClientException(
167179
ClientException.SIGN_IN_WITH_GOOGLE_FAILED,
168-
"Unexpected credential type" + credential.javaClass.simpleName
180+
errorMessage
169181
)
170182
return Result.failure(clientException)
171183
}
172184
} catch (e: GetCredentialException) {
173185
// failure
186+
Logger.warn(TAG, "Error getting google id token credential, $e.message")
174187
val clientException = ClientException(
175188
ClientException.SIGN_IN_WITH_GOOGLE_FAILED,
176189
e.message,

common/src/main/java/com/microsoft/identity/common/internal/msafederation/google/SignInWithGoogleApi.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// THE SOFTWARE.
2323
package com.microsoft.identity.common.internal.msafederation.google
2424

25+
import android.app.Activity
2526
import com.microsoft.identity.common.internal.msafederation.FederatedSignInProviderFactory
2627
import kotlinx.coroutines.CoroutineScope
2728
import kotlinx.coroutines.Dispatchers
@@ -96,4 +97,12 @@ class SignInWithGoogleApi internal constructor(
9697
}
9798
}
9899
}
100+
101+
suspend fun signOut(activity: Activity) {
102+
val signInWithGoogleParameters = SignInWithGoogleParameters(activity)
103+
val googleSignInProvider = federatedSignInProviderFactory.getProvider(
104+
signInWithGoogleParameters
105+
)
106+
googleSignInProvider.signOut()
107+
}
99108
}

common/src/test/java/com/microsoft/identity/common/internal/msafederation/google/GoogleSignInProviderTest.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package com.microsoft.identity.common.internal.msafederation.google
2424

2525
import android.app.Activity
26+
import androidx.credentials.ClearCredentialStateRequest
2627
import androidx.credentials.CredentialManager
2728
import androidx.credentials.GetCredentialRequest
2829
import androidx.credentials.GetCredentialResponse
@@ -31,6 +32,7 @@ import com.google.android.libraries.identity.googleid.GetSignInWithGoogleOption
3132
import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential
3233
import com.microsoft.identity.common.internal.msafederation.MsaFederationConstants
3334
import io.mockk.coEvery
35+
import io.mockk.coVerify
3436
import io.mockk.mockk
3537
import io.mockk.slot
3638
import kotlinx.coroutines.runBlocking
@@ -83,7 +85,7 @@ class GoogleSignInProviderTest {
8385
}
8486

8587
@Test
86-
fun testSignInWithBottomSheet() {
88+
fun testSignInBottomSheet() {
8789
val mockCredentialManager = mockk<CredentialManager>()
8890
val mockActivity = mockk<Activity>()
8991
val mockParameters = SignInWithGoogleParameters(mockActivity, true)
@@ -119,4 +121,17 @@ class GoogleSignInProviderTest {
119121
val capturedActivity = activitySlot.captured
120122
assertSame(mockActivity, capturedActivity)
121123
}
124+
125+
@Test
126+
fun testSignOut() {
127+
val mockCredentialManager = mockk<CredentialManager>()
128+
val mockActivity = mockk<Activity>()
129+
val mockParameters = SignInWithGoogleParameters(mockActivity)
130+
val webClientId = MsaFederationConstants.GOOGLE_MSA_WEB_CLIENT_ID
131+
val googleSignInProvider = GoogleSignInProvider(mockCredentialManager, mockParameters, webClientId)
132+
133+
coEvery { mockCredentialManager.clearCredentialState(any()) } returns Unit
134+
runBlocking { googleSignInProvider.signOut() }
135+
coVerify { mockCredentialManager.clearCredentialState(any<ClearCredentialStateRequest>()) }
136+
}
122137
}

common/src/test/java/com/microsoft/identity/common/internal/msafederation/google/MockGoogleSignInProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ class MockGoogleSignInProvider : IFederatedSignInProvider {
3333
}
3434

3535
override suspend fun signOut() {
36-
TODO("Not yet implemented")
36+
// No-op
3737
}
3838
}

common/src/test/java/com/microsoft/identity/common/internal/msafederation/google/SignInWithGoogleParametersTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import org.robolectric.Robolectric
3333
import org.robolectric.RobolectricTestRunner
3434

3535
/**
36-
* Tests for []SignInWithGoogleParameters].
36+
* Tests for [SignInWithGoogleParameters].
3737
*/
3838
@RunWith(RobolectricTestRunner::class)
3939
class SignInWithGoogleParametersTest {

0 commit comments

Comments
 (0)