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
fun handleAuthorizationResponse(intent: Intent) { | |
val authorizationResponse : AuthorizationResponse? = AuthorizationResponse.fromIntent(intent) | |
val error = AuthorizationException.fromIntent(intent) | |
authState = AuthState(authorizationResponse, error) |
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
val authorizationLauncher = registerForActivityResult( | |
ActivityResultContracts.StartActivityForResult()){ | |
result -> | |
run { | |
if (result.resultCode == Activity.RESULT_OK) { | |
handleAuthorizationResponse(result.data!!) | |
} | |
} | |
} |
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
val request = builder.build() | |
val authIntent = authorizationService.getAuthorizationRequestIntent(request) | |
launchForResult(authIntent) |
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
val parameters = HashMap<String, String>() | |
paramters.put("Example", "Example") | |
builder.setAdditionalParameters(parameters) |
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
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, |
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
val digest = MessageDigest.getInstance(Constants.MESSAGE_DIGEST_ALGORITHM) | |
val hash = digest.digest(codeVerifier.toByteArray()) | |
val codeChallenge = Base64.encodeToString(hash, encoding) |
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
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) |
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
fun attemptAuthorization() { | |
} |
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
private fun initAuthService() { | |
val appAuthConfiguration = AppAuthConfiguration.Builder() | |
.setBrowserMatcher( | |
BrowserAllowList( | |
VersionedBrowserMatcher.CHROME_CUSTOM_TAB, | |
VersionedBrowserMatcher.SAMSUNG_CUSTOM_TAB | |
) | |
).build() | |
authorizationService = AuthorizationService( |
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
private fun initAuthServiceConfig() { | |
authServiceConfig = AuthorizationServiceConfiguration( | |
Uri.parse(Constants.URL_AUTHORIZATION), | |
Uri.parse(Constants.URL_TOKEN_EXCHANGE), | |
null, | |
Uri.parse(Constants.URL_LOGOUT)) | |
} |