This file contains hidden or 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
private fun signup() { | |
lifecycleScope.launch(errorHandler()) { | |
val result = oneTapClient.suspendBeginSignInRequest(buildSignupRequest()) | |
signUpResult.launch( | |
IntentSenderRequest.Builder(result.pendingIntent) | |
.build() | |
) | |
} | |
} |
This file contains hidden or 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
private val signUpResult = | |
registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { | |
try { | |
val credential = oneTapClient.getSignInCredentialFromIntent(it.data) | |
val idToken = credential.googleIdToken | |
when { | |
idToken != null -> { | |
// Got an ID token from Google. Use it to authenticate | |
// with your backend. | |
Log.d(TAG, "Got ID token.") |
This file contains hidden or 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
private val oneTapClient: SignInClient by lazy { | |
Identity.getSignInClient(this) | |
} | |
lifecycleScope.launch(CoroutineExceptionHandler { _, e -> | |
Log.e( | |
TAG, | |
e.localizedMessage ?: "", | |
e | |
) | |
}) { |
This file contains hidden or 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
private fun buildSignupRequest() = BeginSignInRequest.builder() | |
.setGoogleIdTokenRequestOptions( | |
BeginSignInRequest.GoogleIdTokenRequestOptions.builder() | |
.setSupported(true) | |
.setServerClientId(getString(R.string.one_tap_client_id)) | |
.setFilterByAuthorizedAccounts(false) | |
.build() | |
) | |
.build() |
This file contains hidden or 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
suspend fun SignInClient.suspendBeginSignInRequest(beginSignInRequest: BeginSignInRequest) :BeginSignInResult = | |
suspendCoroutine { continuation -> | |
beginSignIn(beginSignInRequest).addOnSuccessListener { | |
continuation.resume(it) | |
} | |
.addOnFailureListener { | |
continuation.resumeWithException(it) | |
} | |
} |
This file contains hidden or 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
data class AuthenticationInternalClaims(val payload: GoogleIdToken.Payload) : Authentication { | |
override fun getName(): String = payload.subject | |
override fun getAttributes(): MutableMap<String, Any> = payload // Don't actually do this... | |
} | |
@Singleton | |
class GoogleAuthenticationHandler : TokenValidator { | |
override fun validateToken(token: String?): Flowable<Authentication> { |
This file contains hidden or 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
@Named("generator") | |
class OtherCustomTokenValidator : RSASignatureConfiguration { | |
override fun getPublicKey(): RSAPublicKey { | |
val decoder = Base64.getDecoder() | |
val spec = X509EncodedKeySpec(decoder.decode("USERESULTOFPYTHONSCRIPTHERE")) | |
val kf: KeyFactory = KeyFactory.getInstance("RSA") | |
return kf.generatePublic(spec) as RSAPublicKey | |
} | |
} |
This file contains hidden or 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
@Controller("/loin") | |
class CustomTokenController { | |
@Secured(SecurityRule.IS_ANONYMOUS) | |
@Get("/logmein") | |
fun getLogin(principal: Principal) : String { | |
FirebaseUtil.initialise() | |
return FirebaseAuth.getInstance().createCustomToken(principal.name) | |
} | |
} |
This file contains hidden or 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
@Secured(SecurityRule.IS_ANONYMOUS) | |
@Controller("/authenticated") | |
class CertificateCheckerController { | |
@Secured(SecurityRule.IS_AUTHENTICATED) | |
@Get("/verification") | |
fun verify(principal: Principal?) = | |
principal |