Skip to content

Instantly share code, notes, and snippets.

View adrianhall's full-sized avatar

Adrian Hall adrianhall

View GitHub Profile
custom:
appSync:
name : ${self:provider.apiname}
region : ${self:provider.region}
authenticationType : AWS_IAM
serviceRole : "AppSyncServiceRole"
#=======================================================================================
IdentityPool:
Type : AWS::Cognito::IdentityPool
Description : "Federation for the User Pool members to access AWS resources"
Properties:
IdentityPoolName : ${self:provider.apiname}_identities
AllowUnauthenticatedIdentities : true
CognitoIdentityProviders:
- ClientId : { Ref: AndroidUserPoolClient }
ProviderName : { Fn::Sub: [ 'cognito-idp.${self:provider.region}.amazonaws.com/#{client}', { "client": { Ref: CognitoUserPoolMyPool }}]}
#=======================================================================================
AuthRole:
Type : AWS::IAM::Role
Description : "Role that the an authenticated user assumes"
Properties:
RoleName : ${self:provider.apiname}-auth
AssumeRolePolicyDocument:
Version : "2012-10-17"
Statement:
- Effect : Allow
#=======================================================================================
CognitoUserPoolMyPool:
Type : AWS::Cognito::UserPool
Description : "Username / Password auth database"
Properties:
UserPoolName : ${self:provider.apiname}
Schema:
- Name : email
Required : true
Mutable : true
/**
* Load the data from the biometric store and populate the right fields
*/
private fun loadFromBiometricStore() {
if (whorlwind?.canStoreSecurely() == true) {
val disposable = whorlwind!!.read("password")
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { result ->
when (result.readState) {
/**
* Save the current form data to the biometric store
*/
private fun saveToBiometricStore(password: String) {
if (whorlwind?.canStoreSecurely() == true) {
val disposable = Observable.just(password)
.observeOn(Schedulers.io())
.flatMapCompletable {value ->
whorlwind?.write("password", ByteString.encodeUtf8(value))
}
IdentityRequest.SUCCESS -> {
analyticsService.recordSuccessfulLogin(loginFormUsernameField.text.toString())
model.updateStoredUsername(loginFormUsernameField.text.toString())
saveToBiometricStore(loginFormPasswordField.text.toString())
[email protected]()
}
/**
* Callback for when the permissions has been requested and responded to.
*/
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
when (requestCode) {
REQUEST_PERMISSIONS_FINGERPRINT -> {
checkedPermissions = true
hasPermissions = (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)
}
// Ask for permission to use the fingerprint scanner
if (fingerprintManager.isHardwareDetected) {
if (checkSelfPermission(Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
if (checkedPermissions) {
hasPermissions = false
} else {
requestPermissions(arrayOf(Manifest.permission.USE_FINGERPRINT), REQUEST_PERMISSIONS_FINGERPRINT)
}
} else {
hasPermissions = true
class AuthenticatorActivity : AppCompatActivity() {
companion object {
private const val REQUEST_PERMISSIONS_FINGERPRINT = 90001
}
private val model by viewModel<AuthenticatorViewModel>()
private val analyticsService by inject<AnalyticsService>()
// For permissions checks
private var checkedPermissions = false