Browse Source

fix authorization

technical/upgrade-exoplayer
Ryan Harg 2 years ago
parent
commit
20ee27da21
  1. 8
      app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt
  2. 21
      app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt

8
app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt

@ -76,8 +76,13 @@ fun Request.authorize(context: Context, oAuth: OAuth): Request {
val old = state.accessToken val old = state.accessToken
val auth = ClientSecretPost(oAuth.state().clientSecret) val auth = ClientSecretPost(oAuth.state().clientSecret)
val done = CompletableDeferred<Boolean>() val done = CompletableDeferred<Boolean>()
val tokenService = oAuth.service(context)
state.performActionWithFreshTokens(oAuth.service(context), auth) { token, _, _ -> state.performActionWithFreshTokens(tokenService, auth) { token, _, e ->
if (e != null) {
Log.e("Request.authorize()", "performActionWithFreshToken failed: ${e}")
Log.e("Request.authorize()", Log.getStackTraceString(e))
}
if (token == old) { if (token == old) {
Log.i("Request.authorize()", "Accesstoken not renewed") Log.i("Request.authorize()", "Accesstoken not renewed")
} }
@ -88,6 +93,7 @@ fun Request.authorize(context: Context, oAuth: OAuth): Request {
done.complete(true) done.complete(true)
} }
done.await() done.await()
tokenService.dispose()
return@runBlocking this return@runBlocking this
} }
} }

21
app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt

@ -98,8 +98,13 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory
return if (state.refreshToken != null) { return if (state.refreshToken != null) {
val refreshRequest = state.createTokenRefreshRequest() val refreshRequest = state.createTokenRefreshRequest()
val auth = ClientSecretPost(state.clientSecret) val auth = ClientSecretPost(state.clientSecret)
val refreshService = service(context)
runBlocking { runBlocking {
service(context).performTokenRequest(refreshRequest, auth) { response, e -> refreshService.performTokenRequest(refreshRequest, auth) { response, e ->
if (e != null) {
Log.e("OAuth", "performTokenRequest failed: ${e}")
Log.e("OAuth", Log.getStackTraceString(e))
} else {
state.apply { state.apply {
Log.i("OAuth", "applying new authState") Log.i("OAuth", "applying new authState")
update(response, e) update(response, e)
@ -107,6 +112,8 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory
} }
} }
} }
}
refreshService.dispose()
true true
} else { } else {
false false
@ -202,17 +209,23 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory
AuthorizationResponse.fromIntent(authorization)?.let { AuthorizationResponse.fromIntent(authorization)?.let {
val auth = ClientSecretPost(state().clientSecret) val auth = ClientSecretPost(state().clientSecret)
val requestService = service(context)
service(context).performTokenRequest(it.createTokenExchangeRequest(), auth) { response, e -> requestService.performTokenRequest(it.createTokenExchangeRequest(), auth) { response, e ->
state if (e != null) {
.apply { Log.e("FFA", "performTokenRequest failed: ${e}")
Log.e("FFA", Log.getStackTraceString(e))
} else {
state.apply {
update(response, e) update(response, e)
save() save()
} }
}
if (response != null) success() if (response != null) success()
else Log.e("FFA", "performTokenRequest() not successful") else Log.e("FFA", "performTokenRequest() not successful")
} }
requestService.dispose()
} }
} }
} }

Loading…
Cancel
Save