Skip to content

Instantly share code, notes, and snippets.

@PaulTR
Created December 2, 2021 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulTR/721ce53e33c77ecb5aa6e5e4f69edfef to your computer and use it in GitHub Desktop.
Save PaulTR/721ce53e33c77ecb5aa6e5e4f69edfef to your computer and use it in GitHub Desktop.
fun makeApiCall() {
authState.performActionWithFreshTokens(authorizationService,
object: AuthState.AuthStateAction {
override fun execute(accessToken: String?, idToken: String?, ex: AuthorizationException?) {
GlobalScope.launch {
async(Dispatchers.IO) {
val client = OkHttpClient()
val request = Request.Builder()
.url(Constants.URL_API_CALL)
.addHeader("Authorization", "Bearer " + authState.accessToken)
.build()
try {
val response = client.newCall(request).execute()
val jsonBody = response.body?.string() ?: ""
Log.i(LOG_TAG, JSONObject(jsonBody).toString())
} catch (e: Exception) { }
}
}
}
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment