Skip to content

Commit

Permalink
Merge pull request #48 from android/beta_changes
Browse files Browse the repository at this point in the history
Beta changes
  • Loading branch information
niharika2810 committed Jul 27, 2023
2 parents d054b7c + 8e0fc04 commit cbf2f56
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
8 changes: 4 additions & 4 deletions CredentialManager/app/build.gradle
Expand Up @@ -31,11 +31,11 @@ keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
namespace 'com.google.credentialmanager.sample'
compileSdkVersion 33
compileSdkVersion 34
defaultConfig {
applicationId "com.google.credentialmanager.sample"
minSdk 21
targetSdk 33
targetSdk 34
versionCode 1
versionName "1.0"

Expand Down Expand Up @@ -100,8 +100,8 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

implementation 'androidx.credentials:credentials:1.0.0-alpha06'
implementation 'androidx.credentials:credentials-play-services-auth:1.0.0-alpha06'
implementation 'androidx.credentials:credentials-play-services-auth:1.2.0-beta01'
implementation 'androidx.credentials:credentials:1.2.0-beta01'

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
Expand Down
2 changes: 1 addition & 1 deletion CredentialManager/app/src/main/assets/AuthFromServer
@@ -1,6 +1,6 @@
{
"challenge": "HjBbH__fbLuzy95AGR31yEARA0EMtKlY0NrV5oy3NQw",
"timeout": 1800000,
"userVerification": "",
"userVerification": "required",
"rpId": "passkeys-codelab.glitch.me"
}
Expand Up @@ -23,6 +23,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.credentials.CredentialManager
import androidx.credentials.CustomCredential
import androidx.credentials.GetCredentialRequest
import androidx.credentials.GetPasswordOption
import androidx.credentials.GetPublicKeyCredentialOption
Expand Down Expand Up @@ -104,17 +105,17 @@ class SignInFragment : Fragment() {

private suspend fun getSavedCredentials(): String? {
val getPublicKeyCredentialOption =
GetPublicKeyCredentialOption(fetchAuthJsonFromServer(), null, true)
GetPublicKeyCredentialOption(fetchAuthJsonFromServer(), null)
val getPasswordOption = GetPasswordOption()
val result = try {
credentialManager.getCredential(
requireActivity(),
GetCredentialRequest(
listOf(
getPublicKeyCredentialOption,
getPasswordOption
)
),
requireActivity()
)
)
} catch (e: Exception) {
configureViews(View.INVISIBLE, true)
Expand All @@ -135,7 +136,10 @@ class SignInFragment : Fragment() {
DataProvider.setSignedInThroughPasskeys(false)
return "Got Password - User:${cred.id} Password: ${cred.password}"
}

if (result.credential is CustomCredential) {
//If you are also using any external sign-in libraries, parse them here with the
// utility functions provided.
}
return null
}

Expand Down
Expand Up @@ -31,11 +31,11 @@ import androidx.credentials.CreatePublicKeyCredentialRequest
import androidx.credentials.CreatePublicKeyCredentialResponse
import androidx.credentials.CredentialManager
import androidx.credentials.exceptions.CreateCredentialCancellationException
import androidx.credentials.exceptions.CreateCredentialCustomException
import androidx.credentials.exceptions.CreateCredentialException
import androidx.credentials.exceptions.CreateCredentialInterruptedException
import androidx.credentials.exceptions.CreateCredentialProviderConfigurationException
import androidx.credentials.exceptions.CreateCredentialUnknownException
import androidx.credentials.exceptions.CreateCustomCredentialException
import androidx.credentials.exceptions.publickeycredential.CreatePublicKeyCredentialDomException
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -175,7 +175,7 @@ class SignUpFragment : Fragment() {
binding.password.text.toString()
)
try {
credentialManager.createCredential(request, requireActivity()) as CreatePasswordResponse
credentialManager.createCredential(requireActivity(), request) as CreatePasswordResponse
} catch (e: Exception) {
Log.e("Auth", "createPassword failed with exception: " + e.message)
}
Expand All @@ -186,8 +186,8 @@ class SignUpFragment : Fragment() {
var response: CreatePublicKeyCredentialResponse? = null
try {
response = credentialManager.createCredential(
request,
requireActivity()
requireActivity(),
request
) as CreatePublicKeyCredentialResponse
} catch (e: CreateCredentialException) {
configureProgress(View.INVISIBLE)
Expand Down Expand Up @@ -232,7 +232,7 @@ class SignUpFragment : Fragment() {
is CreateCredentialUnknownException -> {
"An unknown error occurred while creating passkey. Check logs for additional details."
}
is CreateCustomCredentialException -> {
is CreateCredentialCustomException -> {
// You have encountered an error from a 3rd-party SDK. If you
// make the API call with a request object that's a subclass of
// CreateCustomCredentialRequest using a 3rd-party SDK, then you
Expand Down

0 comments on commit cbf2f56

Please sign in to comment.