identity-samples icon indicating copy to clipboard operation
identity-samples copied to clipboard

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

Open isra9711 opened this issue 1 year ago • 1 comments
trafficstars

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)
        }
    }

isra9711 avatar Jul 24 '24 17:07 isra9711

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

aarchish avatar Jul 26 '24 08:07 aarchish

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

niharika2810 avatar Aug 30 '24 06:08 niharika2810