android / identity-samples

Multiple samples showing the best practices in identity on Android.
Apache License 2.0
338 stars 211 forks source link

Documentation Error, CredentialManager method specifically in credentialManager.createCredential(request, requireActivity()) as CreatePasswordResponse #93

Closed isra9711 closed 1 week ago

isra9711 commented 1 month ago
Method expect : 
public open suspend fun createCredential(
    context: Context,
    request: CreateCredentialRequest
): CreateCredentialResponse
Registers a user credential that can be used to authenticate the user to the app in the future.
The execution potentially launches framework UI flows for a user to view their registration options, grant consent, etc.
Params:
context - the context used to launch any UI needed; use an activity context to make sure the UI will be launched within the same task stack
request - the request for creating the credential
Throws:
CreateCredentialException - If the request fails

Incorrect code :

private suspend fun createPassword() {

        //TODO : CreatePasswordRequest with entered username and password
        val request = CreatePasswordRequest(
            binding.username.text.toString(),
            binding.password.text.toString()
        )
        //TODO : Create credential with created password request
        try {
            credentialManager.createCredential(request, requireActivity()) as CreatePasswordResponse
        } catch (e: Exception) {
            Log.e("Auth", " Exception Message : " + e.message)
        }
    }
**Correct code should look :** 
        private suspend fun createPassword() {

        //TODO : CreatePasswordRequest with entered username and password
        val request = CreatePasswordRequest(
            binding.username.text.toString(),
            binding.password.text.toString()
        )
        //TODO : Create credential with created password request
        try {
            credentialManager.createCredential(requireActivity(), request) as CreatePasswordResponse
        } catch (e: Exception) {
            Log.e("Auth", " Exception Message : " + e.message)
        }
    }
aarchish commented 1 month ago

Thank you for the correction. I would have been stuck pretty bad.

niharika2810 commented 1 week ago

Hi tank you for sharing, We have already updated the code sometime back. Please check and let me know if there's an issue or I missed anything? Feel free to reopen