Skip to content

Commit 5192775

Browse files
committed
copilot review fixes
1 parent 57a6db1 commit 5192775

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

samples/android/login-pkce/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
<application
88
android:label="@string/app_name"
99
android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar"
10-
android:allowBackup="false"
11-
tools:targetApi="33">
10+
android:allowBackup="false">
1211

1312
<activity
1413
android:name=".MainActivity"

samples/android/login-pkce/app/src/main/java/com/secureauth/quickstart/AuthViewModel.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ class AuthViewModel(app: Application) : AndroidViewModel(app) {
9999
)
100100
.setScopes(AuthConfig.scopes)
101101
.build()
102+
val intent = authService.getAuthorizationRequestIntent(request)
102103
pendingAuthState = AuthState(config)
103-
authService.getAuthorizationRequestIntent(request)
104-
} catch (e: Throwable) {
104+
intent
105+
} catch (e: Exception) {
105106
_error.value = e.localizedMessage ?: "Authorization failed"
106107
null
107108
}
@@ -115,6 +116,7 @@ class AuthViewModel(app: Application) : AndroidViewModel(app) {
115116
val ex = AuthorizationException.fromIntent(intent)
116117
val pending = pendingAuthState
117118
if (response == null || pending == null) {
119+
pendingAuthState = null
118120
_error.value = ex?.localizedMessage ?: "Authorization failed"
119121
return
120122
}
@@ -125,7 +127,7 @@ class AuthViewModel(app: Application) : AndroidViewModel(app) {
125127
pending.update(tokenResponse, null)
126128
_state.value = pending
127129
scheduleExpiryTimer()
128-
} catch (e: Throwable) {
130+
} catch (e: Exception) {
129131
_error.value = e.localizedMessage ?: "Token exchange failed"
130132
} finally {
131133
pendingAuthState = null
@@ -137,7 +139,7 @@ class AuthViewModel(app: Application) : AndroidViewModel(app) {
137139
// @description Revoke the access token at the IdP and clear local auth state
138140
suspend fun signOut() {
139141
_state.value?.lastTokenResponse?.accessToken?.let { token ->
140-
try { revokeToken(token) } catch (_: Throwable) { /* best-effort */ }
142+
try { revokeToken(token) } catch (_: Exception) { /* best-effort */ }
141143
}
142144
_state.value = null
143145
_expired.value = false
@@ -195,13 +197,16 @@ class AuthViewModel(app: Application) : AndroidViewModel(app) {
195197
val conn = (URL(revokeUrl).openConnection() as HttpURLConnection).apply {
196198
requestMethod = "POST"
197199
doOutput = true
200+
connectTimeout = 5_000
201+
readTimeout = 5_000
198202
setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
199203
}
200204
try {
201205
val body = "token=${URLEncoder.encode(token, "UTF-8")}" +
202206
"&client_id=${URLEncoder.encode(AuthConfig.clientId, "UTF-8")}"
203207
conn.outputStream.use { it.write(body.toByteArray(Charsets.UTF_8)) }
204-
conn.inputStream.use { it.readBytes() }
208+
val stream = if (conn.responseCode in 200..299) conn.inputStream else conn.errorStream
209+
stream?.use { it.readBytes() }
205210
} finally {
206211
conn.disconnect()
207212
}

0 commit comments

Comments
 (0)