Skip to content

Instantly share code, notes, and snippets.

View PaulTR's full-sized avatar

Paul Ruiz PaulTR

  • Google
  • Boulder, Colorado, USA
View GitHub Profile
fun handleAuthorizationResponse(intent: Intent) {
val authorizationResponse : AuthorizationResponse? = AuthorizationResponse.fromIntent(intent)
val error = AuthorizationException.fromIntent(intent)
authState = AuthState(authorizationResponse, error)
val authorizationLauncher = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()){
result ->
run {
if (result.resultCode == Activity.RESULT_OK) {
handleAuthorizationResponse(result.data!!)
}
}
}
val request = builder.build()
val authIntent = authorizationService.getAuthorizationRequestIntent(request)
launchForResult(authIntent)
val parameters = HashMap<String, String>()
paramters.put("Example", "Example")
builder.setAdditionalParameters(parameters)
val builder = AuthorizationRequest.Builder(
authServiceConfig,
Constants.CLIENT_ID,
ResponseTypeValues.CODE,
Uri.parse(Constants.URL_AUTH_REDIRECT))
.setCodeVerifier(codeVerifier,
codeChallenge,
Constants.CODE_VERIFIER_CHALLENGE_METHOD)
builder.setScopes(Constants.SCOPE_PROFILE,
val digest = MessageDigest.getInstance(Constants.MESSAGE_DIGEST_ALGORITHM)
val hash = digest.digest(codeVerifier.toByteArray())
val codeChallenge = Base64.encodeToString(hash, encoding)
val secureRandom = SecureRandom()
val bytes = ByteArray(64)
secureRandom.nextBytes(bytes)
val encoding = Base64.URL_SAFE or Base64.NO_PADDING or Base64.NO_WRAP
val codeVerifier = Base64.encodeToString(bytes, encoding)
fun attemptAuthorization() {
}
private fun initAuthService() {
val appAuthConfiguration = AppAuthConfiguration.Builder()
.setBrowserMatcher(
BrowserAllowList(
VersionedBrowserMatcher.CHROME_CUSTOM_TAB,
VersionedBrowserMatcher.SAMSUNG_CUSTOM_TAB
)
).build()
authorizationService = AuthorizationService(
private fun initAuthServiceConfig() {
authServiceConfig = AuthorizationServiceConfiguration(
Uri.parse(Constants.URL_AUTHORIZATION),
Uri.parse(Constants.URL_TOKEN_EXCHANGE),
null,
Uri.parse(Constants.URL_LOGOUT))
}