-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finish Save PasswordCredential via Credential Manager Api
- Loading branch information
Showing
18 changed files
with
324 additions
and
91 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
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
18 changes: 18 additions & 0 deletions
18
...ain/java/com/x8bit/bitwarden/data/autofill/password/model/PasswordGetCredentialsResult.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,18 @@ | ||
package com.x8bit.bitwarden.data.autofill.password.model | ||
|
||
/** | ||
* Represents the result of a FIDO 2 Get Credentials request. | ||
*/ | ||
sealed class PasswordGetCredentialsResult { | ||
/** | ||
* Indicates credentials were successfully queried. | ||
*/ | ||
data class Success( | ||
val data: String | ||
) : PasswordGetCredentialsResult() | ||
|
||
/** | ||
* Indicates an error was encountered when querying for matching credentials. | ||
*/ | ||
data object Error : PasswordGetCredentialsResult() | ||
} |
18 changes: 18 additions & 0 deletions
18
...java/com/x8bit/bitwarden/data/autofill/password/model/PasswordRegisterCredentialResult.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,18 @@ | ||
package com.x8bit.bitwarden.data.autofill.password.model | ||
|
||
/** | ||
* Models the data returned from creating a FIDO 2 credential. | ||
*/ | ||
sealed class PasswordRegisterCredentialResult { | ||
|
||
/** | ||
* Indicates the credential has been successfully registered. | ||
*/ | ||
data object Success : PasswordRegisterCredentialResult() | ||
|
||
/** | ||
* Indicates there was an error and the credential was not registered. | ||
*/ | ||
data object Error : PasswordRegisterCredentialResult() | ||
|
||
} |
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
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
20 changes: 20 additions & 0 deletions
20
...c/main/java/com/x8bit/bitwarden/ui/autofill/password/manager/PasswordCompletionManager.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,20 @@ | ||
package com.x8bit.bitwarden.ui.autofill.password.manager | ||
|
||
import com.x8bit.bitwarden.data.autofill.password.model.PasswordGetCredentialsResult | ||
import com.x8bit.bitwarden.data.autofill.password.model.PasswordRegisterCredentialResult | ||
|
||
/** | ||
* A manager for completing the Password creation process. | ||
*/ | ||
interface PasswordCompletionManager { | ||
|
||
/** | ||
* Completes the Password registration process with the provided [result]. | ||
*/ | ||
fun completePasswordRegistration(result: PasswordRegisterCredentialResult) | ||
|
||
/** | ||
* Complete the Password "Get credentials" process with the provided [result]. | ||
*/ | ||
fun completePasswordGetCredentialRequest(result: PasswordGetCredentialsResult) | ||
} |
52 changes: 52 additions & 0 deletions
52
...in/java/com/x8bit/bitwarden/ui/autofill/password/manager/PasswordCompletionManagerImpl.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,52 @@ | ||
package com.x8bit.bitwarden.ui.autofill.password.manager | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.os.Build | ||
import androidx.annotation.RequiresApi | ||
import androidx.credentials.CreatePasswordResponse | ||
import androidx.credentials.exceptions.CreateCredentialUnknownException | ||
import androidx.credentials.provider.PendingIntentHandler | ||
import com.x8bit.bitwarden.data.autofill.password.model.PasswordGetCredentialsResult | ||
import com.x8bit.bitwarden.data.autofill.password.model.PasswordRegisterCredentialResult | ||
import com.x8bit.bitwarden.ui.platform.manager.intent.IntentManager | ||
|
||
/** | ||
* Primary implementation of [PasswordCompletionManager] when the build version is | ||
* UPSIDE_DOWN_CAKE (34) or above. | ||
*/ | ||
@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) | ||
class PasswordCompletionManagerImpl( | ||
private val activity: Activity, | ||
private val intentManager: IntentManager, | ||
) : PasswordCompletionManager { | ||
|
||
override fun completePasswordRegistration(result: PasswordRegisterCredentialResult) { | ||
activity.also { | ||
val intent = Intent() | ||
when (result) { | ||
is PasswordRegisterCredentialResult.Error -> { | ||
PendingIntentHandler | ||
.setCreateCredentialException( | ||
intent = intent, | ||
exception = CreateCredentialUnknownException(), | ||
) | ||
} | ||
|
||
is PasswordRegisterCredentialResult.Success -> { | ||
PendingIntentHandler | ||
.setCreateCredentialResponse( | ||
intent = intent, | ||
response = CreatePasswordResponse(), | ||
) | ||
} | ||
} | ||
it.setResult(Activity.RESULT_OK, intent) | ||
it.finish() | ||
} | ||
} | ||
|
||
override fun completePasswordGetCredentialRequest(result: PasswordGetCredentialsResult) { | ||
TODO() | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...bit/bitwarden/ui/autofill/password/manager/PasswordCompletionManagerUnsupportedApiImpl.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,14 @@ | ||
package com.x8bit.bitwarden.ui.autofill.password.manager | ||
|
||
import com.x8bit.bitwarden.data.autofill.password.model.PasswordGetCredentialsResult | ||
import com.x8bit.bitwarden.data.autofill.password.model.PasswordRegisterCredentialResult | ||
|
||
/** | ||
* A no-op implementation of [PasswordCompletionManagerImpl] provided when the build version is below | ||
* UPSIDE_DOWN_CAKE (34). These versions do not support [androidx.credentials.CredentialProvider]. | ||
*/ | ||
object PasswordCompletionManagerUnsupportedApiImpl : PasswordCompletionManager { | ||
override fun completePasswordRegistration(result: PasswordRegisterCredentialResult) = Unit | ||
|
||
override fun completePasswordGetCredentialRequest(result: PasswordGetCredentialsResult) = Unit | ||
} |
Oops, something went wrong.