OneTap for Android and Micronaut

Account setup

Go to “Credentials” on the left hand side and then ‘Create credentials’ you want to create an ‘oauth client ID’
Fill in your package name, and you can retrieve the SHA-1 fingerprint for your debug certificate using the command below
keytool -keystore ~/.android/debug.keystore -list -v

Setting up the Android application

implementation 'com.google.android.gms:play-services-auth:18.0.0
implementation "androidx.fragment:fragment:1.3.0-alpha06"
implementation "androidx.fragment:fragment-ktx:1.3.0-alpha06"
<string name="one_tap_client_id"></string>
signUpResult.launch(
IntentSenderRequest.Builder(result.pendingIntent)
.build()
)
private fun errorHandler(onError: (() -> Unit)? = null): CoroutineExceptionHandler {
return CoroutineExceptionHandler { _, e ->
onError?.invoke()
Log.e(
TAG,
e.localizedMessage ?: "",
e
)
}
}
Log.d(TAG, "Got ID token.")
Log.d(TAG, "Got ID token. $token")

Implementing the backend

mn create-application OneTapAuthenticator -l kotlin -f security-jwt
micronaut:
security:
enabled: true
endpoints:
login:
enabled: true
token:
jwt:
enabled: true
signatures:
secret:
generator:
secret: "${JWT_GENERATOR_SIGNATURE_SECRET:pleaseChangeThisSecretForANewOne}"
mn create-controller CreateCheckerController
@Controller("/authenticated")
class CertificateCheckerController {

@Secured(SecurityRule.IS_AUTHENTICATED)
@Get("/verification")
fun verify(principal: Principal?) =
principal

}
curl http://localhost:8080/authenticated/verification

Allow authentication in the app

implementation 'com.google.api-client:google-api-client:1.30.9'
  • The singleton / token validator means this will be used when a client has a Bearer token
  • The token passed in is a JWT — the one that is generated in your android app (idToken)
  • The rest is calling through to the Google client API to verify the certificate. We take the payload and return the authentication response
curl -H "Authorization: Bearer <your token from the android app>" http://localhost:8080/authenticated/verification  -v

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Create Custom Android App to Control Arduino Board Using Bluetooth

A simple way to add assets and images to pubsbec.yaml

Android Chunks View

How to use Shimmer in Android

Experimenting new Admob Open AD

Top 3 Ways to Install Android on PC

Android Dev | Tinder Swipe Card

Using Firebase In-App-Messaging on an Android app

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Daniel Llewellyn

Daniel Llewellyn

More from Medium

Android Static analysis- How to pull APK?

Application Framework Introduction.(Part-II)

Pixel Vault

Score Implementation Pt 2./Lives Display